#arc117c. [arc117_c]Tricolor Pyramid
[arc117_c]Tricolor Pyramid
Problem Statement
We have blocks arranged in a row, where each block is painted blue, white, or red. The color of the -th block from the left is represented by a character ; 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 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
- is an integer satisfying .
- Each of is
B
,W
, orR
.
Input
Input is given from Standard Input in the following format:
Output
If the topmost block will be blue, print B
; if it will be white, print W
; if it will be red, print R
.
Sample Input 1
3
BWR
Sample Output 1
W
In this case, we will pile up blocks as follows:
- the -st and -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 -nd and -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 -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
.
Sample Input 2
4
RRBB
Sample Output 2
W
In this case, we will pile up blocks as follows:
- the -st and -nd blocks from the left in the bottom row are both red, so we place a red block on top of it;
- the -nd and -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 -rd and -th blocks from the left in the bottom row are both blue, so we place a blue block on top of it;
- the -st and -nd blocks from the left in the -nd row from the bottom are respectively red and white, so we place a blue block on top of it;
- the -nd and -rd blocks from the left in the -nd row from the bottom are respectively white and blue, so we place a red block on top of it;
- the blocks in the -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
.
Sample Input 3
6
BWWRBW
Sample Output 3
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.
Sample Input 4
8
WWBRBBWB
Sample Output 4
R
The figure below shows the final arrangement of blocks. The block at the top will be red; we should print R
.
Sample Input 5
21
BWBRRBBRWBRBBBRRBWWWR
Sample Output 5
B