P18119 [ICPC 2026 Seoul R] Baduk Solitaire
Description
umin found a long and narrow wooden board in her grandfather’s attic. It is a single row cut from an old Baduk (Go) board and consists of $n$ cells numbered $1$ through $n$ from left to right. Each cell is either empty or contains exactly one black or white Baduk stone. Sumin decides to play a solitaire puzzle on this board: she wants to remove all the stones from the board by repeatedly applying the only allowed move, called a *sweep*, which is defined as follows:
- Choose two distinct stones of the same color, say the stones in cells $i$ and $j$ with $i < j$.
- The sweep is allowed only if every stone in cells $i$ through $j$, inclusive, has the same color as the two chosen stones. Empty cells between them do not matter.
- All the stones in cells $i$ through $j$, inclusive, are removed from the board at once, and those cells become empty. The other stones stay in their cells.
Since a sweep always removes at least two stones of the same color, a stone can never be removed by itself; it must be swept together with another stone of the same color. Note that the order of sweeps matters.
For example, consider the board with $n = 10$ cells shown in the figure below. The board is represented by the string `B.WWBBBW.B`, where `B`, `W`, and `.` denote a black stone, a white stone, and an empty cell, respectively. Sumin can remove all the stones with three sweeps. She first sweeps the three black stones in cells $5$ through $7$. Then the white stones in cells $3$, $4$, and $8$ can be swept together, so she sweeps them next. Finally, she sweeps the two black stones in cells $1$ and $10$. However, if her first sweep removes the two white stones in cells $3$ and $4$, or only two of the three black stones in cells $5$ through $7$, then she can never remove all the stones from the board.

Given the initial state of the board, write a program to determine whether Sumin can remove all the stones from the board.
Input Format
Your program is to read from standard input. The input starts with a line containing an integer $n$ ($1 \le n \le 1{,}000{,}000$), where $n$ is the number of cells of the board.
The next line contains a string of length $n$ that represents the board from cell $1$ to cell $n$. Each character of the string is `B`, `W`, or `.`, which denotes a cell containing a black stone, a cell containing a white stone, or an empty cell, respectively. The board contains at least one stone.
Output Format
Your program is to write to standard output. Print exactly one line. If Sumin can remove all the stones from the board, print `YES`. Otherwise, print `NO`.