P25398 [AtCoder] Decode RGB Sequence
提高
题目描述

Problem Description

There is a grid of length $ N $ with all squares initially painted white. Each square is numbered from 1 to $ N $ from left to right.

For a consecutive group of 3 squares in this grid, a stamp is used to paint them from left to right in red, green, and blue colors sequentially. More precisely, an integer $ i $ $(\ =\ 1,\ 2,\ \ldots,\ N-2)$ is chosen, and the square $ i $ is painted red, the square $ i+1 $ is painted green, and the square $ i+2 $ is painted blue. Squares that have already been stamped can be stamped again, and the color of each stamped square is overwritten by the new stamp's color. Aoki continued this operation until there were no more white squares. Even after all white squares are gone, the operation can continue, and the operation can be ended at any time.

Write a program to determine if it is possible to achieve a desired color scheme at the end of the operations. The desired color scheme is represented by a string $ S $ of length $ N $. For $i\ =\ 1,\ 2,\ \ldots,\ N$, $ S_i $ = 'R' indicates that the $ i $th square should be red, $ S_i $ = 'G' indicates that the $ i $th square should be green, and $ S_i $ = 'B' indicates that the $ i $th square should be blue.

Input Format

The input is given from the standard input in the following format:

$ N $ $ S $

Output Format

If the color scheme represented by the string $ S $ can be achieved, output "Yes"; otherwise, output "No".

Sample Input and Output

Sample Input #1

4
RGBB

Sample Output #1

Yes

Sample Input #2

6
RRGGBB

Sample Output #2

No

Sample Input #3

10
RGBBBGRRGB

Sample Output #3

Yes

Notes/Hints

Constraints

  • $3\ \le\ N\ \le\ 10^5$
  • $|S|\ =\ N$
  • $ S $ is a string consisting of 'R', 'G', 'B'.

Sample Explanation 1

First, stamp the last 3 squares, then stamp the first 3 squares, resulting in "RGBB".

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 RGBB
样例输出
Yes