The flag of Berland is such rectangular field n × 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 × 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-----

The first line contains two integer numbers n and m (1 ≤ n, m ≤ 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-----

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


-----Examples-----
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG

Output
YES

Input
4 3
BRG
BRG
BRG
BRG

Output
YES

Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB

Output
NO

Input
4 4
RRRR
RRRR
BBBB
GGGG

Output
NO



-----Note-----

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.

Difficulty: interview

Starter code:

Solutions:
n,m=list(map(int,input().split()))
f=[input() for _ in range(n)]
def clr(ss):
    cc = None
    for s in ss:
        for c in s:
            if cc is None:
                cc = c
            elif cc != c:
                return None
    return cc
if n%3 == 0:
    s = set()
    for i in range(0,n,n//3):
        ret = clr(f[i:i+n//3])
        if ret is None:
            continue
        s.add(ret)
    if len(s) == 3:
        print('YES')
        return
if m%3 == 0:
    s = set()
    for j in range(0,m,m//3):
        ff = []
        for i in f:
            ff.append(i[j:j+m//3])
        ret = clr(ff)
        if ret is None:
            continue
        s.add(ret)
    if len(s) == 3:
        print('YES')
        return
print('NO')


#! /usr/bin/env python3

n, m = list(map(int, input().split()))
a = [input() for i in range(n)]
b = [''.join(a[i][j] for i in range(n)) for j in range(m)]


def check(a, n, m):
    if n % 3 != 0:
        return False
    s = a[0 * n // 3], a[1 * n // 3], a[2 * n // 3]
    if set(s) != set([x * m for x in 'RGB']):
        return False
    for i in range(n):
        if a[i] != s[i * 3 // n]:
            return False
    return True


if check(a, n, m) or check(b, m, n):
    print('YES')
else:
    print('NO')


def check_flag(flag, n, m):
    if n % 3 > 0 and m % 3 > 0:
        return False

    if n % 3 == 0:
        nrows = int(n / 3)

        set1 = set("".join(flag[:nrows]))
        set2 = set("".join(flag[nrows:2*nrows]))
        set3 = set("".join(flag[2*nrows:]))

        if len(set1) + len(set2) + len(set3) == 3 and len(set1.union(set2.union(set3))) == 3:
            return True

    if m % 3 == 0:
        ncols = int(m / 3)

        set1 = set("".join([row[:ncols] for row in flag]))
        set2 = set("".join([row[ncols:2*ncols] for row in flag]))
        set3 = set("".join([row[2*ncols:] for row in flag]))

        if len(set1) + len(set2) + len(set3) == 3 and len(set1.union(set2.union(set3))) == 3:
            return True

    return False


n, m = [int(i) for i in input().strip(" ").split(" ")]

flag = []
for _ in range(n):
    flag.append(input().strip(" "))

if check_flag(flag, n, m):
    print("YES")
else:
    print("NO")


import sys


def main():
    n, m = list(map(int, sys.stdin.readline().split()))
    if n % 3 != 0 and m % 3 != 0:
        print("NO")
        return
    f = []
    for i in range(n):
        f.append(sys.stdin.readline())

    ok = True
    if f[0][0] == f[n - 1][0]:  # vertical
        if m % 3 != 0:
            ok = False
        else:
            sz = int(m / 3)
            if f[0][0] == f[0][sz] or f[0][0] == f[0][2 * sz] or f[0][2 * sz] == f[0][sz]:
                ok = False
            else:
                for k in range(3):
                    c = f[0][k * sz]
                    for i in range(n):
                        for j in range(k * sz, (k + 1) * sz):
                            if c != f[i][j]:
                                ok = False
                                break
                        if not ok:
                            break
                    if not ok:
                        break

    else:  # horizontal
        if n % 3 != 0:
            ok = False
        else:
            sz = int(n / 3)
            if f[0][0] == f[sz][0] or f[0][0] == f[2 * sz][0] or f[2 * sz][0] == f[sz][0]:
                ok = False
            else:
                for k in range(3):
                    c = f[k * sz][0]
                    for i in range(k * sz, (k + 1) * sz):
                        for j in range(m):
                            if c != f[i][j]:
                                ok = False
                                break
                        if not ok:
                            break
                    if not ok:
                        break

    if ok:
        print("YES")
    else:
        print("NO")


main()


n, m = list(map(int, input().split()))

flag = []

def letterwidth(i):
    res = flag[i][0]
    for item in flag[i]:
        if item != res:
            return None
    return res
def letterheight(i):
    res = flag[0][i]
    for j in range(n):
        if flag[j][i] != res:
            return None
    return res

for i in range(n):
    flag.append(input())

result = False

if(n % 3 == 0 and not result):
    w = n // 3
    letters = []
    for i in range(n):
        curres = letterwidth(i)
        letters.append(curres)
        if curres is None:
            break
    if(letters.count(None) == 0):
        answers = []
        counter = 0
        for i in range(3):
            res = letters[counter]
            answers.append(res)
            counter += 1
            for j in range(w - 1):
                if(letters[counter] != res):
                    letters.append(None)
                    break
                counter += 1
            if(letters.count(None) > 0):
                break
        if(letters.count(None) == 0):
            if(len(answers) == len(set(answers))):
                result = True
if(m % 3 == 0 and not result):
    w = m // 3
    letters = []
    for i in range(m):
        curres = letterheight(i)
        letters.append(curres)
        if curres is None:
            break
    if(letters.count(None) == 0):
        answers = []
        counter = 0
        for i in range(3):
            res = letters[counter]
            answers.append(res)
            counter += 1
            for j in range(w - 1):
                if(letters[counter] != res):
                    letters.append(None)
                    break
                counter += 1
            if(letters.count(None) > 0):
                break
        if(letters.count(None) == 0):
            if(len(answers) == len(set(answers))):
                result = True
if(result):
    print("YES")
else:
    print("NO")


def matrixTranspose( matrix ):
    if not matrix: return []
    return [ [ row[ i ] for row in matrix ] for i in range( len( matrix[ 0 ] ) ) ]
def f(x):
    #print(x)
    bool=True
    b,r,g=0,0,0
    col=['e']
    for row in x:
         if all(el=='R' for el in row):
             r+=1
             if col[-1] != 'r':
                 col.append('r')
         elif all(el=='G' for el in row):
             g+=1
             if col[-1] != 'g':
                 col.append('g')
         elif all(el=='B' for el in row):
             b+=1
             if col[-1] != 'b':
                 col.append('b')
         else:
             bool=False
             break
    return (bool and b==g==r and sorted(col)==sorted(list(set(col))))
    
n,m=map(int,input().split())
a=[0]*n
for i in range(n):
    a[i]=list(input())
print('YES' if f(a) or f(matrixTranspose(a)) else 'NO')

n, m = map(int, input().split(" "))
flag2 = 0
flag1 = 0
if (n % 3 == 0):
	flag1 = 1
if (m % 3 == 0):
	flag2 = 1
s = []
f = [""] * m
for i in range(n):
	t = input()
	s.append(t)
	for j in range(m):
		f[j] += t[j]
H = [0, 0, 0]
p = []
for i in s:
	if (i == 'R' * m):
		H[0] += 1
		p.append(0)
	if (i == 'B' * m):
		H[1] += 1
		p.append(1)
	if (i == 'G' * m):
		H[2] += 1
		p.append(2)
cnt = 0
for i in range(1, len(p)):
	if (p[i] != p[i-1]):
		cnt += 1
if (H[0] == n / 3 and H[1] == n / 3 and H[2] == n / 3 and flag1 and cnt == 2):
	print("YES")
else:
	H = [0, 0, 0]
	p = []
	for i in f:
		if (i == 'R' * n):
			H[0] += 1
			p.append(0)
		if (i == 'B' * n):
			H[1] += 1
			p.append(1)
		if (i == 'G' * n):
			H[2] += 1
			p.append(2)
	cnt = 0
	for i in range(1, len(p)):
		if (p[i] != p[i-1]):
			cnt += 1
	if (H[0] == m / 3 and H[1] == m / 3 and H[2] == m / 3 and flag2 and cnt == 2):
		print("YES")
	else:
		print("NO")

import re, sys

n, m = list(map(int, input().split()))

s = sys.stdin.read()
d = s.split('\n')
d.remove("")
rgb = "RGB"
f = True
#print(s)
#print(d)
for c in rgb:
    t = re.findall(c + "+", d[0])
    if len(t) != 1 or len(t[0]) != m / 3:
        f = False

if f:
    for st in d:
        if st != d[0]:
            f = False

if f:
    print("YES")
    return

s = s.replace('\n', '')
f = True
for c in rgb:
    t = re.findall(c + "+", s)
    if len(t) != 1 or len(t[0]) != m * n / 3:
        f = False

if f:
    print("YES")
    return

print("NO")


a, b = map(int, input().split())
rows = [list(input()) for x in range(a)]
columns = [[x[y] for x in rows] for y in range(b)]
def check(l):
    line = []
    for x in l:
        p = x[0]
        for y in x:
            if y != p:
                break
        else:
            line.append(p)
            continue
        return [False, line]
    else:
        return [True, line]
def colors(c, l):
    p = c[1][0]
    n = 0
    colors = []
    for x in c[1]:
        if x != p:
            colors.append([p, n])
            p = x
            n = 1
        else:
            n += 1
    colors.append([p, n])
    if len(colors) == 3 and l % 3 == 0:
        m = l // 3
        letters = ["R", "G", "B"]
        for x in colors:
            p, q = x[0], x[1]
            if x[0] in letters and q == m:
                letters.remove(x[0])
            else:
                return False
                break
        else:
            return True
    else:
        return False
condition = False
if a % 3 == 0 or b % 3 == 0:
    c, d = check(rows), check(columns)
    if c[0]:
        condition = colors(c, a)
    if not condition and d[0]:
        condition = colors(d, b)
if condition:
    print("YES")
else:
    print("NO")

n, m = list(map(int, input().split()))
c = [list(input()) for _ in range(n)]

ans = "NO"
if n % 3 == 0:
    l = []
    for i in range(3):
        s = set([])
        for j in range(i * n // 3, (i + 1) * n // 3):
            for k in range(m):
                s.add(c[j][k])
        if len(s) == 1:
            l.append(s.pop())
    if sorted(l) == ['B', 'G', 'R']:
        ans = "YES"
if m % 3 == 0:
    l = []
    for i in range(3):
        s = set([])
        for j in range(i * m // 3, (i + 1) * m // 3):
            for k in range(n):
                s.add(c[k][j])
        if len(s) == 1:
            l.append(s.pop())
    if sorted(l) == ['B', 'G', 'R']:
        ans = "YES"

print(ans)


def satisfy_line(line):
    total = len(line)
    size = total // 3
    if total % 3 != 0:
        return False

    first_part = line[0:size]
    second_part = line[size:2 * size]
    third_part = line[2 * size:3 * size]

    first_set = set(first_part)
    second_set = set(second_part)
    third_set = set(third_part)

    if len(first_set) == len(second_set) == len(third_set) == 1:
        all_color = set().union(first_set, second_set, third_set)
        if all_color == {'R', 'G', 'B'}:
            return True
    return False


def satisfy_flag(flag):
    first_line = flag[0]

    if not satisfy_line(first_line):
        return False

    for line in flag:
        if line != first_line:
            return False

    return True


def rotate(flag, n, m):
    rotated_flag = []

    for i in range(m):
        line = []
        for j in range(n):
            line.append(flag[j][i])
        rotated_flag.append(line)

    return rotated_flag


def main():
    n, m = [int(t) for t in input().split()]
    flag = [input() for _ in range(n)]

    if satisfy_flag(flag):
        print('YES')
    elif satisfy_flag(rotate(flag, n, m)):
        print('YES')
    else:
        print('NO')


def __starting_point():
    main()

__starting_point()

from copy import deepcopy
n, m = map(int, input().split())

l = [0 for i in range(n)]

for i in range(n):
  l[i] = input()
# print(l)

f1 = 0
f2 = 0
for i in range(n):
  cnt = [0, 0, 0]
  for j in range(m):
    if (l[i][j] == 'R'):
      cnt[0] += 1
    if (l[i][j] == 'G'):
      cnt[1] += 1
    if (l[i][j] == 'B'):
      cnt[2] += 1
  if not ((cnt[0] == 0 and cnt[1] == 0) or (cnt[1] == 0 and cnt[2] == 0) or (cnt[2] == 0) and cnt[0] == 0):
    f1 = 1

for j in range(m):
  cnt = [0, 0, 0]
  for i in range(n):
    if (l[i][j] == 'R'):
      cnt[0] += 1
    if (l[i][j] == 'G'):
      cnt[1] += 1
    if (l[i][j] == 'B'):
      cnt[2] += 1
  if not ((cnt[0] == 0 and cnt[1] == 0) or (cnt[1] == 0 and cnt[2] == 0) or (cnt[2] == 0) and cnt[0] == 0):
    f2 = 1

if (f1 == 1 and f2 == 1):
  print('NO')
  return
if (f2 == 0):
  l1 = [[0 for i in range(n)] for j in range(m)]
  for i in range(n):
    for j in range(m):
      l1[j][i] = l[i][j]
  n, m = m, n
  l = deepcopy(l1)

r = []
g = []
b = []
for i in range(n):
  if (l[i][0] == 'R'):
    r.append(i)
  if (l[i][0] == 'G'):
    g.append(i)
  if (l[i][0] == 'B'):
    b.append(i)
ans = 0
if (len(r) != len(g) or len(r) != len(b) or len(r) != len(g)):
  ans = 1
for i in range(len(r) - 1):
  if (r[i+1] - r[i] != 1):
    ans = 1
for i in range(len(g) - 1):
  if (g[i+1] - g[i] != 1):
    ans = 1
for i in range(len(b) - 1):
  if (b[i+1] - b[i] != 1):
    ans = 1
if (ans == 1):
  print('NO')
  return
print('YES')

n, m = map(int, input().split())

f = [0 for _ in range(n)]

for i in range(n):
    f[i] = input()


hor = True

if n % 3 != 0:
    hor = False
else:
    c = "RGB"
    used = {"R":False, "G":False, "B":False}
    used[f[0][0]] = True

    cnt = 0
    if [f[0][0] * m for i in range(n // 3)] == \
       f[:n // 3]:
        cnt += 1

    if not used[f[n // 3][0]]:
        used[f[n // 3][0]] = True
        if [f[n // 3][0] * m for i in range(n // 3)] == \
           f[n // 3 : n // 3 * 2]:
            cnt += 1

    if not used[f[n // 3 * 2][0]]:
        used[f[n // 3 * 2][0]] = True
        if [f[n // 3 * 2][0] * m for i in range(n // 3)] == \
           f[n // 3 * 2:]:
            cnt += 1

    if cnt == 3:
        hor = True
    else:
        hor = False

ver = True

if m % 3 != 0:
    ver = False
else:
    new_f = ["" for _ in range(m)]
    for i in range(m):
        for j in range(n):
            new_f[i] += f[j][i]

    c = "RGB"
    used = {"R":False, "G":False, "B":False}
    used[new_f[0][0]] = True

    cnt = 0
    if [new_f[0][0] * n for i in range(m // 3)] == \
       new_f[:m // 3]:
        cnt += 1

    if not used[new_f[m // 3][0]]:
        used[new_f[m // 3][0]] = True
        if [new_f[m // 3][0] * n for i in range(m // 3)] == \
           new_f[m // 3 : m // 3 * 2]:
            cnt += 1

    if not used[new_f[m // 3 * 2][0]]:
        used[new_f[m // 3 * 2][0]] = True
        if [new_f[m // 3 * 2][0] * n for i in range(m // 3)] == \
           new_f[m // 3 * 2:]:
            cnt += 1

    if cnt == 3:
        ver = True
    else:
        ver = False

if hor or ver:
    print("YES")
else:
    print("NO")

def re(a):
    if a=='R':
        return 0
    elif a=='B':
        return 1
    else:
        return 2

def llk(a):
    dd=''.join(a)
    i=0
    n=len(dd)
    su=0
    while(i<n-1):
        if dd[i]!=dd[i+1]:
            su+=1
        i+=1
    if su==2:
        return 1
    else:
        return 0
            


a=[int(i) for i in input().split()]
k=[]
lk=[]
for i in range(a[0]):
    aa=input()
    k.append(aa)
    lk.append(set(aa))


ml=0
ch=[0,0,0]
for i in k:
    if len(set(i))==1:
        ch[re(i[0])]+=1
    else:
        ml=1
        break
mll=0
gk=['']*(a[1])
for i in range(a[0]):
    dk=k[i]
    for j in range(a[1]):
        gk[j]+=(dk[j])
ch1=[0,0,0]
for i in gk:
    if len(set(i))==1:
        ch1[re(i[0])]+=1
    else:
        mll=1
        break      


if (len(set(ch))==1 and ml==0 and llk(k)):
    print("YES")
elif (len(set(ch1))==1 and mll==0 and llk(gk)):
    print("YES")
else:
    print("NO")

            
            


def check(n, m, fl, count):
  nonlocal flag, tr_flag
  if count == 3:
    return 'NO'
  num = n // 3
  is_ok = set()
  for k in range(0, n, num):
    new_check = set()
    for i in range(k, k + num):
      new_check = new_check | set(fl[i])
    if len(new_check) != 1:
      flag, tr_flag = tr_flag, flag
      if m % 3 == 0:
        return check(m, n, flag, count + 1)
      else:
        return 'NO'
    now = list(new_check)[0]
    if now in is_ok:
      flag, tr_flag = tr_flag, flag
      if m % 3 == 0:
        return check(m, n, flag, count + 1)
      else:
        return 'NO'
    is_ok.add(now)
  return 'YES'

def main():
  nonlocal n, m, flag, tr_flag
  if n % 3 != 0 and m % 3 != 0:
    return 'NO'
  
  if n % 3 == 0:
    return check(n, m, flag, 0)
  else:
    return check(m, n, tr_flag, 0)
    

n, m = map(int, input().split())
flag = []
for i in range(n):
  string = list(input())
  flag.append(string)
tr_flag = list(map(list, zip(*flag)))
answer = main()
print(answer)

n,m = map(int,input().split())
a = []
s = ''
for i in range(n):
    a.append(input())
    s += a[i]
    
s1 = ''
for i in range(m):
    for j in range(n):
        s1 += a[j][i]
f,f1 = True,True
v = []
v1 = []

if s[0:n*m//3] == s[0]*(n*m//3):
    v.append(s[0])
else:
    f = False
if s1[0:n*m//3] == s1[0]*(n*m//3):
    v1.append(s1[0])
else:
    f1 = False    
    
    
if s[n*m//3:n*m//3*2] == s[n*m//3]*(n*m//3):
    v.append(s[n*m//3])
else:
    f = False
    
if s1[n*m//3:n*m//3*2] == s1[n*m//3]*(n*m//3):
    v1.append(s1[n*m//3])
else:
    f1 = False
 
    
    
if s[n*m//3*2:n*m] == s[n*m//3*2]*(n*m//3):
    v.append(s[n*m//3*2])
else:
    f = False
if s1[n*m//3*2:n*m] == s1[n*m//3*2]*(n*m//3):
    v1.append(s1[n*m//3*2])
else:
    f1 = False  
    
v.sort()
v1.sort()
#print(v,v1)
if f and v == ['B','G','R']:
    print('YES')
elif f1 and v1 == ['B','G','R']:
    print('YES')
else:
    print('NO')

n, m = list(map(int, input().split(' ')))
ls, col = [], []
for x in range(n):
    ls.append(input())
for i in range(m):
    elem = ''
    for x in ls:
        elem = ''.join([elem,x[i]])
    col.append(elem)

def ans():
    if n % 3 != 0 and m % 3 != 0:
        return 'NO'
    for x in ls:
        if any(y not in ['R', 'G', 'B'] for y in x):
            return 'NO'

    if n%3 == 0 and all(x == ls[0] for x in ls[0:n//3]) and all(x == ls[n//3] for x in ls[n//3:2*n//3]) and all(x == ls[2*n//3] for x in ls[2*n//3:n]):
        if ls[0] != ls[n//3] and ls[n//3] != ls[2*n//3]:
            for z in ['R', 'G', 'B']:
                tmp = [bool(z in ls[0]), bool(z in ls[n//3]), bool(z in ls[2*n//3])]
                if tmp.count(True) > 1:
                    return 'NO'
            return 'YES'
    if m%3 == 0 and all(x == col[0] for x in col[0:m//3]) and all(x == col[m//3] for x in col[m//3:2*m//3]) and all(x == col[2*m//3] for x in col[2*m//3:m]):
        if col[0] != col[m//3] and col[m//3] != col[2*m//3]:
            for z in ['R', 'G', 'B']:
                tmp = [bool(z in col[0]), bool(z in col[m//3]), bool(z in col[2*m//3])]
                if tmp.count(True) > 1:
                    return 'NO'
            return 'YES'
    return 'NO'
print(ans())



n, m = [int(el) for el in input().split()]
fl =  [input().split()  for i in range(n)]
fl1 = [['R'* m] for i in range  (n //3) ] + [['G' * m ]for i in range  (n //3) ] +  [['B'* m] for i in range  (n //3)]
fl2 = [['R'* m] for i in range  (n //3) ] + [['B'* m] for i in range  (n //3) ] +  [['G'* m] for i in range  (n //3)]
fl3 = [['B'* m] for i in range  (n //3) ] + [['G' * m] for i in range  (n //3) ] +  [['R' * m ]for i in range  (n //3)]
fl4 = [['B' * m] for i in range  (n //3) ] + [['R'* m ]for i in range  (n //3) ] +  [['G'* m] for i in range  (n //3)]
fl5 = [['G'* m] for i in range  (n //3) ] + [['R' * m ]for i in range  (n //3) ] +  [['B'* m] for i in range  (n //3)]
fl6 = [['G'* m] for i in range  (n //3) ] + [['B' * m ]for i in range  (n //3) ] +  [['R'* m ]for i in range  (n //3)]

fl7 =[['R' * ( m// 3) + 'G' * ( m// 3) + 'B' * ( m// 3)]  for i in range(n)]
fl8 =[['R' * ( m// 3) + 'B' * ( m// 3) + 'G' * ( m// 3) ] for i in range(n)]
fl9 =[['G' * ( m// 3) + 'B' * ( m// 3) + 'R' * ( m// 3) ] for i in range(n)]
fl10 =[['G' * ( m// 3) + 'R' * ( m// 3) + 'B' * ( m// 3)]  for i in range(n)]
fl11 =[['B' * ( m// 3) + 'G' * ( m// 3) + 'R' * ( m// 3) ] for i in range(n)]
fl12 =[['B' * ( m// 3) + 'R' * ( m// 3) + 'G' * ( m// 3) ] for i in range(n)]

if fl == fl1 or fl == fl2 or fl == fl3 or fl == fl4  or fl == fl5  or fl == fl6  or fl == fl7 or fl == fl8  or fl == fl9  or fl == fl10 or fl == fl11  or fl == fl12:
    print('YES')
else:
    print('NO')


import sys, math

n, m = list(map(int, input().split()))

a = ["" for i in range(n)]
for i in range(n):
    a[i] = input()

if (a[0][0] == a[0][m-1]) and (n % 3 == 0):
    for i in range(n // 3):
        for j in range(m):
            if (not a[i][j] == a[0][0]):
                print("NO")
                return
    for i in range(n // 3, 2 * n // 3):
        for j in range(m):
            if (not a[i][j] == a[n // 3][0]):
                print("NO")
                return
    for i in range(2 * n // 3, n):
        for j in range(m):
            if (not a[i][j] == a[2 * n // 3][0]):
                print("NO")
                return
    if (a[0][0] == a[n // 3][0]) or (a[0][0] == a[2 * n // 3][0]) or (a[2 * n // 3][0] == a[n // 3][0]):
        print("NO")
        return
    else:
        print("YES")
        return
elif (a[0][0] == a[n - 1][0]) and (m % 3 == 0):
    for i in range(n):
        for j in range(m // 3):
            if not ((a[i][j] == a[0][0]) and (a[i][j + m // 3] == a[0][m // 3]) and (
                a[i][j + 2 * m // 3] == a[0][2 * m // 3])):
                print("NO")
                return
    if (a[0][0] == a[0][m // 3]) or (a[0][0] == a[0][2 * m // 3]) or (a[0][2 * m // 3] == a[0][m // 3]):
        print("NO")
        return
    else:
        print("YES")
else:
    print("NO")


n,m = (int(i) for i in input().split())
flag = []
for i in range(n):
    flag += [input()]


count = {"R":0,"G":0,"B":0}

for line in flag:
    for let in line:
        count[let] += 1
check1 = True
change1 = 0
for i in range(n):
    if i < n-1 and flag[i][0] != flag[i+1][0]:
        change1+=1
    for j in range(m):
        if j < m-1 and flag[i][j] != flag[i][j+1]:
            check1 = False
if change1 != 2 or len({count["R"],count["G"],count["B"]}) > 1:
    check1 = False


check2 = True
change2 = 0
for j in range(m):
    if j < m-1 and flag[0][j] != flag[0][j+1]:
        change2+=1
    for i in range(n):
        if i < n-1 and flag[i][j] != flag[i+1][j]:
            check2 = False
if change2 != 2 or len({count["R"],count["G"],count["B"]}) > 1:
    check2 = False

if check2 or check1:
    print("YES")
else:
    print("NO")


n, m = list(map(int, input().split()))
fl = [input() for i in range(n)]
c1 = fl[0][0]
BOOL = False
for i in range(n):
    if fl[i][0] != c1:
        BOOL = True
        break
if BOOL:
    BOOL = False 
    if n % 3 == 0:
        for i in range(n // 3)[:n//3]:
            for j in range(m):
                if fl[i][j] != c1:
                    BOOL = True
        c2 = fl[n//3][0]
        if not BOOL:
            for i in range(n)[n//3:-(n//3)]:
                for j in range(m):
                    if fl[i][j] != c2:
                        BOOL = True
        c3 = fl[-(n//3)][0]
        if not BOOL:
            for i in range(n)[-(n//3):]:
                for j in range(m):
                    if fl[i][j] != c3:
                        BOOL = True
        if c1 == c2 or c2 == c3 or c1 == c3:
            print('NO')
        else:
            if  BOOL:
                print('NO')
            else:
                print('YES')
    else:
        print('NO')
else:
    if m % 3 == 0:
        for i in range(m)[:m//3]:
            for j in range(n):
                if fl[j][i] != c1:
                    BOOL = True
        c2 = fl[0][m//3]
        if not BOOL:
            for i in range(m)[m//3:-(m//3)]:
                for j in range(n):
                    if fl[j][i] != c2:
                        BOOL = True
        c3 = fl[0][-(m//3)]
        if not BOOL:
            for i in range(m)[-(m//3):]:
                for j in range(n):
                    if fl[j][i] != c3:
                        BOOL = True
        if c1 == c2 or c2 == c3 or c1 == c3:
            print('NO')
        else:
            if  BOOL:
                print('NO')
            else:
                print('YES')
    else:
        print('NO')


n, m = list(map(int, input().split()))
field = [input() for i in range(n)]

if n % 3 == 0:
    size = n // 3
    flag = True
    block = set()
    stripes = set()
    for i in range(n):
        if i % size == 0:
            block = set()
        for j in range(m):
            block.add(field[i][j])
        if (i + 1) % size == 0:
            if len(block) > 1:
                flag = False
            else:
                stripes.add(list(block)[0])
    if len(stripes) != 3:
        flag = False
    if flag:
        print('YES')
        return

if m % 3 == 0:
    size = m // 3
    flag = True
    block = set()
    stripes = set()
    for j in range(m):
        if j % size == 0:
            block = set()
        for i in range(n):
            block.add(field[i][j])
        if (j + 1) % size == 0:
            if len(block) > 1:
                flag = False
            else:
                stripes.add(list(block)[0])
    if len(stripes) != 3:
        flag = False
    if flag:
        print('YES')
        return

print('NO')


n, m = map(int, input().split())
A = [0 for i in range(n)]
for i in range(n):
    A[i] = input()

f1, f2 = True, True

colors = ["R", "G", "B"]
if n % 3 != 0:
    f1 = False
else:
    for i in range(3):
        if A[n//3 * i][0] in colors:
            qq = A[n//3 * i][0]
            colors.remove(A[n//3 * i][0])
        else:
            f1 = False
        for j in range(n//3 * i, n//3 *(i + 1) ):
            if A[j][0] != qq:
                f1 = False
                break
            for k in A[j]:
                if k != A[j][0]:
                    f1 = False
                    break
colors = ["R", "G", "B"]
if m % 3 != 0:
    f2 = False
else:
    for i in range(3):
        if A[0][m // 3 * i] in colors:
            qq = A[0][m // 3 * i]
            colors.remove(A[0][m // 3 * i])
        else:
            f2 = False
        
        for j in range(m//3 * i, m//3 *(i + 1) ):
            if A[0][j] != qq:
                f2 = False
                break
            for k in range(n):
                if A[k][j] != A[0][j]:
                    f2 = False
                    break



if f1 or f2:
    print("YES")
else:
    print("NO")