atcoder#ARC117C. [ARC117C] Tricolor Pyramid

[ARC117C] Tricolor Pyramid

Score : 600600 points

Problem Statement

We have NN blocks arranged in a row, where each block is painted blue, white, or red. The color of the ii-th block from the left (1iN)(1 \leq i \leq N) is represented by a character cic_i; B, W, and R stand for blue, white, and red, respectively.

From this situation, we will pile up blue, white, and red blocks to make a pyramid with NN steps. The following figure shows an example of this:

Here, we place blocks one by one from bottom to top as follows:

  • if the two blocks immediately below a position have the same color, we will place there a block of the same color;
  • if the two blocks immediately below a position have different colors, we will place there a block of the color different from those two colors.

What will be the color of the block at the top?

Constraints

  • NN is an integer satisfying 2N4000002 \leq N \leq 400000.
  • Each of c1,c2,,cNc_1, c_2, \dots, c_N is B, W, or R.

Input

Input is given from Standard Input in the following format:

NN

c1c_1c2c_2\cdotscNc_N

Output

If the topmost block will be blue, print B; if it will be white, print W; if it will be red, print R.

3
BWR
W

In this case, we will pile up blocks as follows:

  • the 11-st and 22-nd blocks from the left in the bottom row are respectively blue and white, so we place a red block on top of it;
  • the 22-nd and 33-rd blocks from the left in the bottom row are respectively white and red, so we place a blue block on top of it;
  • the blocks in the 22-nd row from the bottom are respectively red and blue, so we place a white block on top of it.

Thus, the block at the top will be white; we should print W.

4
RRBB
W

In this case, we will pile up blocks as follows:

  • the 11-st and 22-nd blocks from the left in the bottom row are both red, so we place a red block on top of it;
  • the 22-nd and 33-rd blocks from the left in the bottom row are respectively red and blue, so we place a white block on top of it;
  • the 33-rd and 44-th blocks from the left in the bottom row are both blue, so we place a blue block on top of it;
  • the 11-st and 22-nd blocks from the left in the 22-nd row from the bottom are respectively red and white, so we place a blue block on top of it;
  • the 22-nd and 33-rd blocks from the left in the 22-nd row from the bottom are respectively white and blue, so we place a red block on top of it;
  • the blocks in the 33-rd row from the bottom are respectively blue and red, so we place a white block on top of it.

Thus, the block at the top will be white; we should print W.

6
BWWRBW
B

The figure below shows the final arrangement of blocks. The block at the top will be blue; we should print B.

Note that this is the case shown as an example in Problem Statement.

8
WWBRBBWB
R

The figure below shows the final arrangement of blocks. The block at the top will be red; we should print R.

21
BWBRRBBRWBRBBBRRBWWWR
B