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: MEDIUM_HARD

Solutions:
(n, m) = map(int, input().split())
ls = []
for i in range(n):
	s = input()
	ls.append(s)
horizontal = []
f1 = True
for i in range(n):
	if ls[i] == ls[i][0] * len(ls[i]):
		if i == 0:
			horizontal.append([ls[i], 1])
		elif ls[i] == horizontal[-1][0]:
			horizontal[-1][1] += 1
		else:
			horizontal.append([ls[i], 1])
	else:
		f1 = False
		break
if len(horizontal) == 3 and horizontal[0][1] == horizontal[1][1] == horizontal[2][1]:
	if horizontal[0][0] != horizontal[1][0] and horizontal[0][0] != horizontal[2][0] and (horizontal[1][0] != horizontal[2][0]):
		s = ''
	else:
		f1 = False
else:
	f1 = False
new_ls = ['' for i in range(m)]
for i in range(n):
	for j in range(m):
		new_ls[j] += ls[i][j]
ls = new_ls
horizontal = []
f2 = True
for i in range(m):
	if ls[i] == ls[i][0] * len(ls[i]):
		if i == 0:
			horizontal.append([ls[i], 1])
		elif ls[i] == horizontal[-1][0]:
			horizontal[-1][1] += 1
		else:
			horizontal.append([ls[i], 1])
	else:
		f2 = False
		break
if len(horizontal) == 3 and horizontal[0][1] == horizontal[1][1] == horizontal[2][1]:
	if horizontal[0][0] != horizontal[1][0] and horizontal[0][0] != horizontal[2][0] and (horizontal[1][0] != horizontal[2][0]):
		s = ''
	else:
		f2 = False
else:
	f2 = False
if f1 or f2:
	print('YES')
else:
	print('NO')


