# Very Well Informed Domino Player

Four friends join regularly to play Domino. They are friendly and always ready to spend the night together playing Domino, but they are not uninformed by any means. One of them, Bob, is specially cautious about the game. He wants to be so very well informed that he wants to know, given the game (the pieces of all the players), which piece should he use first to start the game so that the probability of wining is bigger. The Domino game is fairly easy: there are twenty-eight (28) pieces, each one with two halves. Each half has a number in it, from zero to six, represented as spots in the surface. You can see pieces as pairs of numbers. So, the 28 pieces are composed by: (6,6), (6,5), (6,4), ..., (0,0). Pieces can always be seen from both halves, so, for instance, (6,5) is the same piece as (5,6). In the game there are four (4) players. Pi, with i from 1 to 4. To start the game, each player has seven (7) pieces, (pij1 , pij2 ), with i from 1 to 4, and j from 1 to 7, taken at random, and one of them starts the game putting one piece in the center of the table. Then, all players play in turns putting one piece into the table (if they have one applicable), by joining it with the ones that actually are in the table. To build a set of pieces in the table, the pieces have to “match” by sides. That is, suppose that in the table there are a set of pieces (x1,y1), (x2,y2), (x3,y3), ..., (xn,yn). It is always the case that yi =x(i+1). Then,anyplayercanputanotherpiece(j,k),iffx1 =jorx1 =koryn =koryn =j. Suppose that the latter, yn = j holds. The new set of pieces on the table would be: (x1, y1), (x2, y2), (x3, y3), . . . , (xn, yn), (j, k). Note also that, for the purposes of the game, the pieces in the table are equivalent if you put them the other way round, that is, The game ends when: (k, j), (yn, xn), . . . , (y3, x3), (y2, x2), (y1, x1).

1. One player inserts into the table his or her last piece (he or she wins).
2. No player can put a new piece. In this case, a sum is computed for each player, counting the numeric value of each part of each piece the player has left. The winner is the player with less points, that is: Cw|Cw < Ci,i ∈ [1,...,4] ∑ Ci = and player w wins. Note that if there are more than one player that hold the minimum value, there is no winner of this game. At a given point, Bob is informed of all the pieces that the other players have received. The pieces of each player are these: Bob: where j ∈ available pieces player i pij1 + pij2

2/3 Alice: Peter: Mike: The first turn goes to Bob, and he wants to know the probability of wining this game if he starts with any of his pieces... Would you help him? Input The input will be composed of lines. Each line contains the specification of a piece that Bob has (one of the 7 pieces listed above), composed as follows: • A left parenthesis ‘(’, • The number of the part, x, (from 0 to 6), • a comma ‘,’, • The number of the other part, y, (from 0 to 6), • A right parenthesis ‘)’. Note that at this point, again, (x, y) is equivalent to (y, x).

3/3 Output For each line of input, the output is another line containing the following: wins W; loses L where W is the number of all possible games played starting with that piece where Bob wins; and L is the number of all possible games played starting with that piece where Bob loses the game. Sample Input (2,0) (0,6) Sample Output wins 2738632; loses 3409819 wins 4121220; loses 4678487