National Olympiad in Informatics, China, 2011
Recently, Bunny and Eggy have developed an interest in a new type of board game.
This game is played on an
Each game will always have Bunny go first, followed by them alternating. The general steps are:
- Every time Bunny moves, she will select a white piece adjacent to the empty square and move it onto the space.
- Every time Eggy moves, he will select a black piece adjacent to the empty square and move it onto the space.
The first person that cannot follow the above loses the game. To
simplify our description, we denote the action of "moving the piece from
row

Figure 1

Figure 2

Figure 3
Bunny has been losing a lot recently, and thus Eggy has been getting overly arrogant. Bunny wants to invite her good friend – you! – to help her. She has brought over a game which she has lost to Eggy, and wishes for you to point out all of the "mistakes" she made.
Note:
- Two squares are considered adjacent if and only if they share an edge.
- A move of Bunny's is a "mistake" if and only if Bunny had a guaranteed winning strategy before it was made, and Eggy had a guaranteed winning strategy after it was made.
Input Specification
The first line of input contains two positive integers
The following X
, an uppercase O
, or a period .
.
Respectively, they represent a black piece on a square, a white piece on
a square, and an empty square. The .
character will appear exactly
once.
The following line contains a single integer
The following
The input guarantees that there will be exactly one empty square, all
moves made by Bunny and Eggy in the process are valid, and that Eggy
will be the winner at the end.
Output Specification
The first line of output should contain a single integer
The following
Sample Input 1
1 6
XO.OXO
1
1 2
1 1
Sample Output 1
1
1
Explanation for Sample Output 1
This corresponds to the example in figure 1.
Sample Input 2
3 3
XOX
O.O
XOX
4
2 3
1 3
1 2
1 1
2 1
3 1
3 2
3 3
Sample Output 2
0
Explanation for Sample Output 2
This corresponds to the example in figure 3.
Sample Input 3
4 4
OOXX
OXXO
OO.O
XXXO
2
3 2
2 2
1 2
1 3
Sample Output 3
2
1
2
Constraints
The attributes of all the test cases are outlined below.
Test Case | Range of | Range of |
---|---|---|
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | ||
20 |
Problem translated to English by .
Comments