Hide

Problem F
Board Coloring

One day you were visiting a museum where you saw a modern piece of art that shows a grid of $N$ rows and $M$ columns. Each cell in the grid has a color, which can be one of the four: red (‘R’), green (‘G’), blue (‘B’), and white (‘W’).

You think that the art is so simple so that even you can reproduce it yourself. After getting home, you get yourself a grid board with exactly $N$ rows and $M$ columns. The cells of the board are initially all white. You also find some red, green and blue paint (unfortunately you didn’t find any white paint), as well as a square stamp of a size equal to exactly $3 \times 3$ cells. With the tools at hand, in each step you can choose a square of $3\times 3$ cells from the board and pick a color, and then stamp the chosen square of cells with that color (overwriting their previous colors). Note that the chosen square is not allowed to exceed the board boundary, otherwise you would spill the paint and make your home messy.

You soon realize that the art seems to be simple but is not so easy to reproduce. Actually, you are not even sure about whether it is possible to reproduce the art with the aforementioned procedure. You eventually decide to make it a ProgNova question and ask some smart people for help.

Input

The first line contains two integers $N$ and $M$ ($3 \leq N, M \leq 30$). Each of the next $N$ lines has a string of $M$ characters. All strings contain only letters ‘R’, ‘G’, ‘B’, and ‘W’, representing the colors of the cells in the art piece you want to reproduce.

Output

Output “YES” if it is possible to reproduce the art piece, or “NO” otherwise.

Sample Input 1 Sample Output 1
4 5
WRRRG
WRRRG
WRRRG
WBBBB
YES
Sample Input 2 Sample Output 2
3 4
WWRR
WRRR
WRRR
NO
Sample Input 3 Sample Output 3
3 3
WWW
WWW
WWW
YES

Please log in to submit a solution to this problem

Log in