Hide

Problem F
Thwack!

The game Thwack is played on a 1-dimensional grid of cells: the game board. Each grid cell contains either a black stone, a white stone, or is empty.

Two players alternate taking turns. A turn consists of choosing two adjacent stones of opposite colours and then choosing one of these stones to capture the other. That is, one stone eliminates the other stone by moving to its position. A player loses when it is their turn to play but there are no available moves, i.e. there is no pair of adjacent stones of different colours.

The interesting thing about Thwack is that there is no default “initial setup” of the game board. Any game can be made by simply placing stones randomly on the grid.

Given the initial configuration of a game, your job is to list all the opening moves that would be winning moves for the first player assuming both players play optimally.

Input

The first line of input contains a single integer $N$ $(1 \leq N \leq 100)$ indicating the number of cells on the game board.

The second line contains a single string of length $N$ consisting only of characters B, W, or . which indicate the initial contents of the cells on the game board at the start of the game.

Output

The first line of output displays the number $W$ of possible opening moves for the first player that would result in them winning, assuming both players play perfectly. Then $W$ lines follow, the $i$th of which contains two integers $A_ i, D_ i$ ($1 \leq A_ i, D_ i \leq N, |A_ i - D_ i| = 1$) indicating that moving the stone at $A_ i$ to capture the stone at position $D_ i$ is one possible opening move that would result in the first player winning. These lines should be presented in lexicographical ordering, i.e. for $1 \leq i < N$ we have either a) $A_ i < A_{i+1}$ or b) $A_ i = A_{i+1}$ and $D_ i < D_{i+1}$.

Sample Input 1 Sample Output 1
4
BWBW
2
2 3
3 2
Sample Input 2 Sample Output 2
11
.BW.WB..W..
0
Sample Input 3 Sample Output 3
8
BBBBW.BW
1
5 4
Sample Input 4 Sample Output 4
9
BBBBBW.BW
0
Sample Input 5 Sample Output 5
12
WBBWBWWBBWBW
5
2 1
4 5
5 4
10 11
11 10
Sample Input 6 Sample Output 6
11
WBBWWWBBWBW
5
1 2
4 3
9 10
10 9
11 10

Please log in to submit a solution to this problem

Log in