1696.Flag of Berland

Time Limit: 1s Memory Limit: 256MB

The flag of Berland is such rectangular field n \times m that satisfies following conditions:
Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe.
You are given a field n \times m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).

Input Format(From the terminal/stdin)

The first line contains two integer numbers n and m (1 \le n,m \le 100) - the sizes of the field.

Each of the following n lines consisting of m characters 'R', 'G' and 'B' - the description of the field.

Output Format(To the terminal/stdout)

Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

Sample Input 1

Copy
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
 · \n
     \n
     \n
     \n
     \n
     \n
     \n

Sample Output 1

Copy
YES
   \n

Sample Input 2

Copy
4 3
BRG
BRG
BRG
BRG
 · \n
   \n
   \n
   \n
   \n

Sample Output 2

Copy
YES
   \n

Sample Input 3

Copy
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
 · \n
       \n
       \n
       \n
       \n
       \n
       \n

Sample Output 3

Copy
NO
  \n

Sample Input 4

Copy
4 4
RRRR
RRRR
BBBB
GGGG
 · \n
    \n
    \n
    \n
    \n

Sample Output 4

Copy
NO
  \n

Hints

The field in the third example doesn't have three parralel stripes.

Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights - 2, 1 and 1.

Submit

请先 登录

© 2025 FAQs