#P10055. Twos and Threes
Twos and Threes
Twos and Threes
Finn is playing a game called Twos and Threes on a one-dimensional board. Initially, there are $N$ blocks placed in a row, each labeled with either A
or B
. The blocks are numbered from $1$ to $N$. Finn can perform the following operation:
- Select either $2$ or $3$ consecutive blocks that all have the same label and remove them from the board. After removal, the remaining blocks are concatenated and renumbered from left to right.
If all blocks are removed, Finn wins the game. Your task is to determine a sequence of operations that leads to a win (removing all blocks) or to determine that the game cannot be won.
inputFormat
The first line contains an integer $N$ ($1 \leq N \leq 20$) indicating the number of blocks on the board. The second line contains a string of length $N$ consisting only of the characters A
and B
, representing the blocks from left to right.
outputFormat
If a winning sequence of operations exists, first output an integer $M$ representing the number of moves. Then output $M$ lines, each containing two integers $l$ and $r$, representing that the blocks at positions $l$ through $r$ (inclusive) are removed in that move. Note that positions are reindexed after each move. If it is impossible to win, output a single line containing NO
(without quotes).
sample
2
AA
1
1 2
</p>