def f(n, m, g):
	if n % 3:
		return False
	c = g[0][0] + g[n // 3][0] + g[n // 3 * 2][0]
	if len(set(c)) < 3:
		return False
	f = [c[i // (n // 3)] * m for i in range(n)]
	return f == g
(n, m) = map(int, input().split())
g = [input() for i in range(n)]
print('YES' if f(n, m, g) or f(m, n, [''.join((g[i][j] for i in range(n))) for j in range(m)]) else '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')


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)


(a, b) = input().split()
a = int(a)
b = int(b)
arr = []
Rflag = Gflag = Bflag = flag = False
for i in range(a):
	arr += [list(input().strip())]
if a % 3 == 0:
	flag = True
	for i in range(3):
		for j in range(a // 3):
			if j == 0 and flag == True:
				if arr[a // 3 * i + j].count('R') == b and Rflag == False:
					curr = ['R']
					Rflag = True
				elif arr[a // 3 * i + j].count('G') == b and Gflag == False:
					curr = ['G']
					Gflag = True
				elif arr[a // 3 * i + j].count('B') == b and Bflag == False:
					curr = ['B']
					Bflag = True
				else:
					flag = False
			elif flag == True:
				if arr[a // 3 * i + j] != curr * b:
					flag = False
if b % 3 == 0 and flag == False:
	arr = tuple(zip(*arr[::-1]))
	Rflag = Gflag = Bflag = False
	(a, b) = (b, a)
	flag = True
	for i in range(3):
		for j in range(a // 3):
			if j == 0 and flag == True:
				if arr[a // 3 * i + j].count('R') == b and Rflag == False:
					curr = 'R'
					Rflag = True
				elif arr[a // 3 * i + j].count('G') == b and Gflag == False:
					curr = 'G'
					Gflag = True
				elif arr[a // 3 * i + j].count('B') == b and Bflag == False:
					curr = 'B'
					Bflag = True
				else:
					flag = False
			elif flag == True:
				if arr[a // 3 * i + j].count(curr) != b:
					flag = False
if flag and Gflag and Bflag and Rflag:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
arr = [0] * n
for i in range(n):
	arr[i] = input()
was = []
dist = -1
m_dist = 0
chk1 = 1
chk2 = 1
prev_ans = arr[0][0]
was.append(arr[0][0])
allowed = ['R', 'B', 'G']
if not arr[0][0] in allowed:
	chk1 = 0
	chk2 = 0
for i in range(n):
	dist += 1
	for j in range(m):
		if arr[i][j] != prev_ans:
			if arr[i][j] in was or (m_dist != 0 and m_dist != dist) or (not arr[i][j] in allowed):
				chk1 = 0
			else:
				was.append(arr[i][j])
				prev_ans = arr[i][j]
				m_dist = dist
				dist = 0
		prev_ans = arr[i][j]
dist += 1
if len(was) != 3 or m_dist != dist:
	chk1 = 0
was = []
dist = -1
m_dist = 0
chk2 = 1
prev_ans = arr[0][0]
was.append(arr[0][0])
allowed = ['R', 'B', 'G']
for j in range(m):
	dist += 1
	for i in range(n):
		if arr[i][j] != prev_ans:
			if arr[i][j] in was or (m_dist != 0 and m_dist != dist) or (not arr[i][j] in allowed):
				chk2 = 0
			else:
				was.append(arr[i][j])
				prev_ans = arr[i][j]
				m_dist = dist
				dist = 0
		prev_ans = arr[i][j]
dist += 1
if len(was) != 3 or m_dist != dist:
	chk2 = 0
if chk1 or chk2:
	print('YES')
else:
	print('NO')


(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()
if f and v == ['B', 'G', 'R']:
	print('YES')
elif f1 and v1 == ['B', 'G', 'R']:
	print('YES')
else:
	print('NO')


def fn(s):
	ans = True
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			ans = False
	return ans

def chk(n, m, l):
	if n % 3 != 0:
		return False
	w = n // 3
	ls = []
	ans = True
	for i in range(0, 3):
		s = ''
		for j in range(i * w, i * w + w):
			s += l[j]
		ls.append(s)
	for i in range(3):
		ans = ans and fn(ls[i])
	return ans and ls[0] != ls[1] and (ls[1] != ls[2]) and (ls[0] != ls[2])
(n, m) = map(int, input().strip().split())
l = []
for i in range(n):
	l.append(str(input()))
if n % 3 != 0:
	x = 'v'
elif m % 3 != 0:
	x = 'h'
else:
	x = 'h'
	for i in range(m - 1):
		if l[0][i] != l[0][i + 1]:
			x = 'v'
if x == 'h':
	flag = chk(n, m, l)
elif x == 'v':
	ls = []
	for i in range(m):
		s = ''
		for j in range(n):
			s += l[j][i]
		ls.append(s)
	flag = chk(m, n, ls)
if flag:
	print('YES')
else:
	print('NO')


(N, M) = map(int, input().split())
flag = [input() for n in range(N)]

def get_rect_of_color(color):
	rect_points = []
	for (i, row) in enumerate(flag):
		first = True
		seq_is_broken = False
		tmp = [None] * 4
		for (j, char) in enumerate(row):
			if char == color:
				if first:
					first = False
					(tmp[0], tmp[1]) = (i, j)
				if seq_is_broken:
					raise Exception()
				(tmp[2], tmp[3]) = (i, j)
			elif not first:
				seq_is_broken = True
		if tmp[0] is not None:
			rect_points += [tmp]
	return rect_points

def get_bounding_rect(rect):
	last_pos = rect[0]
	first = True
	for row in rect:
		if first:
			first = False
			continue
		(ly1, lx1, ly2, lx2) = last_pos
		(y1, x1, y2, x2) = row
		if y1 - ly1 != 1 or y2 - ly2 != 1 or x1 - lx1 != 0 or (x2 - lx2 != 0):
			raise Exception()
		last_pos = row
	return ((rect[0][0], rect[0][1]), (rect[-1][2], rect[-1][3]))
try:
	R = get_bounding_rect(get_rect_of_color('R'))
	G = get_bounding_rect(get_rect_of_color('G'))
	B = get_bounding_rect(get_rect_of_color('B'))
	Rh = abs(R[1][0] - R[0][0])
	Bh = abs(B[1][0] - B[0][0])
	Gh = abs(G[1][0] - G[0][0])
	Rw = abs(R[1][1] - R[0][1])
	Bw = abs(B[1][1] - B[0][1])
	Gw = abs(G[1][1] - G[0][1])
	if len(set([Rw, Bw, Gw])) != 1 or len(set([Rh, Bh, Gh])) != 1:
		print('NO')
	else:
		print('YES')
except Exception:
	print('NO')


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()
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')


class CodeforcesTask837BSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.flag = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[0]):
			self.flag.append(input())

	def process_task(self):
		if self.n_m[0] % 3 and self.n_m[1] % 3:
			self.result = 'NO'
		else:
			variants = []
			if not self.n_m[0] % 3:
				c1 = self.flag[0][0]
				c2 = self.flag[self.n_m[0] // 3][0]
				c3 = self.flag[self.n_m[0] // 3 * 2][0]
				if c1 != c2 and c1 != c3 and (c3 != c2):
					l1 = []
					l2 = []
					l3 = []
					for x in range(self.n_m[0] // 3):
						l1.append(c1 * self.n_m[1])
						l2.append(c2 * self.n_m[1])
						l3.append(c3 * self.n_m[1])
					v = l1 + l2 + l3
					variants.append(v)
			if not self.n_m[1] % 3:
				c1 = self.flag[0][0]
				c2 = self.flag[0][self.n_m[1] // 3]
				c3 = self.flag[0][self.n_m[1] // 3 * 2]
				if c1 != c2 and c1 != c3 and (c3 != c2):
					x = self.n_m[1] // 3
					l = c1 * x + c2 * x + c3 * x
					v = [l for z in range(self.n_m[0])]
					variants.append(v)
			canbe = False
			for v in variants:
				c = True
				for x in range(self.n_m[0]):
					if self.flag[x] != v[x]:
						c = False
						break
				if c:
					canbe = True
					break
			self.result = 'YES' if canbe else 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask837BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(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')
		exit(0)
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')
		exit(0)
print('NO')


(n, m) = input().split()
n = int(n)
m = int(m)
flag = []
tes = []
RGB = {'R': 0, 'G': 0, 'B': 0}
for i in range(n):
	flag.append(['.'] * m)
	tes.append(['.'] * m)
for i in range(n):
	sting = input()
	for j in range(m):
		flag[i][j] = sting[j]
check = False
if n % 3 != 0 and m % 3 != 0:
	print('NO')
elif n % 3 == 0 and m % 3 != 0:
	l = int(n / 3)
	si1 = flag[0][0]
	RGB[si1] += 1
	si2 = flag[l][0]
	RGB[si2] += 1
	si3 = flag[l + l][0]
	RGB[si3] += 1
	for i in range(0, l):
		for j in range(m):
			tes[i][j] = si1
	for i in range(l, l + l):
		for j in range(m):
			tes[i][j] = si2
	for i in range(l + l, n):
		for j in range(m):
			tes[i][j] = si3
	if tes == flag and RGB['R'] == 1 and (RGB['G'] == 1) and (RGB['B'] == 1):
		print('YES')
	else:
		print('NO')
elif n % 3 != 0 and m % 3 == 0:
	l = int(m / 3)
	si1 = flag[0][0]
	RGB[si1] += 1
	si2 = flag[0][l]
	RGB[si2] += 1
	si3 = flag[0][l + l]
	RGB[si3] += 1
	for j in range(0, l):
		for i in range(n):
			tes[i][j] = si1
	for j in range(l, l + l):
		for i in range(n):
			tes[i][j] = si2
	for j in range(l + l, m):
		for i in range(n):
			tes[i][j] = si3
	if tes == flag and RGB['R'] == 1 and (RGB['G'] == 1) and (RGB['B'] == 1):
		print('YES')
	else:
		print('NO')
elif n % 3 == 0 and m % 3 == 0:
	q = 0
	l = int(n / 3)
	si1 = flag[0][0]
	RGB[si1] += 1
	si2 = flag[l][0]
	RGB[si2] += 1
	si3 = flag[l + l][0]
	RGB[si3] += 1
	for i in range(0, l):
		for j in range(m):
			tes[i][j] = si1
	for i in range(l, l + l):
		for j in range(m):
			tes[i][j] = si2
	for i in range(l + l, n):
		for j in range(m):
			tes[i][j] = si3
	if tes == flag and RGB['R'] == 1 and (RGB['G'] == 1) and (RGB['B'] == 1):
		print('YES')
		q = 1
	RGB['R'] = 0
	RGB['G'] = 0
	RGB['B'] = 0
	if q == 0:
		l = int(m / 3)
		si1 = flag[0][0]
		RGB[si1] += 1
		si2 = flag[0][l]
		RGB[si2] += 1
		si3 = flag[0][l + l]
		RGB[si3] += 1
		for j in range(0, l):
			for i in range(n):
				tes[i][j] = si1
		for j in range(l, l + l):
			for i in range(n):
				tes[i][j] = si2
		for j in range(l + l, m):
			for i in range(n):
				tes[i][j] = si3
		if tes == flag and RGB['R'] == 1 and (RGB['G'] == 1) and (RGB['B'] == 1):
			print('YES')
		else:
			print('NO')


(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')


(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 itertools

def check(lst):
	if not all((row.count(row[0]) == len(row) for row in lst)):
		return False
	_ = [[k, list(g)] for (k, g) in itertools.groupby([x[0] for x in lst])]
	(keys, groups) = zip(*_)
	keys = list(keys)
	return len(keys) == len(set(keys)) == 3 and len(set([len(list(x)) for x in groups])) == 1
import sys
(nrow, ncol) = map(int, sys.stdin.readline().split(' '))
data = list(map(list, sys.stdin.read().split('\n')[:nrow]))
sys.stdout.write('YES' if check(data) or check(list(zip(*data))) else '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]:
		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
	elif 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(' ')))
(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())


(b, k) = map(int, input().split())
arr = []
for i in range(b):
	s = input()
	arr.append(s)
x = arr[0][0]
nb = 1
nk = 1
pola = str(x)
while nk < k and arr[0][nk] == x:
	nk += 1
	pola += x
if nk == k or nk == k / 3:
	if nk == k / 3:
		arr = list(map(lambda x: ''.join(x), map(list, zip(*arr))))
		(b, k) = (k, b)
		nb = 1
		nk = 1
		pola = str(x)
		while nk < k and arr[0][nk] == x:
			nk += 1
			pola += x
	while nb < b and arr[nb][:nk] == pola:
		nb += 1
	if nb == b / 3:
		y = arr[nb][0]
		polay = ''
		for i in range(nk):
			polay += y
		nby = 0
		brs = nb
		while nby + nb < b and arr[nby + nb] == polay:
			nby += 1
		if nby == nb:
			z = arr[nby + nb][0]
			if z != x:
				polaz = ''
				for i in range(nk):
					polaz += z
				nbz = 0
				brs = nby + nb
				while nbz + nby + nb < b and arr[nbz + nby + nb] == polaz:
					nbz += 1
				if nbz == nb:
					print('YES')
				else:
					print('NO')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')
else:
	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')


(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 check(a):
	cur = a[0][0]
	d = {}
	for p in a:
		if p[0] != cur and p[0] in d:
			return 0
		cur = p[0]
		if not all([x == cur for x in p]):
			return 0
		d[cur] = d.get(cur, 0) + 1
	if len(d) != 3:
		return 0
	if not 'R' in d or not 'G' in d or (not 'B' in d):
		return 0
	cnt = d['R']
	if d['G'] != cnt or d['B'] != cnt:
		return 0
	return 1
(n, m) = map(int, input().split())
a = [list(input()) for i in range(n)]
if check(a):
	print('YES')
else:
	a = list(map(list, zip(*a)))
	if check(a):
		print('YES')
	else:
		print('NO')


import sys
(n, m) = map(int, input().split())
li = []
for _ in range(n):
	li.append(input())
if n % 3 == 0:
	flag = True
	stripe = n // 3
	s0 = li[0][0]
	s1 = li[stripe][0]
	s2 = li[stripe * 2][0]
	for i in range(stripe):
		for j in range(m):
			if li[i][j] != s0:
				flag = False
	for i in range(stripe, 2 * stripe):
		for j in range(m):
			if li[i][j] != s1:
				flag = False
	for i in range(2 * stripe, 3 * stripe):
		for j in range(m):
			if li[i][j] != s2:
				flag = False
	if flag == True and s0 != s1 and (s0 != s2) and (s1 != s2):
		print('YES')
		sys.exit()
if m % 3 == 0:
	flag = True
	stripe = m // 3
	s0 = li[0][0]
	s1 = li[0][stripe]
	s2 = li[0][stripe * 2]
	for i in range(n):
		for j in range(stripe):
			if li[i][j] != s0:
				flag = False
	for i in range(n):
		for j in range(stripe, 2 * stripe):
			if li[i][j] != s1:
				flag = False
	for i in range(n):
		for j in range(2 * stripe, 3 * stripe):
			if li[i][j] != s2:
				flag = False
	if flag == True and s0 != s1 and (s0 != s2) and (s1 != s2):
		print('YES')
		sys.exit()
print('NO')


import sys
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
if n % 3 and m % 3:
	print('NO')
	sys.exit()
b = []
c = []
f1 = True
f2 = True
st = ''
if n % 3 == 0:
	i = 0
	s = set()
	while i < n:
		if a[i][0] in s:
			f1 = False
			break
		s.add(a[i][0])
		for j in range(n // 3):
			b.append(a[i][0] * m)
		i += n // 3
if m % 3 == 0:
	i = 0
	s = set()
	while i < m:
		if a[0][i] in s:
			f2 = False
			break
		s.add(a[0][i])
		st += a[0][i] * (m // 3)
		i += m // 3
for i in range(n):
	c.append(st)
if not f1 and (not f2):
	print('NO')
elif f1 and a == b or (f2 and a == c):
	print('YES')
else:
	print('NO')


n_m = input().strip().split(' ')
n = int(n_m[0])
m = int(n_m[1])
flag = [[] for x in range(n)]
for i in range(n):
	line = input().strip()
	flag[i] = line
horizontal = True
c0 = flag[0][0]
line = flag[0]
for j in range(1, m):
	if line[j] != c0:
		horizontal = False
if horizontal:
	color_change = n / 3
	if n % 3 != 0:
		print('NO')
		exit()
	color = ''
	color_hor = []
	count = 0
	for i in range(n):
		line = flag[i]
		if i % color_change == 0:
			if i != 0:
				count += 1
			new_color = line[0]
			if new_color in color_hor:
				print('NO')
				exit()
			else:
				color_hor.append(new_color)
			if new_color == color:
				print('NO')
				exit()
			else:
				color = new_color
		for j in range(m):
			if line[j] != color:
				print('NO')
				exit()
else:
	color_change = m / 3
	if m % 3 != 0:
		print('NO')
		exit()
	color_hor = ''
	color_ver = []
	for i in range(n):
		line = flag[i]
		count = 0
		for j in range(m):
			if j % color_change == 0:
				if j != 0:
					count += 1
				new_color = line[j]
				if new_color in color_ver and i == 0:
					print('NO')
					exit()
				else:
					color_ver.append(new_color)
				if new_color == color_hor:
					print('NO')
					exit()
				else:
					color_hor = new_color
				if color_hor != color_ver[count]:
					print('NO')
					exit()
			if line[j] != color_hor:
				print('NO')
				exit()
print('YES')


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append([])
	s = input()
	for j in s:
		l[i].append(j)
A = 'YES'
a = True
b = True
if n % 3 != 0 and m % 3 != 0:
	A = 'NO'
if n % 3 == 0:
	s1 = l[0][0]
	for i in range(n // 3):
		for j in range(m):
			if l[i][j] != s1:
				a = False
	s2 = l[n // 3][0]
	for i in range(n // 3, n // 3 * 2):
		for j in range(m):
			if l[i][j] != s2:
				a = False
	s3 = l[n // 3 * 2][0]
	for i in range(n // 3 * 2, n):
		for j in range(m):
			if l[i][j] != s3:
				a = False
	if s1 == s2 or s2 == s3 or s1 == s3:
		a = False
else:
	a = False
if m % 3 == 0:
	s1 = l[0][0]
	for i in range(n):
		for j in range(m // 3):
			if l[i][j] != s1:
				b = False
	s2 = l[0][m // 3]
	for i in range(n):
		for j in range(m // 3, m // 3 * 2):
			if l[i][j] != s2:
				b = False
	s3 = l[0][m // 3 * 2]
	for i in range(n):
		for j in range(m // 3 * 2, m):
			if l[i][j] != s3:
				b = False
	if s1 == s2 or s2 == s3 or s1 == s3:
		b = False
else:
	b = False
if not a and (not b):
	A = 'NO'
print(A)


(n, m) = 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(map(lambda x: x * m, '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 by_col(n, m, lines):
	orders = [None] * 3
	n_div_3 = n // 3
	for i in range(3):
		cur_char = None
		for j in range(n_div_3):
			line = lines[i * n_div_3 + j]
			char = line[0]
			if cur_char == None:
				cur_char = char
			elif char != cur_char:
				return 'NO'
			if line.count(char) != m or char in orders:
				return 'NO'
		orders[i] = cur_char
	return 'YES'

def by_row(n, m, lines):
	m_div_3 = m // 3
	compare_line = None
	for i in range(n):
		line = lines[i]
		if compare_line == None:
			sub_1 = line[:m_div_3]
			if sub_1.count(sub_1[0]) != m_div_3:
				return 'NO'
			sub_2 = line[m_div_3:m_div_3 * 2]
			if sub_2.count(sub_2[0]) != m_div_3:
				return 'NO'
			sub_3 = line[m_div_3 * 2:]
			if sub_3.count(sub_3[0]) != m_div_3:
				return 'NO'
			if sub_1 != sub_2 and sub_1 != sub_3 and (sub_2 != sub_3):
				compare_line = line
			else:
				return 'NO'
		elif line != compare_line:
			return 'NO'
	return 'YES'
(n, m) = map(int, input().split())
n_mod_3 = n % 3
m_mod_3 = m % 3
if n_mod_3 != 0 and m_mod_3 != 0 or (n < 3 and m < 3):
	print('NO')
	exit()
lines = [None] * n
for i in range(n):
	lines[i] = input()
if n_mod_3 == 0 and m_mod_3 != 0:
	print(by_col(n, m, lines))
elif n_mod_3 != 0 and m_mod_3 == 0:
	print(by_row(n, m, lines))
elif by_col(n, m, lines) == 'YES' or by_row(n, m, lines) == 'YES':
	print('YES')
else:
	print('NO')


def checkline(i):
	mark = d[i][0]
	for j in range(m):
		if d[i][j] != mark:
			return 0
	return mark

def checkrow(i):
	mark = d[0][i]
	for j in range(n):
		if d[j][i] != mark:
			return 0
	return mark
(n, m) = map(int, input().split())
if n % 3 != 0 and m % 3 != 0:
	print('NO')
else:
	k = False
	d = []
	f = dict(zip(['R', 'G', 'B'], [0, 0, 0]))
	for i in range(n):
		h = []
		for x in input():
			h.append(x)
			f[x] += 1
		d.append(h)
	if f['R'] == f['G'] and f['G'] == f['B'] and (f['B'] == f['R']):
		if n % 3 == 0:
			a = []
			kk = True
			for i in range(n):
				a.append(checkline(i))
				if (a[i] != a[i - 1] and i != 0) and (not (i == n // 3 or i == 2 * n // 3)) or a[i] == 0:
					kk = False
			if kk:
				k = True
		a = []
		if m % 3 == 0 and (not k):
			kkk = True
			for i in range(m):
				a.append(checkrow(i))
				if (a[i] != a[i - 1] and i != 0) and (not (i == m // 3 or i == 2 * m // 3)) or a[i] == 0:
					kkk = False
					break
			if kkk:
				k = True
	if k:
		print('YES')
	else:
		print('NO')


def solve_h(lines):
	if len(lines) == 0:
		return False
	if len(lines) % 3 != 0:
		return False
	strip = len(lines) // 3
	colors = []
	for (i, line) in enumerate(lines):
		if i % strip == 0:
			colors.append(line[0])
		if not all((ch == colors[-1] for ch in line)):
			return False
	if set(colors) != set('RGB'):
		return False
	return True

def transpose(lines):
	return list((''.join(chs) for chs in zip(*lines)))

def solve_v(lines):
	return solve_h(transpose(lines))

def solve(lines):
	return solve_h(lines) or solve_v(lines)
(h, w) = map(int, input().split())
lines = [input() for _ in range(h)]
print('YES' if solve(lines) else 'NO')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
if n % 3 == 0:
	k = n // 3
	s1 = set()
	s2 = set()
	s3 = set()
	for i in range(k):
		for j in range(m):
			s1.add(A[i][j])
	for i in range(k, 2 * k):
		for j in range(m):
			s2.add(A[i][j])
	for i in range(2 * k, 3 * k):
		for j in range(m):
			s3.add(A[i][j])
	if len(s1) == len(s2) == len(s3) == 1 and len(s1 | s2 | s3) == 3:
		print('YES')
		exit(0)
B = [['0'] * n for _ in range(m)]
for i in range(n):
	for j in range(m):
		B[j][i] = A[i][j]
A = B
(n, m) = (m, n)
if n % 3 == 0:
	k = n // 3
	s1 = set()
	s2 = set()
	s3 = set()
	for i in range(k):
		for j in range(m):
			s1.add(A[i][j])
	for i in range(k, 2 * k):
		for j in range(m):
			s2.add(A[i][j])
	for i in range(2 * k, 3 * k):
		for j in range(m):
			s3.add(A[i][j])
	if len(s1) == len(s2) == len(s3) == 1 and len(s1 | s2 | s3) == 3:
		print('YES')
		exit(0)
print('NO')


(n, m) = map(int, input().split())
flag = [list() for x in range(n)]
h1 = True
for i in range(n):
	li = input()
	flag[i] = li
c0 = flag[0][0]
line = flag[0]
for j in range(1, m):
	if line[j] != c0:
		h1 = False
if not h1:
	cc = m / 3
	if m % 3 != 0:
		print('NO')
		exit()
	ch = ''
	color_ver = []
	for i in range(n):
		line = flag[i]
		kol = 0
		for j in range(m):
			if j % cc == 0:
				if j != 0:
					kol += 1
				new_color = line[j]
				if new_color in color_ver and i == 0:
					print('NO')
					exit()
				else:
					color_ver.append(new_color)
				if new_color == ch:
					print('NO')
					exit()
				else:
					ch = new_color
				if ch != color_ver[kol]:
					print('NO')
					exit()
			if line[j] != ch:
				print('NO')
				exit()
else:
	cc = n / 3
	if n % 3 != 0:
		print('NO')
		exit()
	co = ''
	ch = list()
	kol = 0
	for i in range(n):
		line = flag[i]
		if i % cc == 0:
			if i != 0:
				kol += 1
			new_color = line[0]
			if new_color in ch:
				print('NO')
				exit()
			else:
				ch.append(new_color)
			if new_color != co:
				co = new_color
			else:
				print('NO')
				exit()
		for j in range(m):
			if line[j] != co:
				print('NO')
				exit()
print('YES')


def f(n, m, a):
	d = dict()
	if n % 3 == 0:
		k = n // 3
	else:
		return False
	c = a[0][0]
	d = {}
	d[1] = c
	for i in range(k):
		for j in range(m):
			if c == a[i][j]:
				pass
			else:
				return False
	c = a[k][0]
	d[2] = c
	for i in range(k):
		for j in range(m):
			if c == a[k + i][j]:
				pass
			else:
				return False
	c = a[2 * k][0]
	d[3] = c
	for i in range(k):
		for j in range(m):
			if c == a[2 * k + i][j]:
				pass
			else:
				return False
	if d[1] != d[2] and d[2] != d[3] and (d[3] != d[1]):
		return True
	else:
		return False
(n, m) = list(map(int, input().strip().split()))
(h, v) = ([], [])
for i in range(n):
	s = str(input())
	r = []
	for el in s:
		r.append(el)
	h.append(r)
for i in range(m):
	r = []
	for j in range(n):
		r.append(h[j][i])
	v.append(r)
if f(n, m, h) or f(m, n, v):
	print('YES')
else:
	print('NO')


def rotate_90_degree_anticlckwise(matrix):
	new_matrix = []
	for i in range(len(matrix[0]), 0, -1):
		new_matrix.append(list(map(lambda x: x[i - 1], matrix)))
	return new_matrix
(n, m) = map(int, input().split())
mat = []
for i in range(n):
	temp = input()
	mat.append([i for i in temp])
(horiz, verti) = (False, False)
check = True
resH = []
for i in range(n):
	if mat[i].count(mat[i][0]) == m:
		first = mat[i][0]
		if resH:
			if resH[-1][0] == first:
				resH[-1][1] += 1
			else:
				resH.append([first, 1])
		else:
			resH.append([first, 1])
	else:
		check = False
		break
if len(resH) == 3 and check:
	if len(set([i[1] for i in resH])) == 1 and len(set([i[0] for i in resH])) == 3:
		horiz = True
newMat = rotate_90_degree_anticlckwise(mat)
check = True
resV = []
for i in range(m):
	if newMat[i].count(newMat[i][0]) == n:
		first = newMat[i][0]
		if resV:
			if resV[-1][0] == first:
				resV[-1][1] += 1
			else:
				resV.append([first, 1])
		else:
			resV.append([first, 1])
	else:
		check = False
		break
if len(resV) == 3 and check:
	if len(set([i[1] for i in resV])) == 1 and len(set([i[0] for i in resV])) == 3:
		verti = True
if horiz or verti:
	print('YES')
else:
	print('NO')


(height, width) = map(int, input().split())
a = [input() for i in range(height)]
c = {'r': 0, 'g': 0, 'b': 0}
p = {'r': 0, 'g': 0, 'b': 0}
color = {'r': False, 'g': False, 'b': False}
(horizontal, vertical) = (True, False)
for i in range(height):
	for j in range(width):
		color[a[i][j].lower()] = True
for i in range(height):
	for j in range(1, width):
		if a[i][j] != a[i][j - 1]:
			horizontal = False
			break
		c[a[i][j].lower()] += 1
if not horizontal:
	vertical = True
	for key in c.keys():
		c[key] = 0
	for i in range(width):
		for j in range(1, height):
			if a[j][i] != a[j - 1][i]:
				vertical = False
				break
			c[a[j][i].lower()] += 1
prev = None
if horizontal:
	for i in range(height):
		if prev is None:
			prev = a[i][0].lower()
			c[a[i][0].lower()] += 1
			p[a[i][0].lower()] += 1
		else:
			if prev != a[i][0].lower():
				p[a[i][0].lower()] += 1
				if p[a[i][0].lower()] >= 2:
					print('NO')
					exit()
				prev = a[i][0].lower()
			c[a[i][0].lower()] += 1
elif vertical:
	for i in range(width):
		if prev is None:
			prev = a[0][i].lower()
			c[a[0][i].lower()] += 1
		else:
			if prev != a[0][i].lower():
				p[a[0][i].lower()] += 1
				if p[a[0][i].lower()] >= 2:
					print('NO')
					exit()
				prev = a[0][i].lower()
			c[a[0][i].lower()] += 1
else:
	print('NO')
	exit()
if c['r'] == c['g'] == c['b'] and color['r'] and color['g'] and color['b']:
	print('YES')
else:
	print('NO')


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
(n, m) = il()
a = []
for i in range(n):
	a.append(list(ip()))
if n % 3 != 0 and m % 3 != 0:
	print('NO')
	exit(0)
fl = 1
if n % 3 == 0:
	x = n // 3
	d = {}
	for k in range(3):
		i = 0 + x * k
		ch = a[i][0]
		if d.get(ch):
			fl = 0
			break
		for i1 in range(x):
			for j in range(m):
				if ch != a[i1 + i][j]:
					fl = 0
					break
			if fl == 0:
				break
		d[ch] = 1
	if fl:
		print('YES')
		exit(0)
if m % 3 == 0:
	x = m // 3
	d = {}
	fl = 1
	for k in range(3):
		i = 0 + x * k
		ch = a[0][i]
		if d.get(ch):
			fl = 0
			break
		for i1 in range(x):
			for j in range(n):
				if ch != a[j][i1 + i]:
					fl = 0
					break
			if fl == 0:
				break
		d[ch] = 1
	if fl:
		print('YES')
		exit(0)
print('NO')


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left, bisect
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(input()[:-1])
(c1, c2) = (0, 0)
v = dc(int)
h = dc(int)
for i in range(n):
	v[l[i][0]] += 1
for i in range(m):
	h[l[0][i]] += 1
if v['R'] == v['G'] and v['G'] == v['B']:
	f = 0
	p = l[0][0]
	for i in range(v['R']):
		for j in range(m):
			if l[i][j] != p:
				f = 1
				break
	if f == 0:
		p = l[v['R']][0]
		for i in range(v['R'], 2 * v['R']):
			for j in range(m):
				if l[i][j] != p:
					f = 1
					break
		if f == 0:
			p = l[2 * v['R']][0]
			for i in range(2 * v['R'], n):
				for j in range(m):
					if l[i][j] != p:
						f = 1
						break
	if f == 0:
		print('YES')
	else:
		print('NO')
elif h['R'] == h['G'] and h['G'] == h['B']:
	f = 0
	p = l[0][0]
	for i in range(n):
		for j in range(h['R']):
			if l[i][j] != p:
				f = 1
				break
	if f == 0:
		p = l[0][h['R']]
		for i in range(n):
			for j in range(h['R'], 2 * h['R']):
				if l[i][j] != p:
					f = 1
					break
		if f == 0:
			p = l[0][2 * h['R']]
			for i in range(n):
				for j in range(2 * h['R'], m):
					if l[i][j] != p:
						f = 1
						break
	if f == 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
a = [input() for q in range(n)]
naw = a[0][0]
flag = n % 3 == 0 and a[0][0] != a[n // 3][0] and (a[0][0] != a[n // 3 * 2][0]) and (a[n // 3][0] != a[n // 3 * 2][0])
for q in range(n // 3):
	for q1 in range(len(a[q])):
		if a[q][q1] != naw:
			flag = False
naw = a[n // 3][0]
for q in range(n // 3, 2 * n // 3):
	for q1 in range(len(a[q])):
		if a[q][q1] != naw:
			flag = False
naw = a[n // 3 * 2][0]
for q in range(n // 3 * 2, n):
	for q1 in range(len(a[q])):
		if a[q][q1] != naw:
			flag = False
if flag:
	print('YES')
else:
	s = [[a[q][q1] for q in range(n)] for q1 in range(m)]
	(n, m, a) = (m, n, s)
	naw = a[0][0]
	flag = n % 3 == 0 and a[0][0] != a[n // 3][0] and (a[0][0] != a[n // 3 * 2][0]) and (a[n // 3][0] != a[n // 3 * 2][0])
	for q in range(n // 3):
		for q1 in range(len(a[q])):
			if a[q][q1] != naw:
				flag = False
	naw = a[n // 3][0]
	for q in range(n // 3, 2 * n // 3):
		for q1 in range(len(a[q])):
			if a[q][q1] != naw:
				flag = False
	naw = a[n // 3 * 2][0]
	for q in range(n // 3 * 2, n):
		for q1 in range(len(a[q])):
			if a[q][q1] != naw:
				flag = False
	if flag:
		print('YES')
	else:
		print('NO')


(n, _) = map(int, input().split())
s = input()
n -= 1
a = ''
k = 0
if 'R' in s:
	k += 1
if 'G' in s:
	k += 1
if 'B' in s:
	k += 1
t = 1
if k > 1:
	a = s
	for _ in range(n):
		s1 = input()
		if s1 != s:
			t = 0
			break
elif k == 1:
	a += s[0]
	for _ in range(n):
		s = input()
		a += s[0]
		k = 0
		if 'R' in s:
			k += 1
		if 'G' in s:
			k += 1
		if 'B' in s:
			k += 1
		if k != 1:
			t = 0
			break

def f(a):
	if len(a) % 3 > 0:
		return 1
	b = len(a) // 3
	if a[0] * b + a[b] * b + a[-1] * b != a:
		return 1
	k = 0
	if 'R' in a:
		k += 1
	if 'G' in a:
		k += 1
	if 'B' in a:
		k += 1
	if k != 3:
		return 1
	return 0
if t == 0 or f(a):
	print('NO')
else:
	print('YES')


(n, m) = 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')
		elif BOOL:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
elif 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')
	elif BOOL:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
a = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	s = input()
	for j in range(m):
		a[i][j] = s[j]
ch = 0
if n % 3 == 0:
	c = n // 3
	k = 0
	c1 = 1
	c2 = 1
	c3 = 1
	color1 = a[0][0]
	for i in range(c):
		for j in range(m):
			if a[i][j] != color1:
				c1 = 0
	k += c
	color2 = a[k][0]
	for i in range(k, k + c):
		for j in range(m):
			if a[i][j] != color2:
				c2 = 0
	k += c
	color3 = a[k][0]
	for i in range(k, k + c):
		for j in range(m):
			if a[i][j] != color3:
				c3 = 0
	if c1 == c2 == c3 == 1 and color1 != color2 and (color2 != color3) and (color3 != color1):
		ch = 1
if m % 3 == 0:
	c = m // 3
	k = 0
	c1 = 1
	c2 = 1
	c3 = 1
	color1 = a[0][0]
	for i in range(n):
		for j in range(c):
			if a[i][j] != color1:
				c1 = 0
	k += c
	color2 = a[0][k]
	for i in range(n):
		for j in range(k, k + c):
			if a[i][j] != color2:
				c2 = 0
	k += c
	color3 = a[0][k]
	for i in range(n):
		for j in range(k, k + c):
			if a[i][j] != color3:
				c3 = 0
	if c1 == c2 == c3 == 1 and color1 != color2 and (color2 != color3) and (color3 != color1):
		ch = 1
if ch == 1:
	print('YES')
else:
	print('NO')


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()


(altura, largura) = map(int, input().split())
band = [input() for i in range(altura)]
new_bandeira = [''.join(coluna) for coluna in zip(*band)]

def confere(bandeira, altura):
	flag = True
	for linha in bandeira:
		cor = linha[0]
		if cor * len(linha) != linha:
			flag = False
			break
	dicionario = {}
	for linha in bandeira:
		if linha not in dicionario:
			dicionario[linha] = 0
		dicionario[linha] += 1
	for d in dicionario:
		if dicionario[d] != altura / 3:
			flag = False
	ir = []
	ib = []
	ig = []
	for (i, linha) in enumerate(bandeira):
		if linha[0] == 'R':
			ir.append(i)
		if linha[0] == 'B':
			ib.append(i)
		if linha[0] == 'G':
			ig.append(i)
	if flag:
		if len(ir) == 2:
			if not ir[1] - ir[0] == ib[1] - ib[0] == ig[1] - ig[0] == 1:
				flag = False
		if len(ir) > 2:
			dif = 1
			for i in range(1, len(ir)):
				if ir[i] - ir[i - 1] != dif:
					flag = False
				if ib[i] - ib[i - 1] != dif:
					flag = False
				if ig[i] - ig[i - 1] != dif:
					flag = False
	if flag:
		return True
	else:
		return False
if confere(band, altura) or confere(new_bandeira, largura):
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
ls = []
for i in range(n):
	ls.append(input())
if ls[0] != 'R' * m and ls[0] != 'G' * m and (ls[0] != 'B' * m):
	ls1 = []
	for i in range(m):
		row = ''
		for j in range(n):
			row += ls[j][i]
		ls1.append(row)
	ls = ls1
	m = n
	n = len(ls1)
if n % 3 != 0:
	print('NO')
else:
	first = ls[0][0]
	i = 0
	while i < n and ls[i] == first * m:
		i += 1
	if i < n and i == n // 3:
		second = ls[i][0]
		while i < n and ls[i] == second * m:
			i += 1
		if i < n and i == 2 * (n // 3):
			third = ls[i][0]
			while i < n and ls[i] == third * m:
				i += 1
			if i == n and third != first:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


inp = input().split()
n = [int(inp[0]), int(inp[1])]
flag = [[], []]
flag[0] = [input().rstrip() for i in range(n[0])]
flag[1] = list(map(list, zip(*flag[0])))
ok = False
for i in [0, 1]:
	if n[i] % 3 == 0 and (not ok):
		cols = set()
		ok = True
		for k in [0, 1, 2]:
			beg = n[i] // 3 * k
			end = n[i] // 3 * (k + 1)
			if flag[i][beg][0] in cols:
				ok = False
				break
			cols.add(flag[i][beg][0])
			for j in range(beg, end):
				if flag[i][j][0] != flag[i][beg][0]:
					ok = False
					break
			else:
				continue
			break
		for line in flag[i]:
			col = line[0]
			for cell in line:
				if col != cell:
					ok = False
					break
			else:
				continue
			break
if ok:
	print('YES')
else:
	print('NO')


def tran(lis, b, n, m):
	for i in range(m):
		for j in range(n):
			b[i][j] = lis[j][i]

def call(n, lis):
	ans = []
	cv = 1
	for i in range(0, n, n // 3):
		a = []
		for j in range(n // 3):
			a += lis[i + j]
		a = set(a)
		if len(a) > 1:
			cv = 0
			break
		b = list(a)[0]
		ans.append(b)
	if len(set(ans)) != 3:
		cv = 0
	if cv == 1:
		print('YES')
		exit()
(n, m) = map(int, input().split())
lis = []
b = [[0 for x in range(n)] for y in range(m)]
for i in range(n):
	l = list(input())
	lis.append(l)
if n % 3 != 0 and m % 3 != 0:
	print('NO')
	exit()
if n % 3 == 0:
	call(n, lis)
if m % 3 == 0:
	tran(lis, b, n, m)
	call(m, b)
print('NO')


(y, x) = map(int, input().split())
ls = []
for i in range(y):
	ls.append(input())
if ls[0].count(ls[0][0]) == x:
	ls = list(zip(*ls))
	(x, y) = (y, x)
(nr, ng, nb) = (ls[0].count('R'), ls[0].count('G'), ls[0].count('B'))
ch = 0
for i in range(1, x):
	if ls[0][i] != ls[0][i - 1]:
		ch += 1
if nr + ng + nb != x or nr != ng or nr != nb or (ch != 2):
	print('NO')
else:
	for i in ls:
		if i != ls[0]:
			print('NO')
			break
	else:
		print('YES')


def transpose(l):
	(rows, cols) = (len(l), len(l[0]))
	(rows, cols) = (cols, rows)
	return [''.join([l[col][row] for col in range(cols)]) for row in range(rows)]

def all_equal(l):
	first = l[0]
	return all(map(lambda x: x == first, l))

def solve():
	(height, width) = map(int, input().split())
	flag = []
	for _ in range(height):
		line = input().strip()
		if len(line) != width:
			return False
		flag.append(line)
	if height == 1 and width < 3 or (height < 3 and width == 1):
		return False
	if not all_equal(flag[0]):
		flag = transpose(flag)
		(width, height) = (height, width)
	used_colors = set()
	other_lines = None
	current_lines = 0
	current_color = flag[0][0]
	used_colors.add(current_color)
	for i in range(height):
		if flag[i][0] != current_color:
			current_color = flag[i][0]
			if current_color in used_colors:
				return False
			else:
				used_colors.add(current_color)
			if other_lines is None:
				other_lines = current_lines
			elif current_lines != other_lines:
				return False
			current_lines = 0
		if not all_equal(flag[i]):
			return False
		current_lines += 1
	return current_lines == other_lines and len(used_colors) == 3
if solve():
	print('YES')
else:
	print('NO')


import re, sys
(n, m) = map(int, input().split())
s = sys.stdin.read()
d = s.split('\n')
d.remove('')
rgb = 'RGB'
f = True
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')
	exit(0)
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')
	exit(0)
print('NO')


[n, m] = [int(i) for i in input().split()]
flag = []
flip_flag = []
for i in range(m):
	flip_flag.append([])
tmp = n
while tmp:
	tmp -= 1
	flag.append(list(input()))
	for i in range(m):
		flip_flag[i].append(flag[-1][i])
if len(set(flag[0])) != 1:
	flag = flip_flag
strip_count = {}
valid = True
strip_count[flag[0][0]] = 1
if len(set(flag[0])) != 1:
	valid = False
for i in range(1, len(flag)):
	if len(set(flag[i])) != 1 or valid == False:
		valid = False
		break
	if flag[i][0] not in strip_count.keys():
		strip_count[flag[i][0]] = 1
	elif flag[i][0] != flag[i - 1][0]:
		valid = False
		break
	else:
		strip_count[flag[i][0]] += 1
if len(set(strip_count.values())) != 1:
	valid = False
if not (all((i in strip_count.keys() for i in ['R', 'G', 'B'])) and len(set(strip_count.keys())) == 3):
	valid = False
print('YES' if valid else 'NO')


def is_horizontal():
	if n % 3 == 0:
		colors = {}
		diff_colors = set()
		stripe_hight = n // 3
		for k in range(3):
			colors[k] = flag[k * stripe_hight][0]
			diff_colors.add(colors[k])
			for i in range(k * stripe_hight, k * stripe_hight + stripe_hight):
				for j in range(m):
					if flag[i][j] != colors[k]:
						return False
		if len(diff_colors) != 3:
			return False
		return True

def is_vertical():
	if m % 3 == 0:
		colors = {}
		diff_colors = set()
		width = m // 3
		for k in range(3):
			colors[k] = flag[0][k * width]
			diff_colors.add(colors[k])
			for j in range(k * width, k * width + width):
				for i in range(n):
					if flag[i][j] != colors[k]:
						return False
		if len(diff_colors) != 3:
			return False
		return True

def is_flag():
	if n % 3 == 0 or m % 3 == 0:
		if is_horizontal() or is_vertical():
			return 'YES'
	return 'NO'
(n, m) = map(int, input().split())
flag = []
for i in range(n):
	flag.append(input())
print(is_flag())


(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
(n, m) = map(int, input().split())
flag = [list(input()) for _ in range(n)]
if len(set(flag[0])) > 1:
	_flag = [[''] * n for _ in range(m)]
	for i in range(n):
		for j in range(m):
			_flag[j][i] = flag[i][j]
	flag = _flag
	(n, m) = (m, n)
if not all((len(set(row)) == 1 for row in flag)):
	print('NO')
	exit()
color = {flag[0][0]}
length = [1]
prev = flag[0][0]
for i in range(1, n):
	if prev == flag[i][0]:
		length[-1] += 1
	else:
		prev = flag[i][0]
		color.add(flag[i][0])
		length.append(1)
if len(color) == 3 and len(length) == 3 and (len(set(length)) == 1):
	print('YES')
else:
	print('NO')


import sys
n = input()
a = []
(n, m) = n.split()
n = int(n)
m = int(m)
for i in range(n):
	a.append(input())
if m % 3 != 0 and n % 3 != 0:
	print('NO')
	sys.exit()
count = 1
for i in a:
	for j in i:
		if j != i[0]:
			count = 0
			break
	if count == 0:
		break
if count == 1:
	if n % 3 != 0:
		print('NO')
		sys.exit()
	n = int(n / 3)
	if a[0][0] == a[n][0] or a[0][0] == a[2 * n][0] or a[n][0] == a[int(2 * n)][0]:
		print('NO')
		sys.exit()
	for i in range(n):
		if a[0][0] != a[i][0] or a[n][0] != a[n + i][0] or a[2 * n][0] != a[2 * n + i][0]:
			print('NO')
			sys.exit()
	print('YES')
else:
	if m % 3 != 0:
		print('NO')
		sys.exit()
	for i in range(m):
		for j in range(n):
			if a[0][i] != a[j][i]:
				print('NO')
				sys.exit()
	m = int(m / 3)
	if a[0][0] == a[0][m] or a[0][0] == a[0][2 * m] or a[0][m] == a[0][int(2 * m)]:
		print('NO')
		sys.exit()
	for i in range(m):
		if a[0][0] != a[0][i] or a[0][m] != a[0][m + i] or a[0][2 * m] != a[0][2 * m + i]:
			print('NO')
			sys.exit()
	print('YES')


def check_line(line):
	line_color = line[0][0]
	for row in line:
		for color in row:
			if color != line_color:
				return False
	return True

def check_flag(flag, n, m):
	is_vertical = len(set(flag[0])) > 1
	row_has_3_colors = len(set(flag[0])) == 3
	col_has_3_colors = len(set([row[0] for row in flag])) == 3
	if not (row_has_3_colors or col_has_3_colors):
		return False
	if is_vertical:
		dimension = m
	else:
		dimension = n
	unproportional = dimension % 3 != 0
	if unproportional:
		return False
	step = dimension // 3
	for k in range(3):
		if is_vertical:
			is_consistent = check_line([flag[row][k * step:(k + 1) * step] for row in range(n)])
		else:
			is_consistent = check_line(flag[k * step:(k + 1) * step])
		if not is_consistent:
			return False
	return True

def main():
	(n, m) = map(int, input().split())
	flag = [None for i in range(n)]
	for i in range(n):
		flag[i] = input()
	flag_is_correct = check_flag(flag, n, m)
	if flag_is_correct:
		print('YES')
	else:
		print('NO')
main()


def check(stx, sty, x, y):
	for i in range(stx, stx + x):
		for j in range(sty, sty + y):
			if g[i][j] != g[stx][sty]:
				return False
	return True
(n, m) = map(int, input().split())
g = [input() for i in range(n)]
if n % 3 == 0 and check(0, 0, n // 3, m) and check(n // 3, 0, n // 3, m) and check(n // 3 * 2, 0, n // 3, m) and (g[0][0] != g[n // 3 * 2][0]) and (g[0][0] != g[n // 3][0]) and (g[n // 3][0] != g[n // 3 * 2][0]) or (m % 3 == 0 and check(0, 0, n, m // 3) and check(0, m // 3, n, m // 3) and check(0, m // 3 * 2, n, m // 3) and (g[0][0] != g[0][m // 3]) and (g[0][0] != g[0][m // 3 * 2]) and (g[0][m // 3] != g[0][m // 3 * 2])):
	print('YES')
else:
	print('NO')


import sys
(n, m) = map(int, input().split())
s = []
for i in range(n):
	string = input()
	s.append(string)
no = 0
r_mix = 0
for i in range(n):
	cnt_r = s[i].count('R')
	cnt_b = s[i].count('B')
	cnt_g = s[i].count('G')
	if cnt_r and cnt_b or (cnt_b and cnt_g) or (cnt_g and cnt_r):
		r_mix = 1
c_mix = 0
for j in range(m):
	cnt_r = cnt_b = cnt_g = 0
	for i in range(n):
		if s[i][j] == 'R':
			cnt_r += 1
		elif s[i][j] == 'B':
			cnt_b += 1
		elif s[i][j] == 'G':
			cnt_g += 1
	if cnt_r and cnt_b or (cnt_b and cnt_g) or (cnt_g and cnt_r):
		c_mix = 1
if r_mix == 1 and c_mix == 1 or (r_mix == 0 and c_mix == 0):
	no = 1
if r_mix == 1:
	cnt_b = cnt_g = cnt_r = 0
	if s[0][0] == 'R':
		cnt_r += 1
	elif s[0][0] == 'G':
		cnt_g += 1
	elif s[0][0] == 'B':
		cnt_b += 1
	(f, c) = (-1, 1)
	for j in range(0, m - 1):
		if s[0][j] == s[0][j + 1]:
			c += 1
		else:
			if s[0][j + 1] == 'R':
				cnt_r += 1
			elif s[0][j + 1] == 'G':
				cnt_g += 1
			elif s[0][j + 1] == 'B':
				cnt_b += 1
			if f == -1:
				f = c
			if f != c:
				no = 1
				break
			c = 1
	if f != c or (cnt_r != 1 or cnt_b != 1 or cnt_g != 1):
		no = 1
if c_mix:
	f = -1
	c = 1
	cnt_b = 0
	cnt_g = 0
	cnt_r = 0
	if s[0][0] == 'R':
		cnt_r += 1
	elif s[0][0] == 'G':
		cnt_g += 1
	elif s[0][0] == 'B':
		cnt_b += 1
	for i in range(0, n - 1):
		if s[i][0] == s[i + 1][0]:
			c += 1
		else:
			if s[i + 1][0] == 'R':
				cnt_r += 1
			elif s[i + 1][0] == 'G':
				cnt_g += 1
			elif s[i + 1][0] == 'B':
				cnt_b += 1
			if f == -1:
				f = c
			if f != c:
				no = 1
				break
			c = 1
	if f != c or (cnt_r != 1 or cnt_b != 1 or cnt_g != 1):
		no = 1
if no == 1:
	print('NO')
else:
	print('YES')


(n, m) = list(map(int, input().split()))
res = max(n, m) >= 3
is_horo = True
is_vert = True
if res:
	flag = []
	for i in range(n):
		r = input()
		if len(r) != m:
			res = False
			break
		flag.append(list(r))
	px = flag[0][0]
	for i in range(1, m):
		if flag[0][i] != px:
			is_horo = False
			break
	for i in range(1, n):
		if flag[i][0] != px:
			is_vert = False
			break
	res = is_horo ^ is_vert
compressed = []
if res:
	if is_horo:
		for r in flag:
			px = r[0]
			for c in r[1:]:
				if c != px:
					res = False
					break
			compressed.append(px)
	elif is_vert:
		for i in range(m):
			px = flag[0][i]
			for j in range(1, n):
				if flag[j][i] != px:
					res = False
					break
			compressed.append(px)
if res and compressed:
	stripe_width = None
	c_stripe = None
	c_width = 0
	widths = []
	seen = set()
	for stripe in compressed:
		if c_stripe is None:
			c_stripe = stripe
			c_width = 1
		elif c_stripe != stripe:
			seen.add(c_stripe)
			widths.append(c_width)
			c_width = 1
			c_stripe = stripe
		else:
			c_width += 1
	widths.append(c_width)
	seen.add(c_stripe)
	if len(widths) != 3 or len(seen) != 3:
		res = False
	else:
		first = widths[0]
		for i in range(1, len(widths)):
			if widths[i] != first:
				res = False
				break
print('YES' if res else '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')


import itertools
(n, m) = map(int, input().split())
flag = []
for _ in range(n):
	flag.append(input())

def check(flag):
	if len(flag) % 3 or len(set(itertools.chain(*flag))) != 3:
		return False
	width = len(flag) // 3
	for i in range(3):
		line = set()
		for j in range(width):
			line.update(set(flag[i * width + j]))
		if len(line) != 1:
			return False
	return True
print('YES' if check(flag) or check(list(zip(*flag))) else '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 matrixTranspose(matrix):
	if not matrix:
		return []
	return [[row[i] for row in matrix] for i in range(len(matrix[0]))]

def f(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())
if n * m % 3 != 0:
	print('NO')
else:
	ans = 'NO'
	f = [input() for _ in range(n)]
	if n % 3 == 0:
		for x in f:
			if len(set(x)) != 1:
				pass
				break
		else:
			if any((len(set(f[n * (i - 1) // 3:n * i // 3])) != 1 for i in range(1, 4))):
				pass
			elif len(set([f[0], f[n // 3], f[2 * n // 3]])) != 3:
				pass
			else:
				ans = 'YES'
	if m % 3 == 0:
		c = []
		for x in range(m):
			s = ''
			for y in range(n):
				s += f[y][x]
			c.append(s)
		for x in c:
			if len(set(x)) != 1:
				pass
				break
		else:
			if any((len(set(c[m * (i - 1) // 3:m * i // 3])) != 1 for i in range(1, 3))):
				pass
			elif len(set([c[0], c[m // 3], c[2 * m // 3]])) != 3:
				pass
			else:
				ans = 'YES'
	print(ans)


import sys
(r, c) = [int(x) for x in input().split()]
V = []
for i in range(r):
	V.append(input())
d = {'R': 0, 'G': 0, 'B': 0}
napa = True
zeta = []
for i in range(r):
	alpha = V[i][0]
	if len(zeta) != 0:
		if alpha != zeta[-1] and alpha in zeta:
			napa = False
			break
		else:
			zeta.append(alpha)
	else:
		zeta.append(alpha)
	for j in range(c):
		if V[i][j] == alpha:
			continue
		else:
			napa = False
	if not napa:
		break
	else:
		d[alpha] += 1
if napa == True:
	if d['R'] == d['G'] == d['B']:
		print('YES')
		sys.exit(0)
	else:
		print('NO')
		sys.exit(0)
d = {'R': 0, 'G': 0, 'B': 0}
napa = True
zeta = []
for i in range(c):
	alpha = V[0][i]
	if len(zeta) != 0:
		if alpha != zeta[-1] and alpha in zeta:
			napa = False
			break
		else:
			zeta.append(alpha)
	else:
		zeta.append(alpha)
	for j in range(r):
		if V[j][i] == alpha:
			continue
		else:
			napa = False
	if not napa:
		break
	else:
		d[alpha] += 1
if napa == True:
	if d['R'] == d['G'] == d['B']:
		print('YES')
		sys.exit(0)
	else:
		print('NO')
		sys.exit(0)
else:
	print('NO')


(n, m) = list(map(int, input().split()))
l = [0] * n
for i in range(n):
	l[i] = input()
types = ['B', 'G', 'R']
first = []
second = []
third = []
countb = 0
countr = 0
countg = 0
counter = 0
container = 0
ans = []
ans1 = []
if l[0].count('B') == l[0].count('R') and l[0].count('B') == l[0].count('G'):
	first.append(l[0][0])
	types.remove(first[0])
	for i in range(len(l[0])):
		if first[-1] == l[0][i]:
			counter += 1
		else:
			first[0] = first[0] * counter
			break
	first1 = first.copy()
	second.append(types[0])
	second[0] = second[0] * counter
	second1 = second.copy()
	third.append(types[1])
	third[0] = third[0] * counter
	list(third)
	third1 = third.copy()
	first = first[0] + second[0] + third[0]
	first1 = first1[0] + third[0] + second[0]
	ans.append(first)
	ans1.append(first1)
	ans *= n
	ans1 *= n
else:
	for i in l:
		countb += i.count('B')
		countr += i.count('R')
		countg += i.count('G')
	if countb == countr == countg:
		first.append(l[0])
		for i in range(len(l)):
			if first[-1] == l[i]:
				first.append(l[i])
			else:
				break
		first.pop(0)
		types.remove(first[0][0])
		first1 = first.copy()
		second.append(0)
		second[0] = types[0] * len(l[0])
		second *= len(first)
		second1 = second.copy()
		third.append(0)
		third[0] = types[1] * len(l[0])
		third *= len(first)
		third1 = third.copy()
		first += second
		first += third
		first1 += third1
		first1 += second1
		ans = first
		ans1 = first1
if ans == l or ans1 == l:
	print('YES')
	exit()
else:
	print('NO')
	exit()


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
f1 = 0
f2 = 0
if n % 3 == 0:
	f1 = 1
	o1 = a[0][0]
	o2 = a[n // 3][0]
	o3 = a[2 * n // 3][0]
	if o1 == o2 or o2 == o3 or o1 == o3:
		f1 = 0
	else:
		for i in range(n):
			if i < n // 3:
				if a[i] != o1 * m:
					f1 = 0
					break
			elif i < 2 * n // 3:
				if a[i] != o2 * m:
					f1 = 0
					break
			elif a[i] != o3 * m:
				f1 = 0
				break
if m % 3 == 0:
	f2 = 1
	o1 = a[0][0]
	o2 = a[0][m // 3]
	o3 = a[0][2 * m // 3]
	if o1 == o2 or o2 == o3 or o1 == o3:
		f2 = 0
	else:
		for i in range(n):
			for j in range(m):
				if j < m // 3:
					if a[i][j] != o1:
						f2 = 0
						break
				elif j < 2 * m // 3:
					if a[i][j] != o2:
						f2 = 0
						break
				elif a[i][j] != o3:
					f2 = 0
					break
			if not f2:
				break
if f1 or f2:
	print('YES')
else:
	print('NO')


import sys, math
(n, m) = 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')
				sys.exit()
	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')
				sys.exit()
	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')
				sys.exit()
	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')
		sys.exit()
	else:
		print('YES')
		sys.exit()
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')
				sys.exit()
	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')
		sys.exit()
	else:
		print('YES')
else:
	print('NO')


from collections import defaultdict
from itertools import groupby
(n, m) = map(int, input().split())
arr = []
cases = n
dic = defaultdict(int)
while cases:
	cases -= 1
	s = input()
	dic[s] += 1
	arr.append(s)
if len(dic) == 3 == len(list(groupby(arr))) and len(set(dic.values())) == 1 and ([set(key) for key in sorted(dic.keys())] == [{'B'}, {'G'}, {'R'}]):
	print('YES')
elif len(dic) == 1 and arr[0].count('R') == arr[0].count('G') == arr[0].count('B') and (len(list(groupby(arr[0]))) == 3):
	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')


def check(b):
	i = len(b[0]) // 3
	c = [b[0][0], b[0][i], b[0][2 * i]]
	if len(set(c)) != 3:
		return 0
	j = 0
	for p in range(len(b)):
		j = 0
		for k in range(3):
			if len(set(b[p][j:j + i])) == 1 and set(b[p][j:j + i]) == {c[k]}:
				j += i
				continue
			else:
				return 0
	return 1
(n, m) = map(int, input().split())
a = [input() for i in range(n)]
if n % 3 != 0 and m % 3 != 0:
	print('NO')
elif n % 3 == 0 and m % 3 == 0:
	if check(a) or check(list(map(list, zip(*a)))):
		print('YES')
	else:
		print('NO')
elif n % 3 == 0:
	if check(list(map(list, zip(*a)))):
		print('YES')
	else:
		print('NO')
elif m % 3 == 0:
	if check(a):
		print('YES')
	else:
		print('NO')


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
(n, m) = map(int, input().split())
f = []
for i in range(n):
	f.append(input())
if n % 3 == 0:
	R = []
	for i in range(n // 3):
		R.append('R' * m)
	B = []
	for i in range(n // 3):
		B.append('B' * m)
	G = []
	for i in range(n // 3):
		G.append('G' * m)
	if f == R + B + G or f == R + G + B:
		print('YES')
		exit()
	if f == B + R + G or f == B + G + R:
		print('YES')
		exit()
	if f == G + B + R or f == G + R + B:
		print('YES')
		exit()
if m % 3 == 0:
	R = 'R' * (m // 3)
	B = 'B' * (m // 3)
	G = 'G' * (m // 3)
	if f == [R + B + G] * n or f == [R + G + B] * n:
		print('YES')
		exit()
	if f == [B + G + R] * n or f == [B + R + G] * n:
		print('YES')
		exit()
	if f == [G + B + R] * n or f == [G + R + B] * n:
		print('YES')
		exit()
print('NO')


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
if n % 3 != 0 and m % 3 != 0:
	print('NO')
	exit()
flag = 0
if n % 3 == 0:
	if not (s[0][0] != s[n // 3][0] and s[2 * n // 3][0] != s[n // 3][0] and (s[2 * n // 3][0] != s[0][0])):
		flag = 1
	(r, g, b) = (0, 0, 0)
	if s[0][0] == 'R':
		r = 1
	elif s[0][0] == 'G':
		g = 1
	else:
		b = 1
	for i in range(n // 3):
		for j in range(m):
			if s[i][j] == 'G' and g != 1:
				flag = 1
			elif s[i][j] == 'R' and r != 1:
				flag = 1
			elif s[i][j] == 'B' and b != 1:
				flag = 1
	if s[n // 3][0] == 'R':
		if r == 1:
			flag = 1
		r = 1
		(g, b) = (0, 0)
	elif s[n // 3][0] == 'G':
		if g == 1:
			flag = 1
		g = 1
		(r, b) = (0, 0)
	else:
		if b == 1:
			flag = 1
		b = 1
		(r, g) = (0, 0)
	for i in range(n // 3, 2 * n // 3):
		for j in range(m):
			if s[i][j] == 'G' and g != 1:
				flag = 1
			elif s[i][j] == 'R' and r != 1:
				flag = 1
			elif s[i][j] == 'B' and b != 1:
				flag = 1
	if s[2 * n // 3][0] == 'R':
		if r == 1:
			flag = 1
		r = 1
		(g, b) = (0, 0)
	elif s[2 * n // 3][0] == 'G':
		if g == 1:
			flag = 1
		g = 1
		(r, b) = (0, 0)
	else:
		if b == 1:
			flag = 1
		b = 1
		(r, g) = (0, 0)
	for i in range(2 * n // 3, n):
		for j in range(m):
			if s[i][j] == 'G' and g != 1:
				flag = 1
			elif s[i][j] == 'R' and r != 1:
				flag = 1
			elif s[i][j] == 'B' and b != 1:
				flag = 1
	if flag == 0:
		print('YES')
		exit()
flag = 0
if m % 3 == 0:
	if not (s[0][0] != s[0][m // 3] and s[0][2 * m // 3] != s[0][m // 3] and (s[0][0] != s[0][2 * m // 3])):
		flag = 1
	(r, g, b) = (0, 0, 0)
	if s[0][0] == 'R':
		r += 1
	elif s[0][0] == 'G':
		g += 1
	else:
		b += 1
	for j in range(m // 3):
		for i in range(n):
			if s[i][j] == 'G' and g != 1:
				flag = 1
			elif s[i][j] == 'R' and r != 1:
				flag = 1
			elif s[i][j] == 'B' and b != 1:
				flag = 1
	if s[0][m // 3] == 'R':
		if r == 1:
			flag = 1
		r = 1
		(g, b) = (0, 0)
	elif s[0][m // 3] == 'G':
		if g == 1:
			flag = 1
		g = 1
		(r, b) = (0, 0)
	else:
		if b == 1:
			flag = 1
		b = 1
		(r, g) = (0, 0)
	for j in range(m // 3, 2 * m // 3):
		for i in range(n):
			if s[i][j] == 'G' and g != 1:
				flag = 1
			elif s[i][j] == 'R' and r != 1:
				flag = 1
			elif s[i][j] == 'B' and b != 1:
				flag = 1
	if s[0][2 * m // 3] == 'R':
		if r == 1:
			flag = 1
		r = 1
		(g, b) = (0, 0)
	elif s[0][2 * m // 3] == 'G':
		if g == 1:
			flag = 1
		g = 1
		(r, b) = (0, 0)
	else:
		if b == 1:
			flag = 1
		b = 1
		(r, g) = (0, 0)
	for j in range(2 * m // 3, m):
		for i in range(n):
			if s[i][j] == 'G' and g != 1:
				flag = 1
			elif s[i][j] == 'R' and r != 1:
				flag = 1
			elif s[i][j] == 'B' and b != 1:
				flag = 1
	if flag == 0:
		print('YES')
		exit()
print('NO')


def rotate(matrix):
	global n, m
	new_matrix = [[0 for i in range(n)] for j in range(m)]
	for i in range(n):
		for j in range(m):
			new_matrix[j][i] = matrix[i][j]
	return new_matrix

def check(tab, n, m):
	colors = set()
	color = tab[0][0]
	colors.add(color)
	for i in range(n // 3):
		for j in range(m):
			if tab[i][j] != color:
				return False
	color = tab[n // 3][0]
	colors.add(color)
	for i in range(n // 3, n // 3 * 2):
		for j in range(m):
			if tab[i][j] != color:
				return False
	color = tab[n // 3 * 2][0]
	colors.add(color)
	for i in range(n // 3 * 2, n):
		for j in range(m):
			if tab[i][j] != color:
				return False
	if len(colors) == 3:
		return True
	return False
(n, m) = map(int, input().split())
tab = [list(input()) for i in range(n)]
tf = False if n % 3 else check(tab, n, m)
tfr = False if m % 3 else check(rotate(tab), m, n)
if tf or tfr:
	print('YES')
else:
	print('NO')


def solve(h, w, f):
	if h % 3:
		return False
	a = f[0][0]
	b = f[h // 3][0]
	c = f[2 * h // 3][0]
	if a == b or b == c or c == a:
		return False
	for y in range(h // 3):
		if f[y].count(a) != w:
			return False
	for y in range(h // 3, 2 * h // 3):
		if f[y].count(b) != w:
			return False
	for y in range(2 * h // 3, h):
		if f[y].count(c) != w:
			return False
	return True

def main():
	(h, w) = map(int, input().split())
	f = [input() for _ in range(h)]
	g = [''.join([f[y][x] for y in range(h)]) for x in range(w)]
	ans = solve(h, w, f) or solve(w, h, g)
	print(ans and 'YES' or 'NO')
main()


list_1 = []
list_2 = []
index_n = 0
index_m = 0
(n, m) = map(int, input().split())
for i in range(n):
	ch1 = str(input())
	list_1.append(ch1)
if n % 3 != 0:
	index_n = 1
if m % 3 != 0:
	index_m = 1
if n % 3 == 0:
	a = n / 3
	for i in range(n):
		ch1 = list_1[i]
		if i % a == 0:
			ch2 = ch1
			list_2.append(ch2[0])
			for j in range(m - 1):
				if ch2[j] != ch2[j + 1]:
					index_n = 1
		if ch2 != ch1:
			index_n = 1
	if 'R' in list_2 and 'G' in list_2 and ('B' in list_2):
		b = 1
	else:
		index_n = 1
list_2 = []
if m % 3 == 0:
	a = int(m / 3)
	ch1 = list_1[0]
	for i in range(3):
		for j in range(a):
			if j == 0:
				list_2.append(ch1[i * a + j])
			if j != a - 1:
				if ch1[i * a + j] != ch1[i * a + 1 + j]:
					index_m = 1
	for i in range(n):
		if ch1 != list_1[i]:
			index_m = 1
	if 'R' in list_2 and 'G' in list_2 and ('B' in list_2):
		b = 1
	else:
		index_m = 1
if index_n == 0 or index_m == 0:
	print('YES')
else:
	print('NO')


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, m) = M()
l = []
flag = 0
for i in range(n):
	s = input().strip()
	x = set([])
	for j in s:
		x.add(j)
	if len(x) == 1:
		flag = 1
	l.append(s)
if flag == 1 and n % 3 != 0:
	print('NO')
	exit()
elif flag == 1 and n % 3 == 0:
	x = set([])
	c = 0
	for i in range(n // 3):
		if l[i] == l[0]:
			c += 1
		r = set([])
		for j in l[i]:
			r.add(j)
		if len(r) == 1:
			x.add(str(l[i]))
			if len(x) != 1:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	if c != n // 3:
		print('NO')
		exit()
	c = 0
	for i in range(n // 3, 2 * n // 3):
		if l[i] == l[n // 3]:
			c += 1
		r = set([])
		for j in l[i]:
			r.add(j)
		if len(r) == 1:
			x.add(str(l[i]))
			if len(x) != 2:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	if c != n // 3:
		print('NO')
		exit()
	c = 0
	for i in range(2 * n // 3, n):
		if l[i] == l[2 * n // 3]:
			c += 1
		r = set([])
		for j in l[i]:
			r.add(j)
		if len(r) == 1:
			x.add(str(l[i]))
			if len(x) != 3:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	if c != n // 3:
		print('NO')
		exit()
	if len(x) == 3:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
else:
	if m % 3 != 0:
		print('NO')
		exit()
	e = []
	for i in range(m):
		x = []
		for j in range(n):
			x.append(l[j][i])
		e.append(x)
	l = e[:]
	d = n
	n = m
	m = d
	x = set([])
	c = 0
	for i in range(n // 3):
		if l[i] == l[0]:
			c += 1
		r = set([])
		for j in l[i]:
			r.add(j)
		if len(r) == 1:
			x.add(str(l[i]))
			if len(x) != 1:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	if c != n // 3:
		print('NO')
		exit()
	c = 0
	for i in range(n // 3, 2 * n // 3):
		if l[i] == l[n // 3]:
			c += 1
		r = set([])
		for j in l[i]:
			r.add(j)
		if len(r) == 1:
			x.add(str(l[i]))
			if len(x) != 2:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	if c != n // 3:
		print('NO')
		exit()
	c = 0
	for i in range(2 * n // 3, n):
		if l[i] == l[2 * n // 3]:
			c += 1
		r = set([])
		for j in l[i]:
			r.add(j)
		if len(r) == 1:
			x.add(str(l[i]))
			if len(x) != 3:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	if c != n // 3:
		print('NO')
		exit()
	if len(x) == 3:
		print('YES')
		exit()
	else:
		print('NO')
		exit()


(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')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = [list(input().rstrip()) for i in range(n)]
tate = True
yoko = True
if n < 3:
	yoko = False
if m < 3:
	tate = False
for i in range(n - 1):
	if a[i][0] != a[i + 1][0]:
		tate = False
for j in range(m - 1):
	if a[0][j] != a[0][j + 1]:
		yoko = False
if not tate ^ yoko:
	print('NO')
	exit()
if tate:
	if m % 3 != 0:
		print('NO')
		exit()
	c1 = a[0][0]
	c2 = a[0][m // 3]
	c3 = a[0][2 * m // 3]
	if c1 == c2 or c2 == c3 or c3 == c1:
		print('NO')
		exit()
	flag = True
	for i in range(n):
		for j in range(m // 3):
			if c1 != a[i][j]:
				flag = False
		for j in range(m // 3, 2 * m // 3):
			if c2 != a[i][j]:
				flag = False
		for j in range(2 * m // 3, m):
			if c3 != a[i][j]:
				flag = False
	if flag:
		print('YES')
	else:
		print('NO')
else:
	if n % 3 != 0:
		print('NO')
		exit()
	c1 = a[0][0]
	c2 = a[n // 3][0]
	c3 = a[2 * n // 3][0]
	if c1 == c2 or c2 == c3 or c3 == c1:
		print('NO')
		exit()
	flag = True
	for j in range(m):
		for i in range(n // 3):
			if c1 != a[i][j]:
				flag = False
		for i in range(n // 3, 2 * n // 3):
			if c2 != a[i][j]:
				flag = False
		for i in range(2 * n // 3, n):
			if c3 != a[i][j]:
				flag = False
	if flag:
		print('YES')
	else:
		print('NO')


import sys

def verifyFlag(flagList, row, column):
	if row % 3 != 0:
		return False
	q = row // 3
	u = [flagList[0 * q], flagList[1 * q], flagList[2 * q]]
	us = set(u)
	patternToMatch = set()
	for color in ['R', 'G', 'B']:
		patternToMatch.add(color * column)
	if us != patternToMatch:
		return False
	for (i, row) in enumerate(flagList):
		if row != u[i // q]:
			return False
	return True

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	a = []
	for i in range(n):
		a.append(sys.stdin.readline().rstrip())
	b = []
	for i in range(m):
		temp = ''
		for j in range(n):
			temp += a[j][i]
		b.append(temp)
	rv1 = verifyFlag(a, n, m)
	rv2 = verifyFlag(b, m, n)
	if rv1 or rv2:
		print('YES')
	else:
		print('NO')
main()


vv = input()
n = int(vv[0:vv.find(' ')])
m = int(vv[vv.find(' '):])
x = ''
for mm in range(n):
	x += input()
col = 0
row = 0
res = True
types = 0
if x[0] == x[n * m - m]:
	if m % 3 == 0:
		col = m // 3
		row = n
		types = 1
	else:
		res = False
elif x[0] == x[m - 1]:
	if n % 3 == 0:
		col = m
		row = n // 3
		types = 2
	else:
		res = False
else:
	res = False
c1 = ''
c2 = ''
c3 = ''
if res:
	if types == 1:
		for i in range(row):
			for j in range(col):
				c1 += x[j + m * i]
		for i in range(row):
			for j in range(col, col * 2):
				c2 += x[j + m * i]
		for i in range(row):
			for j in range(col * 2, col * 3):
				c3 += x[j + m * i]
	if types == 2:
		for i in range(m * n // 3):
			c1 += x[i]
		for i in range(m * n // 3, m * n // 3 * 2):
			c2 += x[i]
		for i in range(m * n // 3 * 2, m * n):
			c3 += x[i]
if res:
	let1 = c1[0]
	for i in c1:
		if i != let1:
			res = False
			break
	if res:
		let2 = c2[0]
		if let1 == let2:
			res = False
		else:
			for i in c2:
				if i != let2:
					res = False
					break
	if res:
		let3 = c3[0]
		if let1 == let3 or let2 == let3:
			res = False
		else:
			for i in c3:
				if i != let3:
					res = False
					break
if res:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
ll = []
for i in range(n):
	ll.append(input())
if n % 3 == 0 or m % 3 == 0:
	l1 = ll[0][0]
	l2 = ll[n // 3][0]
	l3 = ll[2 * (n // 3)][0]
	t = False
	if l1 != l2 and l2 != l3 and (l1 != l3) and (n % 3 == 0):
		t = True
		for i in range(n):
			for j in range(m):
				if 0 <= i < n // 3:
					if ll[i][j] != l1:
						t = False
						break
				elif n // 3 <= i < 2 * (n // 3):
					if ll[i][j] != l2:
						t = False
						break
				elif ll[i][j] != l3:
					t = False
					break
			if t == False:
				break
	if t == False and m % 3 == 0:
		l2 = ll[0][m // 3]
		l3 = ll[0][2 * (m // 3)]
		if l1 != l2 and l2 != l3 and (l1 != l3):
			t = True
			for i in range(m):
				for j in range(n):
					if 0 <= i < m // 3:
						if ll[j][i] != l1:
							t = False
							break
					elif m // 3 <= i < 2 * (m // 3):
						if ll[j][i] != l2:
							t = False
							break
					elif ll[j][i] != l3:
						t = False
						break
				if t == False:
					break
	print('YES' if t == True else 'NO')
else:
	print('NO')