Problem D
Hackenbush Lupines
Languages
en
is
Hackenbush is a game played on edges of three colours which all connect to each other or the ground. The edges are all red, green or blue. The first player can hack red and green edges and the second blue and green edges. When a player hacks an edge it is deleted. Any edges that can’t reach the ground are discarded.
The value of a Hackenbush game with red and blue edges can be defined in a few steps. We say that a blue edge is $+1$ and a red edge is $-1$. We also regard any position where whoever plays first loses as having value $0$. By repeating, combining and comparing games we can figure when the value becomes $0$ to determine the value of a given game. Consider as an example the game with one blue edge attached to a single red edge which is attached to the ground. If we take two copies of this game and a single blue edge attached to the ground, we get a game with value $0$. Thus the value of the game we are considering is $-1/2$.
You are given a position of Hackenbush lupines. This is a position in the game Hackenbush where all edges are red or blue and all edges are on straight paths from the ground, which do not split.
You need to determine the value of the game. It can be shown that this is always an integer fraction.
Input
The first line of input contains a single integer $0 \leq n \leq 100$, the number of stalks in the input. Next there are $n$ lines, each containing one stalk. Each stalk is given as a string containing only the letters R and B. R denotes a red edge and B denotes a blue edge. The first letter denotes the edge that touches the ground, the second letter the edge above that and so on. The height of each stalk is at most $10^3$.
Output
If the value of the game is $p/2^q$ print p/2q where $p/2^q$ is a fully reduced fraction. If the fraction is an integer, print just that integer without /20. The value of the game is always of this form.
Sample Input 1 | Sample Output 1 |
---|---|
3 RB RR BB |
-1/2^1 |
Sample Input 2 | Sample Output 2 |
---|---|
1 BBR |
3/2^1 |
Sample Input 3 | Sample Output 3 |
---|---|
1 BRRB |
3/2^3 |
Sample Input 4 | Sample Output 4 |
---|---|
3 BBB RRRR BB |
1 |