Johnny is playing a simple game with a set of colored stones and a circular board with squares laid out in a track around the edge, some of which are marked. To start with, he places some stones of different colors on the board in different unmarked squares and marks the starting position of each stone. He then picks some number from allowedMoves and advances some stone that number of squares clockwise around the board. If the square that the stone lands in is unmarked, then he leaves the stone there and marks the square. If the square was the starting position of that particular stone, then he removes the stone from the board. Otherwise, if the square had previously been marked, the move is invalid and he returns the stone to its position before he moved it at the beginning of this turn. He then repeats this process. The board is considered complete once all the squares are marked and all the stones have been removed (having moved at least once, then returned to their starting positions). To make the game more interesting, some of the squares on the board are marked before he starts the game and these squares are given in a String markedSquares, in which a marked square is denoted 'X' and an unmarked square '.'. The squares are given in clockwise order. Note that since the board is circular, the first element of markedSquares is adjacent to the last element. Return the minimum number of stones that Johnny would need to place on the board in order to complete the game, or -1 if it is impossible to complete the board. |