During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.

It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.

To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.

Cube is called solved if for each face of cube all squares on it has the same color.

https://en.wikipedia.org/wiki/Rubik's_Cube


-----Input-----

In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.


-----Output-----

Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.


-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4

Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3

Output
YES


-----Note-----

In first test case cube looks like this: [Image] 

In second test case cube looks like this:  [Image] 

It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation

Complete search


Solutions:
a = [0]
a.extend(list(map(int, input().split())))
if a[2] == a[4] == a[22] == a[24] and a[1] == a[3] == a[6] == a[8] and (a[13] == a[14] == a[15] == a[16]) and (a[17] == a[18] == a[19] == a[20]) and (a[21] == a[23] == a[9] == a[11]) and (a[5] == a[7] == a[10] == a[12]):
	print('YES')
elif a[13] == a[14] == a[15] == a[16] and a[17] == a[18] == a[19] == a[20] and (a[2] == a[4] == a[5] == a[7]) and (a[6] == a[8] == a[9] == a[11]) and (a[10] == a[12] == a[22] == a[24]) and (a[1] == a[3] == a[21] == a[23]):
	print('YES')
elif a[1] == a[2] == a[3] == a[4] and a[9] == a[10] == a[11] == a[12] and (a[13] == a[14] == a[23] == a[24]) and (a[5] == a[6] == a[15] == a[16]) and (a[17] == a[18] == a[7] == a[8]) and (a[21] == a[22] == a[19] == a[20]):
	print('YES')
elif a[1] == a[2] == a[3] == a[4] and a[9] == a[10] == a[11] == a[12] and (a[13] == a[14] == a[7] == a[8]) and (a[5] == a[6] == a[19] == a[20]) and (a[17] == a[18] == a[23] == a[24]) and (a[21] == a[22] == a[15] == a[16]):
	print('YES')
elif a[5] == a[6] == a[7] == a[8] and a[21] == a[22] == a[23] == a[24] and (a[3] == a[4] == a[13] == a[15]) and (a[14] == a[16] == a[11] == a[12]) and (a[9] == a[10] == a[18] == a[20]) and (a[17] == a[19] == a[1] == a[2]):
	print('YES')
elif a[5] == a[6] == a[7] == a[8] and a[21] == a[22] == a[23] == a[24] and (a[3] == a[4] == a[18] == a[20]) and (a[14] == a[16] == a[1] == a[2]) and (a[9] == a[10] == a[13] == a[15]) and (a[17] == a[19] == a[11] == a[12]):
	print('YES')
else:
	print('NO')


from collections import Counter

def only_one(a):
	return len(Counter(a)) == 1
colors = list(map(int, input().split()))
pairs = ((1, 3), (2, 6), (4, 5))
new_pairs = list()
f = False
c = 0
count = 0
pair = tuple()
for i in pairs:
	(a, b) = (((i[0] - 1) * 4, i[0] * 4), ((i[1] - 1) * 4, i[1] * 4))
	if only_one(colors[a[0]:a[1]]) and only_one(colors[b[0]:b[1]]):
		f = True
		c += 1
		pair = i
	if only_one(colors[a[0]:a[1]]):
		count += 1
	if only_one(colors[b[0]:b[1]]):
		count += 1
	else:
		new_pairs.append(i)
if not f or c != 1 or count != 2:
	print('NO')
else:
	C = colors
	if pair == pairs[0]:
		one = [C[12], C[13], C[4], C[5], C[16], C[17], C[20], C[21]]
		two = [C[14], C[15], C[6], C[7], C[18], C[19], C[22], C[23]]
		if one[2:] + one[:2] == two or one[6:] + one[:6] == two:
			print('YES')
			exit()
	elif pair == pairs[1]:
		one = [C[2], C[3], C[16], C[18], C[9], C[8], C[15], C[13]]
		two = [C[0], C[1], C[17], C[19], C[11], C[10], C[14], C[12]]
		if one[2:] + one[:2] == two or one[6:] + one[:6] == two:
			print('YES')
			exit()
	elif pair == pairs[2]:
		one = [C[0], C[2], C[4], C[6], C[8], C[10], C[23], C[21]]
		two = [C[1], C[3], C[5], C[7], C[9], C[11], C[22], C[20]]
		if one[2:] + one[:2] == two or one[6:] + one[:6] == two:
			print('YES')
			exit()
	print('NO')


l = list(map(int, input().split()))
U = l[0:4]
F = l[4:8]
D = l[8:12]
L = l[12:16]
R = l[16:20]
B = l[20:24]
if L.count(L[0]) == 4 and R.count(R[0]) == 4:
	if D[1] == D[3] == F[0] == F[2] and F[1] == F[3] == U[0] == U[2] and (U[1] == U[3] == B[1] == B[3]) and (B[0] == B[2] == D[0] == D[2]):
		print('YES')
	elif D[1] == D[3] == B[1] == B[3] and B[0] == B[2] == U[0] == U[2] and (U[1] == U[3] == F[0] == F[2]) and (F[1] == F[3] == D[0] == D[2]):
		print('YES')
	else:
		print('NO')
elif U.count(U[0]) == 4 and D.count(D[0]) == 4:
	if L[0] == L[1] == F[2] == F[3] and F[0] == F[1] == R[2] == R[3] and (R[0] == R[1] == B[2] == B[3]) and (B[0] == B[1] == L[2] == L[3]):
		print('YES')
	elif L[0] == L[1] == B[2] == B[3] and B[0] == B[1] == R[2] == R[3] and (R[0] == R[1] == F[2] == F[3]) and (F[0] == F[1] == L[2] == L[3]):
		print('YES')
	else:
		print('NO')
elif F.count(F[0]) == 4 and B.count(B[0]) == 4:
	if L[0] == L[2] == U[2] == U[3] and U[0] == U[1] == R[0] == R[2] and (R[1] == R[3] == D[0] == D[1]) and (D[2] == D[3] == L[1] == L[3]):
		print('YES')
	elif L[0] == L[2] == D[0] == D[1] and D[2] == D[3] == R[0] == R[2] and (R[1] == R[3] == U[3] == U[2]) and (U[0] == U[1] == L[1] == L[3]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


a = list(map(int, input().split()))
(x, i) = (0, 0)
w = []
while i < 24:
	n = len(set(a[i:i + 4]))
	if n == 1:
		x += 1
	elif n == 2:
		w.append(set(a[i:i + 4]))
	i += 4
w = set((frozenset(i) for i in w))
print(['NO', 'YES'][x == 2 and len(set(w)) == 4])


import sys

def check(q):
	if q[1] == q[2] == q[3] == q[4] and q[5] == q[6] == q[7] == q[8] and (q[9] == q[10] == q[11] == q[12]) and (q[13] == q[14] == q[15] == q[16]) and (q[17] == q[18] == q[19] == q[20]) and (q[21] == q[22] == q[23] == q[24]):
		return True
	else:
		return False
a = [0] + [int(x) for x in input().split()]
swaps = []
b = a[:]
b[17] = a[3]
b[19] = a[4]
b[10] = a[17]
b[9] = a[19]
b[14] = a[9]
b[16] = a[10]
b[4] = a[14]
b[3] = a[16]
if check(b):
	print('YES')
	return
b = a[:]
b[17] = a[10]
b[19] = a[9]
b[10] = a[16]
b[9] = a[14]
b[14] = a[4]
b[16] = a[3]
b[4] = a[19]
b[3] = a[17]
if check(b):
	print('YES')
	return
b = a[:]
b[13] = a[21]
b[14] = a[22]
b[5] = a[13]
b[6] = a[14]
b[17] = a[5]
b[18] = a[6]
b[21] = a[17]
b[22] = a[18]
if check(b):
	print('YES')
	return
b = a[:]
b[21] = a[13]
b[22] = a[14]
b[13] = a[5]
b[14] = a[6]
b[5] = a[17]
b[6] = a[18]
b[17] = a[21]
b[18] = a[22]
if check(b):
	print('YES')
	return
b = a[:]
b[7] = a[19]
b[8] = a[20]
b[19] = a[23]
b[20] = a[24]
b[23] = a[15]
b[24] = a[16]
b[15] = a[7]
b[16] = a[8]
if check(b):
	print('YES')
	return
b = a[:]
b[19] = a[7]
b[20] = a[8]
b[23] = a[19]
b[24] = a[20]
b[15] = a[23]
b[16] = a[24]
b[7] = a[15]
b[8] = a[16]
if check(b):
	print('YES')
	return
b = a[:]
b[1] = a[5]
b[3] = a[7]
b[5] = a[9]
b[7] = a[11]
b[9] = a[22]
b[11] = a[24]
b[22] = a[1]
b[24] = a[3]
if check(b):
	print('YES')
	return
b = a[:]
b[5] = a[1]
b[7] = a[3]
b[9] = a[5]
b[11] = a[7]
b[22] = a[9]
b[24] = a[11]
b[1] = a[22]
b[3] = a[24]
if check(b):
	print('YES')
	return
b = a[:]
b[10] = a[6]
b[12] = a[8]
b[6] = a[2]
b[8] = a[4]
b[2] = a[23]
b[4] = a[21]
b[23] = a[10]
b[21] = a[12]
if check(b):
	print('YES')
	return
b = a[:]
b[6] = a[10]
b[8] = a[12]
b[2] = a[6]
b[4] = a[8]
b[23] = a[2]
b[21] = a[4]
b[10] = a[23]
b[12] = a[21]
if check(b):
	print('YES')
	return
b = a[:]
b[1] = a[18]
b[2] = a[20]
b[18] = a[12]
b[20] = a[11]
b[12] = a[15]
b[11] = a[13]
b[15] = a[1]
b[13] = a[2]
if check(b):
	print('YES')
	return
b = a[:]
b[18] = a[1]
b[20] = a[2]
b[12] = a[18]
b[11] = a[20]
b[15] = a[12]
b[13] = a[11]
b[1] = a[15]
b[2] = a[13]
if check(b):
	print('YES')
	return
print('NO')


def f(a, d):
	newa = a[:]
	for i in range(24):
		if i + 1 in d:
			newa[d[i + 1] - 1] = a[i]
	for i in range(0, 22, 4):
		if not newa[i] == newa[i + 1] == newa[i + 2] == newa[i + 3]:
			return False
	return True
arr = list(map(int, input().split()))
var = [dict() for i in range(10)]
var[0][2] = 6
var[0][4] = 8
var[0][6] = 10
var[0][8] = 12
var[0][10] = 23
var[0][12] = 21
var[0][23] = 2
var[0][21] = 4
var[0][17] = 19
var[0][19] = 20
var[0][20] = 18
var[0][18] = 17
var[2][1] = 5
var[2][3] = 7
var[2][5] = 9
var[2][7] = 11
var[2][9] = 24
var[2][11] = 22
var[2][24] = 1
var[2][22] = 3
var[2][13] = 14
var[2][15] = 13
var[2][16] = 15
var[2][14] = 16
var[4][13] = 5
var[4][14] = 6
var[4][5] = 17
var[4][6] = 18
var[4][17] = 21
var[4][18] = 22
var[4][21] = 13
var[4][22] = 14
var[4][1] = 3
var[4][3] = 4
var[4][4] = 2
var[4][2] = 1
var[6][15] = 7
var[6][16] = 8
var[6][7] = 19
var[6][8] = 20
var[6][19] = 23
var[6][20] = 24
var[6][23] = 15
var[6][24] = 16
var[6][9] = 10
var[6][10] = 12
var[6][12] = 11
var[6][11] = 9
var[8][3] = 17
var[8][4] = 19
var[8][17] = 10
var[8][19] = 9
var[8][10] = 16
var[8][9] = 14
var[8][16] = 3
var[8][14] = 4
var[8][5] = 6
var[8][6] = 8
var[8][7] = 5
var[8][8] = 7
for i in range(0, 9, 2):
	for j in range(1, 25):
		if j in var[i]:
			var[i + 1][var[i][j]] = j
for i in range(10):
	if f(arr, var[i]):
		print('YES')
		exit()
print('NO')


import itertools, sys
id = '\n  12\n  34\nef56ijmn\ngh78klop\n  9a\n  bc\n'
transforms = [[[1, 2, 3, 4], [22, 21, 18, 17, 6, 5, 14, 13]], [[9, 10, 11, 12], [15, 16, 7, 8, 19, 20, 23, 24]], [[5, 6, 7, 8], [3, 4, 17, 19, 10, 9, 16, 14]], [[13, 14, 15, 16], [1, 3, 5, 7, 9, 11, 24, 22]], [[17, 18, 19, 20], [4, 2, 21, 23, 12, 10, 8, 6]], [[21, 22, 24, 23], [2, 1, 13, 15, 11, 12, 20, 18]]]

def rot(c, perm, rev):
	new = list(c)
	if rev:
		for i in range(len(perm)):
			new[perm[i] - 1] = c[perm[(i + 1) % len(perm)] - 1]
	else:
		for i in range(len(perm)):
			new[perm[(i + 1) % len(perm)] - 1] = c[perm[i] - 1]
	return new

def do_t(c, t, rev):
	return rot(rot(rot(c, t[0], rev), t[1], rev), t[1], rev)
faces = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]
colors = input().split()
for (rev, t) in itertools.product([0, 1], transforms):
	newc = do_t(colors, t, rev)
	ok = True
	for f in faces:
		fc = [newc[i - 1] for i in f]
		if fc.count(fc[0]) != 4:
			ok = False
	if ok:
		print('YES')
		return
print('NO')


r = ['111155223333224466554466', '111144223333664422555566', '114422225533434315156666', '115522224433414135356666', '111122553333442255666644', '111122443333446655226655', '212132326363444455556161', '616112122323444455556363', '121223233636444455551616', '161621213232444455553636', '551122223344141453536666', '441122223355343451516666']
a = ''.join(input().split(' '))
for b in r:
	ok = True
	for i in range(24):
		for j in range(24):
			if b[i] == b[j] and a[i] != a[j] or (b[i] != b[j] and a[i] == a[j]):
				ok = False
	if ok:
		break
if ok:
	print('YES')
else:
	print('NO')


import sys
import math
strs = [int(x) for x in input().strip().split()]
aa = []
bb = []
cc = []
dd = []
ra = [1, 3, 5, 7, 9, 11, 22, 24]
rb = [2, 4, 6, 8, 10, 12, 21, 23]
rc = [13, 14, 5, 6, 17, 18, 21, 22]
rd = [15, 16, 7, 8, 19, 20, 23, 24]
for i in range(len(ra)):
	aa.append(strs[ra[i] - 1])
	bb.append(strs[rb[i] - 1])
	cc.append(strs[rc[i] - 1])
	dd.append(strs[rd[i] - 1])
cont = 0
for i in range(1, 24, 4):
	if strs[i - 1] == strs[i] == strs[i + 1] == strs[i + 2]:
		cont += 1
pr = []
kl = []
flag = False
stop = 0
if aa == bb and cc == dd:
	flag = True
elif aa == bb or cc == dd:
	if aa != bb:
		pr = aa
		kl = bb
	elif cc != dd:
		pr = cc
		kl = dd
	for i in range(len(ra) - 2):
		if pr[i] == kl[i + 2] or kl[i] == pr[i + 2]:
			if pr.count(1) == kl.count(1) and pr.count(2) == kl.count(2) and (pr.count(3) == kl.count(3)) and (pr.count(4) == kl.count(4)) and (pr.count(5) == kl.count(5)) and (pr.count(6) == kl.count(6)):
				flag = True
			else:
				stop = 1
		else:
			stop = 1
		if stop == 1:
			flag = False
			break
if cont == 6:
	flag = False
if flag == True:
	print('YES')
else:
	print('NO')


colors = input().strip().split()
rotates = [[3, 1, 4, 2, 17, 18, 7, 8, 9, 10, 11, 12, 5, 6, 15, 16, 21, 22, 19, 20, 13, 14, 23, 24], [5, 2, 7, 4, 9, 6, 11, 8, 24, 10, 22, 12, 14, 16, 13, 15, 17, 18, 19, 20, 21, 3, 23, 1], [1, 2, 17, 19, 6, 8, 5, 7, 14, 16, 11, 12, 13, 4, 15, 3, 10, 18, 9, 20, 21, 22, 23, 24]]

def is_assembled(cube):
	for edge in range(6):
		color = cube[edge * 4]
		for i in range(1, 4):
			if cube[edge * 4 + i] != color:
				return False
	return True

def rotate(cube, rotation):
	new_cube = []
	for i in range(len(cube)):
		new_cube.append(cube[rotation[i] - 1])
	return new_cube

def reverse_rotate(rotatation):
	res = 24 * [None]
	for (FROM, TO) in enumerate(rotatation, start=1):
		res[TO - 1] = FROM
	return res
is_assemblible = False
for rot in rotates:
	if is_assembled(rotate(colors, rot)) or is_assembled(rotate(colors, reverse_rotate(rot))):
		is_assemblible = True
		break
if is_assemblible:
	print('YES')
else:
	print('NO')


x = input().split()
if x[0] == x[2] == x[5] == x[7] and x[1] == x[3] == x[21] == x[23] and (x[4] == x[6] == x[9] == x[11]) and (x[8] == x[10] == x[20] == x[22]) and (x[12] == x[13] == x[14] == x[15]) and (x[16] == x[17] == x[18] == x[19]):
	print('YES')
elif x[0] == x[2] == x[20] == x[22] and x[1] == x[3] == x[4] == x[6] and (x[5] == x[7] == x[8] == x[10]) and (x[9] == x[11] == x[21] == x[23]) and (x[12] == x[13] == x[14] == x[15]) and (x[16] == x[17] == x[18] == x[19]):
	print('YES')
elif x[0] == x[1] == x[13] == x[15] and x[2] == x[3] == x[17] == x[19] and (x[12] == x[14] == x[8] == x[9]) and (x[10] == x[11] == x[16] == x[18]) and (x[4] == x[5] == x[6] == x[7]) and (x[20] == x[21] == x[22] == x[23]):
	print('YES')
elif x[0] == x[1] == x[16] == x[18] and x[8] == x[9] == x[17] == x[19] and (x[12] == x[14] == x[2] == x[3]) and (x[10] == x[11] == x[13] == x[15]) and (x[4] == x[5] == x[6] == x[7]) and (x[20] == x[21] == x[22] == x[23]):
	print('YES')
elif x[12] == x[13] == x[6] == x[7] and x[4] == x[5] == x[18] == x[19] and (x[16] == x[17] == x[22] == x[23]) and (x[20] == x[21] == x[14] == x[15]) and (x[0] == x[1] == x[2] == x[3]) and (x[8] == x[9] == x[10] == x[11]):
	print('YES')
elif x[14] == x[15] == x[4] == x[5] and x[6] == x[7] == x[16] == x[17] and (x[18] == x[19] == x[20] == x[21]) and (x[22] == x[23] == x[12] == x[13]) and (x[0] == x[1] == x[2] == x[3]) and (x[8] == x[9] == x[10] == x[11]):
	print('YES')
else:
	print('NO')


l = [0] + [int(i) for i in input().split(' ')]
if l[13] == l[14] == l[15] == l[16] and l[17] == l[18] == l[19] == l[20]:
	if l[5] == l[7] == l[10] == l[12] and l[9] == l[11] == l[21] == l[23] and (l[1] == l[3] == l[6] == l[8]) and (l[2] == l[4] == l[22] == l[24]):
		print('YES')
		exit(0)
	if l[5] == l[7] == l[2] == l[4] and l[9] == l[11] == l[6] == l[8] and (l[1] == l[3] == l[21] == l[23]) and (l[10] == l[12] == l[22] == l[24]):
		print('YES')
		exit(0)
if l[1] == l[2] == l[3] == l[4] and l[9] == l[10] == l[11] == l[12]:
	if l[5] == l[6] == l[19] == l[20] and l[17] == l[18] == l[23] == l[24] and (l[21] == l[22] == l[15] == l[16]) and (l[13] == l[14] == l[7] == l[8]):
		print('YES')
		exit(0)
	if l[5] == l[6] == l[15] == l[16] and l[13] == l[14] == l[23] == l[24] and (l[21] == l[22] == l[19] == l[20]) and (l[17] == l[18] == l[7] == l[8]):
		print('YES')
		exit(0)
if l[5] == l[6] == l[7] == l[8] and l[21] == l[22] == l[23] == l[24]:
	if l[3] == l[4] == l[18] == l[20] and l[17] == l[19] == l[11] == l[12] and (l[9] == l[10] == l[13] == l[15]) and (l[14] == l[16] == l[1] == l[2]):
		print('YES')
		exit(0)
	if l[3] == l[4] == l[13] == l[15] and l[14] == l[16] == l[11] == l[12] and (l[9] == l[10] == l[18] == l[20]) and (l[17] == l[19] == l[1] == l[2]):
		print('YES')
		exit(0)
print('NO')


ll = [int(x) for x in input().split()]
l = ll[:]

def ok(l):
	for i in range(6):
		for j in range(4):
			if l[i * 4 + j] != l[i * 4]:
				return
	print('YES')
	exit(0)
a = l[2]
l[2] = l[16]
l[16] = l[9]
l[9] = l[15]
l[15] = a
a = l[3]
l[3] = l[18]
l[18] = l[8]
l[8] = l[13]
l[13] = a
ok(l)
for i in range(2):
	a = l[2]
	l[2] = l[16]
	l[16] = l[9]
	l[9] = l[15]
	l[15] = a
	a = l[3]
	l[3] = l[18]
	l[18] = l[8]
	l[8] = l[13]
	l[13] = a
ok(l)
l = ll[:]
a = l[12]
l[12] = l[11]
l[11] = l[16]
l[16] = l[4]
l[4] = a
a = l[13]
l[13] = l[10]
l[10] = l[17]
l[17] = l[5]
l[5] = a
ok(l)
for i in range(2):
	a = l[12]
	l[12] = l[11]
	l[11] = l[16]
	l[16] = l[4]
	l[4] = a
	a = l[13]
	l[13] = l[10]
	l[10] = l[17]
	l[17] = l[5]
	l[5] = a
ok(l)
l = ll[:]
a = l[6]
l[6] = l[18]
l[18] = l[22]
l[22] = l[14]
l[14] = a
a = l[7]
l[7] = l[19]
l[19] = l[23]
l[23] = l[15]
l[15] = a
ok(l)
for i in range(2):
	a = l[6]
	l[6] = l[18]
	l[18] = l[22]
	l[22] = l[14]
	l[14] = a
	a = l[7]
	l[7] = l[19]
	l[19] = l[23]
	l[23] = l[15]
	l[15] = a
ok(l)
l = ll[:]
a = l[0]
l[0] = l[4]
l[4] = l[8]
l[8] = l[23]
l[23] = a
a = l[2]
l[2] = l[6]
l[6] = l[10]
l[10] = l[21]
l[21] = a
ok(l)
for i in range(2):
	a = l[0]
	l[0] = l[4]
	l[4] = l[8]
	l[8] = l[23]
	l[23] = a
	a = l[2]
	l[2] = l[6]
	l[6] = l[10]
	l[10] = l[21]
	l[21] = a
ok(l)
print('NO')


a = list(map(int, input().split()))
ans = 'NO'
pairs = [[1, 9], [5, 21], [13, 17]]
cells = {1: [5, 6, 17, 18, 21, 22, 13, 14], 9: [7, 8, 19, 20, 23, 24, 15, 16], 5: [9, 10, 19, 17, 4, 3, 14, 16], 21: [11, 12, 20, 18, 2, 1, 13, 15], 13: [7, 5, 3, 1, 22, 24, 11, 9], 17: [8, 6, 4, 2, 21, 23, 12, 10]}
for (i, j) in pairs:
	if 1 < len(set(a[i - 1:i + 3])) or 1 < len(set(a[j - 1:j + 3])):
		continue
	ci = cells[i]
	cj = cells[j]
	for d in [2, 6]:
		f = True
		for k in range(0, 8, 2):
			if a[ci[k] - 1] != a[ci[(k + 1) % 8] - 1]:
				f = False
			if a[cj[k] - 1] != a[cj[(k + 1) % 8] - 1]:
				f = False
			if a[ci[k] - 1] != a[cj[(k + d) % 8] - 1]:
				f = False
		if f:
			ans = 'YES'
print(ans)


def final(b):
	for i in range(6):
		if len(set(b[4 * i:4 * i + 4])) != 1:
			return False
	return True
a = list(map(int, input().split()))
moves = [[4, 5, 16, 17, 20, 21, 12, 13], [13, 15, 8, 9, 18, 16, 3, 2], [15, 14, 23, 22, 19, 18, 7, 6], [21, 23, 10, 8, 6, 4, 2, 0], [5, 7, 9, 11, 22, 20, 1, 3], [17, 19, 11, 10, 14, 12, 0, 1]]
for (index, m) in enumerate(moves):
	permutation = [i for i in range(24)]
	inverse = [i for i in range(24)]
	for j in range(8):
		first = m[j]
		second = m[(j + 2) % 8]
		permutation[first] = second
		inverse[second] = first
	b = [a[permutation[i]] for i in range(24)]
	c = [a[inverse[i]] for i in range(24)]
	if final(b) or final(c):
		print('YES')
		exit()
print('NO')


cube_state = list(map(int, input().split()))

def is_solved(cube_state):
	previous = None
	for i in range(24):
		if i % 4 == 0:
			previous = cube_state[i]
		elif cube_state[i] != previous:
			return False
	return True

def transfer(array, src, dest):
	copied = array[:]
	for index in range(len(src)):
		copied[dest[index] - 1] = array[src[index] - 1]
	return copied

def try_solution_and_inverse(cube_state, src, dest):
	if is_solved(transfer(cube_state, src, dest)):
		return True
	if is_solved(transfer(cube_state, dest, src)):
		return True
	return False

def can_solve(cube_state):
	if try_solution_and_inverse(cube_state, [1, 2, 3, 4, 5, 6, 17, 18, 21, 22, 13, 14], [2, 4, 1, 3, 13, 14, 5, 6, 17, 18, 21, 22]):
		return True
	if try_solution_and_inverse(cube_state, [11, 12, 10, 9, 7, 8, 19, 20, 23, 24, 15, 16], [12, 10, 9, 11, 15, 16, 7, 8, 19, 20, 23, 24]):
		return True
	for _ in range(4):
		if try_solution_and_inverse(cube_state, [5, 6, 8, 7, 3, 4, 17, 19, 10, 9, 16, 14], [6, 8, 7, 5, 17, 19, 10, 9, 16, 14, 3, 4]):
			return True
		cube_state = transfer(cube_state, [3, 1, 4, 2, 17, 18, 19, 20, 10, 12, 9, 11, 5, 6, 7, 8, 21, 22, 23, 24, 13, 14, 15, 16], list(range(1, 24 + 1)))
	return False
if can_solve(cube_state):
	print('YES')
else:
	print('NO')


from itertools import groupby

def isSolved(c):
	cons = [x[0] for x in groupby(c)]
	return len(cons) == 6
color = list(map(int, input().strip().split()))
faces = [[2, 4, 6, 8, 10, 12, 23, 21], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [1, 3, 5, 7, 9, 11, 24, 22], [9, 10, 19, 17, 4, 3, 14, 16], [1, 2, 18, 20, 12, 11, 15, 13]]

def rotate(g, face):
	c = g[:]
	temp1 = c[face[0] - 1]
	temp2 = c[face[1] - 1]
	for i in range(0, 6, 2):
		c[face[i] - 1] = c[face[i + 2] - 1]
		c[face[i + 1] - 1] = c[face[i + 3] - 1]
	c[face[-2] - 1] = temp1
	c[face[-1] - 1] = temp2
	return c

def canSolve(c):
	for i in faces:
		rot = rotate(c, i)
		if isSolved(rot):
			return True
		x = list(reversed(i))
		rot2 = rotate(c, x)
		if isSolved(rot2):
			return True
	return False
if canSolve(color):
	print('YES')
else:
	print('NO')


from sys import stdin
ocube = [int(x) for x in stdin.readline().strip().split()]
ocube.insert(0, 0)

def UL(array):
	cube = []
	for i in range(len(array)):
		cube.append(array[i])
	cube[5:7] = array[17:19]
	cube[17:19] = array[21:23]
	cube[21:23] = array[13:15]
	cube[13:15] = array[5:7]
	return cube

def UR(array):
	cube = []
	for i in range(len(array)):
		cube.append(array[i])
	cube[5:7] = array[13:15]
	cube[17:19] = array[5:7]
	cube[21:23] = array[17:19]
	cube[13:15] = array[21:23]
	return cube

def RU(array):
	cube = []
	for i in range(len(array)):
		cube.append(array[i])
	cube[6] = array[10]
	cube[8] = array[12]
	cube[23] = array[2]
	cube[21] = array[4]
	cube[10] = array[23]
	cube[12] = array[21]
	cube[2] = array[6]
	cube[4] = array[8]
	return cube

def RD(array):
	cube = []
	for i in range(len(array)):
		cube.append(array[i])
	cube[6] = array[2]
	cube[8] = array[4]
	cube[23] = array[10]
	cube[21] = array[12]
	cube[10] = array[6]
	cube[12] = array[8]
	cube[2] = array[23]
	cube[4] = array[21]
	return cube

def FL(array):
	cube = []
	for i in range(len(array)):
		cube.append(array[i])
	cube[3] = array[17]
	cube[4] = array[19]
	cube[17] = array[10]
	cube[19] = array[9]
	cube[9] = array[14]
	cube[10] = array[16]
	cube[14] = array[4]
	cube[16] = array[3]
	return cube

def FR(array):
	cube = []
	for i in range(len(array)):
		cube.append(array[i])
	cube[3] = array[16]
	cube[4] = array[14]
	cube[17] = array[3]
	cube[19] = array[4]
	cube[9] = array[19]
	cube[10] = array[17]
	cube[14] = array[9]
	cube[16] = array[10]
	return cube

def check(array):
	i = 1
	control = True
	while i <= 24:
		if array[i] == array[i + 1] and array[i + 1] == array[i + 2] and (array[i + 2] == array[i + 3]):
			i += 4
			control = control and True
		else:
			i += 4
			control = control and False
	return control
if check(UL(ocube)) or check(UR(ocube)) or check(RU(ocube)) or check(RD(ocube)) or check(FL(ocube)) or check(FR(ocube)):
	print('YES')
else:
	print('NO')


line = list(map(int, input().split()))
yes = False
q = [1, -1]
if line[4] == line[5] and line[5] == line[6] and (line[6] == line[7]):
	if line[20] == line[21] and line[21] == line[22] and (line[22] == line[23]):
		can = True
		c1 = []
		if line[15] != line[13]:
			can = False
		else:
			c1 += [line[15]]
		if line[3] != line[2]:
			can = False
		else:
			c1 += [line[3]]
		if line[16] != line[18]:
			can = False
		else:
			c1 += [line[16]]
		if line[8] != line[9]:
			can = False
		else:
			c1 += [line[8]]
		c2 = []
		if line[12] != line[14]:
			can = False
		else:
			c2 += [line[14]]
		if line[0] != line[1]:
			can = False
		else:
			c2 += [line[1]]
		if line[17] != line[19]:
			can = False
		else:
			c2 += [line[19]]
		if line[10] != line[11]:
			can = False
		else:
			c2 += [line[11]]
		if can:
			for i in range(2):
				c3 = []
				for j in range(4):
					c3 += [c1[(q[i] + j) % 4]]
				if c3 == c2:
					yes = True
if line[0] == line[1] and line[1] == line[2] and (line[2] == line[3]):
	if line[8] == line[9] and line[9] == line[10] and (line[10] == line[11]):
		can = True
		c1 = []
		if line[12] != line[13]:
			can = False
		else:
			c1 += [line[12]]
		if line[4] != line[5]:
			can = False
		else:
			c1 += [line[4]]
		if line[16] != line[17]:
			can = False
		else:
			c1 += [line[16]]
		if line[20] != line[21]:
			can = False
		else:
			c1 += [line[21]]
		c2 = []
		if line[14] != line[15]:
			can = False
		else:
			c2 += [line[14]]
		if line[6] != line[7]:
			can = False
		else:
			c2 += [line[7]]
		if line[18] != line[19]:
			can = False
		else:
			c2 += [line[19]]
		if line[22] != line[23]:
			can = False
		else:
			c2 += [line[23]]
		if can:
			for i in range(2):
				c3 = []
				for j in range(4):
					c3 += [c1[(q[i] + j) % 4]]
				if c3 == c2:
					yes = True
if line[12] == line[13] and line[13] == line[14] and (line[14] == line[15]):
	if line[16] == line[17] and line[17] == line[18] and (line[18] == line[19]):
		can = True
		c1 = []
		if line[0] != line[2]:
			can = False
		else:
			c1 += [line[2]]
		if line[4] != line[6]:
			can = False
		else:
			c1 += [line[4]]
		if line[8] != line[10]:
			can = False
		else:
			c1 += [line[10]]
		if line[23] != line[21]:
			can = False
		else:
			c1 += [line[21]]
		c2 = []
		if line[1] != line[3]:
			can = False
		else:
			c2 += [line[1]]
		if line[5] != line[7]:
			can = False
		else:
			c2 += [line[7]]
		if line[11] != line[9]:
			can = False
		else:
			c2 += [line[9]]
		if line[22] != line[20]:
			can = False
		else:
			c2 += [line[20]]
		if can:
			for i in range(2):
				c3 = []
				for j in range(4):
					c3 += [c1[(q[i] + j) % 4]]
				if c3 == c2:
					yes = True
if yes:
	print('YES')
else:
	print('NO')


S = 24

class Permutation:

	def __init__(self, C=None):
		if isinstance(C, list):
			assert len(C) == S
			self.P = C
		else:
			self.P = list(range(S))
			if isinstance(C, tuple):
				for i in range(len(C)):
					self.P[C[i]] = C[(i + 1) % len(C)]
		self.P = tuple(self.P)

	def __getitem__(self, i):
		return self.P[i]

	def __mul__(self, A):
		res = [0] * S
		for i in range(S):
			res[i] = self[A[i]]
		return Permutation(res)

	def __hash__(self):
		return hash(self.P)

	def __eq__(self, A):
		return self.P == A.P

	def decomp(self):
		D = []
		seen = [False] * S
		for i0 in range(S):
			if not seen[i0]:
				seen[i0] = True
				C = [i0]
				i = self[i0]
				while i != i0:
					seen[i] = True
					C.append(i)
					i = self[i]
				D.append(C)
		return D
Gen = []
Gen.append(Permutation((0, 1, 2, 3)) * Permutation((4, 9, 14, 19)) * Permutation((7, 8, 13, 18)))
Gen.append(Permutation((4, 5, 6, 7)) * Permutation((1, 17, 21, 9)) * Permutation((2, 18, 22, 10)))
Gen.append(Permutation((8, 9, 10, 11)) * Permutation((15, 3, 7, 21)) * Permutation((14, 2, 6, 20)))
Gen.append(Permutation((12, 13, 14, 15)) * Permutation((20, 16, 0, 8)) * Permutation((23, 19, 3, 11)))
Gen.append(Permutation((16, 17, 18, 19)) * Permutation((13, 23, 5, 1)) * Permutation((12, 22, 4, 0)))
Gen.append(Permutation((20, 21, 22, 23)) * Permutation((12, 11, 6, 17)) * Permutation((15, 10, 5, 16)))

def solved(C, P):
	for i in range(0, 24, 4):
		if any((C[P[i + k]] != C[P[i]] for k in range(1, 4))):
			return False
	return True

def main():
	C = list(map(int, input().split()))
	R = Permutation([5, 7, 6, 4, 9, 11, 10, 8, 13, 15, 14, 12, 1, 3, 2, 0, 17, 19, 18, 16, 21, 23, 22, 20])
	for i in range(len(Gen)):
		Gen.append(Gen[i] * Gen[i] * Gen[i])
	print('YES' if any((solved(C, R * g) for g in Gen)) else 'NO')
main()


cube = [[13, 14, 5, 6, 17, 18, 21, 22], [14, 16, 9, 10, 19, 17, 4, 3], [1, 3, 5, 7, 9, 11, 24, 22]]

def rotate(seq, i):
	lst = []
	s = seq[:]
	for x in range(8):
		lst.append(s[cube[i][x] - 1])
	for j in range(3):
		lst = lst[2:] + lst[:2]
		for x in range(8):
			s[cube[i][x] - 1] = lst[x]
		if check(s) and j % 2 == 0:
			return True
	return False

def check(seq):
	for j in range(6):
		if len(set(seq[j * 4:j * 4 + 4])) != 1:
			return False
	return True
seq = list(map(int, input().split()))
for k in range(len(cube)):
	if rotate(seq, k):
		print('yes')
		break
else:
	print('no')


def ok(v):
	for i in range(0, 24, 4):
		if len(set(v[i:i + 4])) > 1:
			return False
	return True
a = list(map(int, input().split()))
v = a[:]
v[2] = a[15]
v[3] = a[13]
v[16] = a[2]
v[18] = a[3]
v[8] = a[18]
v[9] = a[16]
v[13] = a[8]
v[15] = a[9]
if ok(v):
	print('YES')
	return
v = a[:]
v[2] = a[16]
v[3] = a[18]
v[16] = a[9]
v[18] = a[8]
v[8] = a[13]
v[9] = a[15]
v[13] = a[3]
v[15] = a[2]
if ok(v):
	print('YES')
	return
v = a[:]
v[5] = a[13]
v[4] = a[12]
v[17] = a[5]
v[16] = a[4]
v[21] = a[17]
v[20] = a[16]
v[13] = a[21]
v[12] = a[20]
if ok(v):
	print('YES')
	return
v = a[:]
v[5] = a[17]
v[4] = a[16]
v[17] = a[21]
v[16] = a[20]
v[21] = a[13]
v[20] = a[12]
v[13] = a[5]
v[12] = a[4]
if ok(v):
	print('YES')
	return
v = a[:]
v[0] = a[4]
v[2] = a[6]
v[4] = a[8]
v[6] = a[10]
v[8] = a[23]
v[10] = a[21]
v[23] = a[0]
v[21] = a[2]
if ok(v):
	print('YES')
	return
v = a[:]
v[0] = a[23]
v[2] = a[21]
v[4] = a[0]
v[6] = a[2]
v[8] = a[4]
v[10] = a[6]
v[23] = a[8]
v[21] = a[10]
if ok(v):
	print('YES')
	return
print('NO')


def eq(cube, a, b, c, d):
	return cube[a] == cube[b] and cube[b] == cube[c] and (cube[c] == cube[d])
opp = [2, 5, 0, 4, 3, 1]
cube = input().strip().split()
for i in range(6):
	if cube[4 * i + 0] == cube[4 * i + 1] and cube[4 * i + 2] == cube[4 * i + 1] and (cube[4 * i + 2] == cube[4 * i + 3]):
		if cube[4 * opp[i] + 0] == cube[4 * opp[i] + 1] and cube[4 * opp[i] + 2] == cube[4 * opp[i] + 1] and (cube[4 * opp[i] + 2] == cube[4 * opp[i] + 3]):
			if i == 0 or i == opp[0]:
				if cube[4] == cube[5] and cube[4] == cube[18] and (cube[18] == cube[19]):
					if cube[16] == cube[17] and cube[17] == cube[22] and (cube[22] == cube[23]):
						if cube[20] == cube[21] and cube[21] == cube[14] and (cube[14] == cube[15]):
							print('YES')
							exit()
				if cube[4] == cube[5] and cube[4] == cube[15] and (cube[14] == cube[15]):
					if cube[12] == cube[13] and cube[12] == cube[23] and (cube[22] == cube[23]):
						if cube[20] == cube[21] and cube[18] == cube[19] and (cube[20] == cube[18]):
							print('YES')
							exit()
			if i == 1 or i == opp[1]:
				if eq(cube, 2, 3, 12, 14):
					if eq(cube, 13, 15, 10, 11):
						if eq(cube, 8, 9, 19, 17):
							print('YES')
							exit()
				if eq(cube, 2, 3, 17, 19) and eq(cube, 16, 18, 10, 11) and eq(cube, 8, 9, 12, 14):
					print('YES')
					exit()
			if i == 3 or i == opp[3]:
				if eq(cube, 4, 6, 1, 3) and eq(cube, 0, 2, 20, 22) and eq(cube, 21, 23, 9, 11):
					print('YES')
					exit()
				if eq(cube, 4, 6, 9, 11) and eq(cube, 8, 10, 20, 22) and eq(cube, 21, 23, 1, 3):
					print('YES')
					exit()
print('NO')


def all_is(l):
	f = l[1]
	for i in range(2, len(l)):
		if l[i] == f or l[i] == None:
			pass
		else:
			return False
	return True
lst = list(map(int, input().split(' ')))
(u, f, d, l, r, t) = (lst[:4], lst[4:8], lst[8:12], lst[12:16], lst[16:20], lst[20:])
u.insert(0, None)
f.insert(0, None)
d.insert(0, None)
l.insert(0, None)
r.insert(0, None)
t.insert(0, None)
if all_is(u) and (not all_is(f)) and all_is(d) and (not all_is(l)) and (not all_is(r)) and (not all_is(t)):
	if l[1] == l[2] == f[3] == f[4] and f[1] == f[2] == r[3] == r[4] and (r[1] == r[2] == t[3] == t[4]) and (t[1] == t[2] == l[3] == l[4]) or (l[3] == l[4] == f[1] == f[2] and f[3] == f[4] == r[1] == r[2] and (r[3] == r[4] == t[1] == t[2]) and (t[3] == t[4] == l[1] == l[2])):
		print('YES')
	else:
		print('NO')
elif not all_is(u) and all_is(f) and (not all_is(d)) and (not all_is(l)) and (not all_is(r)) and all_is(t):
	if l[1] == l[3] == u[3] == u[4] and u[1] == u[2] == r[1] == r[3] and (r[2] == r[4] == d[1] == d[2]) and (d[3] == d[4] == l[2] == l[4]) or (l[2] == l[4] == u[1] == u[2] and u[3] == u[4] == r[2] == r[4] and (r[1] == r[3] == d[3] == d[4]) and (d[1] == d[2] == l[1] == l[3])):
		print('YES')
	else:
		print('NO')
elif not all_is(u) and (not all_is(f)) and (not all_is(d)) and all_is(l) and all_is(r) and (not all_is(t)):
	if f[1] == f[3] == u[2] == u[4] and u[1] == u[3] == t[1] == t[3] and (t[2] == t[4] == d[2] == d[4]) and (d[1] == d[3] == f[2] == f[4]) or (f[2] == f[4] == u[1] == u[3] and u[2] == u[4] == t[2] == t[4] and (t[1] == t[3] == d[1] == d[3]) and (d[2] == d[4] == f[1] == f[3])):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


l = list(map(int, input().split()))
l.insert(0, 0)
l1 = [13, 14, 15, 16]
l2 = [17, 18, 19, 20]
l3 = [1, 3, 6, 8]
l4 = [2, 4, 22, 24]
l5 = [5, 7, 10, 12]
l6 = [9, 11, 21, 23]
check = 0
if l[l1[0]] == l[l1[1]] == l[l1[2]] == l[l1[3]]:
	if l[l2[0]] == l[l2[1]] == l[l2[2]] == l[l2[3]]:
		if l[l3[0]] == l[l3[1]] == l[l3[2]] == l[l3[3]]:
			if l[l4[0]] == l[l4[1]] == l[l4[2]] == l[l4[3]]:
				if l[l5[0]] == l[l5[1]] == l[l5[2]] == l[l5[3]]:
					if l[l6[0]] == l[l6[1]] == l[l6[2]] == l[l6[3]]:
						check = 1
if check:
	(print('YES'), exit(0))
l1 = [13, 14, 15, 16]
l2 = [17, 18, 19, 20]
l3 = [1, 3, 21, 23]
l4 = [5, 7, 2, 4]
l5 = [9, 11, 6, 8]
l6 = [10, 12, 22, 24]
check = 0
if l[l1[0]] == l[l1[1]] == l[l1[2]] == l[l1[3]]:
	if l[l2[0]] == l[l2[1]] == l[l2[2]] == l[l2[3]]:
		if l[l3[0]] == l[l3[1]] == l[l3[2]] == l[l3[3]]:
			if l[l4[0]] == l[l4[1]] == l[l4[2]] == l[l4[3]]:
				if l[l5[0]] == l[l5[1]] == l[l5[2]] == l[l5[3]]:
					if l[l6[0]] == l[l6[1]] == l[l6[2]] == l[l6[3]]:
						check = 1
if check:
	(print('YES'), exit(0))
l1 = [1, 2, 3, 4]
l2 = [9, 10, 11, 12]
l3 = [5, 6, 19, 20]
l4 = [7, 8, 13, 14]
l5 = [15, 16, 21, 22]
l6 = [17, 18, 23, 24]
if l[l1[0]] == l[l1[1]] == l[l1[2]] == l[l1[3]]:
	if l[l2[0]] == l[l2[1]] == l[l2[2]] == l[l2[3]]:
		if l[l3[0]] == l[l3[1]] == l[l3[2]] == l[l3[3]]:
			if l[l4[0]] == l[l4[1]] == l[l4[2]] == l[l4[3]]:
				if l[l5[0]] == l[l5[1]] == l[l5[2]] == l[l5[3]]:
					if l[l6[0]] == l[l6[1]] == l[l6[2]] == l[l6[3]]:
						check = 1
if check:
	(print('YES'), exit(0))
l1 = [1, 2, 3, 4]
l2 = [9, 10, 11, 12]
l3 = [5, 6, 15, 16]
l4 = [23, 24, 13, 14]
l5 = [19, 20, 21, 22]
l6 = [7, 8, 17, 18]
if l[l1[0]] == l[l1[1]] == l[l1[2]] == l[l1[3]]:
	if l[l2[0]] == l[l2[1]] == l[l2[2]] == l[l2[3]]:
		if l[l3[0]] == l[l3[1]] == l[l3[2]] == l[l3[3]]:
			if l[l4[0]] == l[l4[1]] == l[l4[2]] == l[l4[3]]:
				if l[l5[0]] == l[l5[1]] == l[l5[2]] == l[l5[3]]:
					if l[l6[0]] == l[l6[1]] == l[l6[2]] == l[l6[3]]:
						check = 1
if check:
	(print('YES'), exit(0))
l1 = [5, 6, 7, 8]
l2 = [21, 22, 23, 24]
l3 = [1, 2, 17, 19]
l4 = [3, 4, 13, 15]
l5 = [9, 10, 18, 20]
l6 = [11, 12, 14, 16]
if l[l1[0]] == l[l1[1]] == l[l1[2]] == l[l1[3]]:
	if l[l2[0]] == l[l2[1]] == l[l2[2]] == l[l2[3]]:
		if l[l3[0]] == l[l3[1]] == l[l3[2]] == l[l3[3]]:
			if l[l4[0]] == l[l4[1]] == l[l4[2]] == l[l4[3]]:
				if l[l5[0]] == l[l5[1]] == l[l5[2]] == l[l5[3]]:
					if l[l6[0]] == l[l6[1]] == l[l6[2]] == l[l6[3]]:
						check = 1
if check:
	(print('YES'), exit(0))
l1 = [5, 6, 7, 8]
l2 = [21, 22, 23, 24]
l3 = [3, 4, 18, 20]
l4 = [17, 19, 11, 12]
l5 = [9, 10, 15, 13]
l6 = [14, 16, 1, 2]
if l[l1[0]] == l[l1[1]] == l[l1[2]] == l[l1[3]]:
	if l[l2[0]] == l[l2[1]] == l[l2[2]] == l[l2[3]]:
		if l[l3[0]] == l[l3[1]] == l[l3[2]] == l[l3[3]]:
			if l[l4[0]] == l[l4[1]] == l[l4[2]] == l[l4[3]]:
				if l[l5[0]] == l[l5[1]] == l[l5[2]] == l[l5[3]]:
					if l[l6[0]] == l[l6[1]] == l[l6[2]] == l[l6[3]]:
						check = 1
if check:
	(print('YES'), exit(0))
print('NO')


def solvable(la):
	colors_faces = [set() for _ in range(6)]
	for (i, a) in zip(list(range(50)), la):
		face = i // 4
		colors_faces[face].add(a)
		if len(colors_faces[face]) > 2:
			return False
	ones = []
	twos = []
	for (i, face_set) in enumerate(colors_faces):
		if len(face_set) == 1:
			ones.append(i)
		else:
			twos.append(i)
	twos.sort()
	possibilities = [[0, 1, 2, 5], [0, 2, 3, 4], [1, 3, 4, 5]]
	if twos not in possibilities:
		return False
	yep = False
	if twos == [0, 1, 2, 5]:
		yep = la[0] == la[2] and la[2] == la[5] and (la[5] == la[7]) and (la[1] == la[3]) and (la[3] == la[21]) and (la[21] == la[23]) and (la[4] == la[6]) and (la[6] == la[9]) and (la[9] == la[11]) and (la[8] == la[10]) and (la[10] == la[20]) and (la[20] == la[22]) or (la[0] == la[2] and la[2] == la[20] and (la[20] == la[22]) and (la[1] == la[3]) and (la[3] == la[4]) and (la[4] == la[6]) and (la[5] == la[7]) and (la[7] == la[8]) and (la[8] == la[10]) and (la[9] == la[11]) and (la[11] == la[21]) and (la[21] == la[23]))
	elif twos == [0, 2, 3, 4]:
		yep = la[0] == la[1] and la[1] == la[16] and (la[16] == la[18]) and (la[17] == la[19]) and (la[19] == la[9]) and (la[9] == la[8]) and (la[10] == la[11]) and (la[11] == la[15]) and (la[15] == la[13]) and (la[2] == la[3]) and (la[3] == la[12]) and (la[12] == la[14]) or (la[0] == la[1] and la[1] == la[13] and (la[13] == la[15]) and (la[2] == la[3]) and (la[3] == la[17]) and (la[17] == la[19]) and (la[12] == la[14]) and (la[14] == la[8]) and (la[8] == la[9]) and (la[10] == la[11]) and (la[11] == la[16]) and (la[16] == la[18]))
	elif twos == [1, 3, 4, 5]:
		yep = la[12] == la[13] and la[13] == la[6] and (la[6] == la[7]) and (la[4] == la[5]) and (la[5] == la[18]) and (la[18] == la[19]) and (la[16] == la[17]) and (la[17] == la[22]) and (la[22] == la[23]) and (la[20] == la[21]) and (la[21] == la[14]) and (la[14] == la[15]) or (la[14] == la[15] and la[4] == la[5] and (la[14] == la[4]) and (la[6] == la[7]) and (la[6] == la[16]) and (la[16] == la[17]) and (la[18] == la[19]) and (la[19] == la[20]) and (la[20] == la[21]) and (la[12] == la[13]) and (la[13] == la[22]) and (la[22] == la[23]))
	return yep
la = list(map(int, input().split()))
print('YES' if solvable(la) else 'NO')


a = input().split()
c1 = a[0] == a[1] == a[2] == a[3]
c2 = a[8] == a[9] == a[10] == a[11]
c3 = a[12] == a[13] == a[6] == a[7]
c4 = a[4] == a[5] == a[18] == a[19]
c5 = a[16] == a[17] == a[22] == a[23]
c6 = a[20] == a[21] == a[14] == a[15]
c1 = c1
c2 = c2
c7 = a[4] == a[5] == a[14] == a[15]
c8 = a[12] == a[13] == a[22] == a[23]
c9 = a[20] == a[21] == a[18] == a[19]
c10 = a[16] == a[17] == a[6] == a[7]
c11 = a[4] == a[5] == a[6] == a[7]
c12 = a[20] == a[21] == a[22] == a[23]
c13 = a[8] == a[9] == a[17] == a[19]
c14 = a[16] == a[18] == a[0] == a[1]
c15 = a[2] == a[3] == a[12] == a[14]
c16 = a[13] == a[15] == a[10] == a[11]
c11 = c11
c12 = c12
c17 = a[8] == a[9] == a[12] == a[14]
c18 = a[13] == a[15] == a[0] == a[1]
c19 = a[2] == a[3] == a[17] == a[19]
c20 = a[16] == a[18] == a[10] == a[11]
c21 = a[12] == a[13] == a[14] == a[15]
c22 = a[16] == a[17] == a[18] == a[19]
c23 = a[8] == a[10] == a[5] == a[7]
c24 = a[4] == a[6] == a[1] == a[3]
c25 = a[0] == a[2] == a[20] == a[22]
c26 = a[21] == a[23] == a[9] == a[11]
c21 = c21
c22 = c22
c27 = a[8] == a[10] == a[20] == a[22]
c28 = a[21] == a[23] == a[1] == a[3]
c29 = a[0] == a[2] == a[5] == a[7]
c30 = a[4] == a[6] == a[9] == a[11]
case1 = c1 and c2 and c3 and c4 and c5 and c6
case2 = c1 and c2 and c7 and c8 and c9 and c10
case3 = c11 and c12 and c13 and c14 and c15 and c16
case4 = c11 and c12 and c17 and c18 and c19 and c20
case5 = c21 and c22 and c23 and c24 and c25 and c26
case6 = c21 and c22 and c27 and c28 and c29 and c30
if case1 or case2 or case3 or case4 or case5 or case6:
	print('YES')
else:
	print('NO')


d = list(map(int, input().split()))
d = [0] + d

def ff(g):
	if g[1] == g[2] == g[3] == g[0]:
		return True
	return False

def df(g):
	return [g[1], g[3], g[0], g[2]]
if ff(d[13:17]) & ff(d[17:21]):
	a = d[:]
	b = True
	for i in range(1, 25, 4):
		if a[i] != a[i + 2]:
			b = False
	for i in range(2, 25, 4):
		if a[i] != a[i + 2]:
			b = False
	if b == False:
		print('NO')
	elif (a[1] == a[6]) & (a[5] == a[10]) & (a[9] == a[21]) & (a[2] == a[22]) | (a[5] == a[2]) & (a[9] == a[6]) & (a[24] == a[12]) & (a[21] == a[1]):
		print('YES')
	else:
		print('NO')
elif ff(d[1:5]) & ff(d[9:13]):
	a = d[:]
	(a[1:5], a[13:17], a[9:13], a[17:21]) = (df(a[17:21]), df(a[1:5]), df(a[13:17]), df(a[9:13]))
	a[5:9] = df(a[5:9])
	a[21:25] = df(df(df(a[21:25])))
	b = True
	for i in range(1, 25, 4):
		if a[i] != a[i + 2]:
			b = False
	for i in range(2, 25, 4):
		if a[i] != a[i + 2]:
			b = False
	if b == False:
		print('NO')
	elif (a[1] == a[6]) & (a[5] == a[10]) & (a[9] == a[21]) & (a[2] == a[22]) | (a[5] == a[2]) & (a[9] == a[6]) & (a[24] == a[12]) & (a[21] == a[1]):
		print('YES')
	else:
		print('NO')
elif ff(d[5:9]) & ff(d[21:25]):
	a = d[:]
	(a[1:5], a[9:13]) = (df(df(df(a[1:5]))), df(a[9:13]))
	(a[13:17], a[5:9], a[17:21], a[21:25]) = (a[5:9], a[17:21], a[21:25], a[13:17])
	b = True
	for i in range(1, 25, 4):
		if a[i] != a[i + 2]:
			b = False
	for i in range(2, 25, 4):
		if a[i] != a[i + 2]:
			b = False
	if b == False:
		print('NO')
	elif (a[1] == a[6]) & (a[5] == a[10]) & (a[9] == a[21]) & (a[2] == a[22]) | (a[5] == a[2]) & (a[9] == a[6]) & (a[24] == a[12]) & (a[21] == a[1]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def main():
	raw = list((int(x) - 1 for x in input().split()))
	d = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]
	l = []
	for i in range(6):
		l.append(raw[4 * i:4 * i + 4])

	def rt(x, y):
		print(x, y)
		if x == (y + 1) % 6 or x == (y + 2) % 6 or x == (y + 3) % 6:
			return True
		else:
			return False
	c = 0
	for face in l:
		if face[0] == face[1] == face[2] == face[3]:
			c += 1
		elif face[0] == face[1] and face[2] == face[3]:
			pass
		elif face[0] == face[2] and face[1] == face[3]:
			pass
		else:
			return 'NO'
	if c != 2:
		return 'NO'
	d = []
	d += [[[[0, 0], [0, 2], [1, 1], [1, 3]], [[1, 0], [1, 2], [2, 1], [2, 3]], [[2, 0], [2, 2], [5, 0], [5, 2]], [[5, 1], [5, 3], [0, 1], [0, 3]]]]
	d += [[[[0, 1], [0, 3], [1, 0], [1, 2]], [[1, 1], [1, 3], [2, 0], [2, 2]], [[2, 1], [2, 3], [5, 1], [5, 3]], [[5, 0], [5, 2], [0, 0], [0, 2]]]]
	d += [[[[1, 0], [1, 1], [4, 2], [4, 3]], [[4, 0], [4, 1], [5, 2], [5, 3]], [[5, 0], [5, 1], [3, 2], [3, 3]], [[3, 0], [3, 1], [1, 2], [1, 3]]]]
	d += [[[[1, 2], [1, 3], [4, 0], [4, 1]], [[4, 2], [4, 3], [5, 0], [5, 1]], [[5, 2], [5, 3], [3, 0], [3, 1]], [[3, 2], [3, 3], [1, 0], [1, 1]]]]
	d += [[[[0, 0], [0, 1], [4, 0], [4, 2]], [[4, 1], [4, 3], [2, 0], [2, 1]], [[2, 2], [2, 3], [3, 1], [3, 3]], [[3, 0], [3, 2], [0, 2], [0, 3]]]]
	d += [[[[0, 2], [0, 3], [4, 1], [4, 3]], [[4, 0], [4, 2], [2, 2], [2, 3]], [[2, 0], [2, 1], [3, 0], [3, 2]], [[3, 1], [3, 3], [0, 0], [0, 1]]]]
	for dd in d:
		flag = True
		for i in dd:
			if not l[i[0][0]][i[0][1]] == l[i[1][0]][i[1][1]] == l[i[2][0]][i[2][1]] == l[i[3][0]][i[3][1]]:
				flag = False
				break
		if flag:
			return 'YES'
	return 'NO'
print(main())


colors = list(map(int, input().split()))
faces = {}
faces['top'] = colors[:4]
faces['front'] = colors[4:8]
faces['bottom'] = colors[8:12]
faces['left'] = colors[12:16]
faces['right'] = colors[16:20]
faces['back'] = [colors[21], colors[20], colors[23], colors[22]]
status = {}
for face in faces.keys():
	colors = faces[face]
	if max(colors) == min(colors):
		status[face] = 'ok'
	elif colors[0] == colors[1] and colors[2] == colors[3]:
		status[face] = 'h'
	elif colors[0] == colors[2] and colors[1] == colors[3]:
		status[face] = 'v'
	else:
		status[face] = 'bad'
if 'bad' in status.values():
	print('NO')
elif status['top'] == status['bottom'] == 'ok' and status['front'] == status['left'] == status['right'] == status['back'] == 'h':
	if faces['front'][0] == faces['left'][3] and faces['left'][0] == faces['back'][3] and (faces['back'][0] == faces['right'][3]) and (faces['right'][0] == faces['front'][3]) or (faces['front'][0] == faces['right'][3] and faces['right'][0] == faces['back'][3] and (faces['back'][0] == faces['left'][3]) and (faces['left'][0] == faces['front'][3])):
		print('YES')
	else:
		print('NO')
elif status['left'] == status['right'] == 'ok' and status['front'] == status['top'] == status['bottom'] == status['back'] == 'v':
	if faces['front'][0] == faces['top'][3] and faces['top'][0] == faces['back'][3] and (faces['back'][0] == faces['bottom'][3]) and (faces['bottom'][0] == faces['front'][3]) or (faces['front'][0] == faces['bottom'][3] and faces['bottom'][0] == faces['back'][3] and (faces['back'][0] == faces['top'][3]) and (faces['top'][0] == faces['front'][3])):
		print('YES')
	else:
		print('NO')
elif status['front'] == status['back'] == 'ok' and status['left'] == status['right'] == 'v' and (status['top'] == status['bottom'] == 'h'):
	if faces['top'][0] == faces['left'][1] and faces['left'][0] == faces['bottom'][0] and (faces['bottom'][3] == faces['right'][0]) and (faces['right'][3] == faces['top'][3]) or (faces['top'][0] == faces['right'][0] and faces['right'][1] == faces['bottom'][0] and (faces['bottom'][3] == faces['left'][1]) and (faces['left'][0] == faces['top'][3])):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


indexes = [[[1, 2, 3, 4], [9, 10, 11, 12], [13, 14, 7, 8], [5, 6, 19, 20], [17, 18, 23, 24], [21, 22, 15, 16]], [[1, 2, 3, 4], [9, 10, 11, 12], [5, 6, 15, 16], [17, 18, 7, 8], [21, 22, 19, 20], [13, 14, 23, 24]], [[17, 18, 19, 20], [13, 14, 15, 16], [21, 23, 1, 3], [10, 12, 22, 24], [6, 8, 9, 11], [2, 4, 5, 7]], [[17, 18, 19, 20], [13, 14, 15, 16], [2, 4, 22, 24], [9, 11, 21, 23], [5, 7, 10, 12], [1, 3, 6, 8]], [[5, 6, 7, 8], [21, 22, 23, 24], [3, 4, 18, 20], [17, 19, 11, 12], [9, 10, 13, 15], [1, 2, 14, 16]], [[5, 6, 7, 8], [21, 22, 23, 24], [1, 2, 17, 19], [9, 10, 18, 20], [14, 16, 11, 12], [3, 4, 13, 15]]]

def same_color(ls, cube):
	first = cube[ls[0]]
	for ind in ls:
		if cube[ind] != first:
			return False
	return True
inp = input().split(' ')
inp = ['0'] + inp
work = False
for turn in indexes:
	work = True
	for grain in turn:
		if not same_color(grain, inp):
			work = False
	if work:
		print('YES')
		exit(0)
print('NO')


def checkRubik(l):
	for i in range(1, 25, 4):
		for j in range(i + 1, i + 4):
			if l[j] != l[i]:
				return False
	return True
a = list(map(int, input().split()))
a.insert(0, 0)
o = checkRubik(a)
if not o:
	b = a
	(b[1], b[3], b[5], b[7], b[9], b[11], b[24], b[22]) = (b[24], b[22], b[1], b[3], b[5], b[7], b[9], b[11])
	o = checkRubik(b)
	if not o:
		b = a
		(b[1], b[3], b[5], b[7], b[9], b[11], b[24], b[22]) = (b[5], b[7], b[9], b[11], b[24], b[22], b[1], b[3])
		o = checkRubik(b)
	if not o:
		b = a
		(b[2], b[4], b[6], b[8], b[10], b[12], b[23], b[21]) = (b[23], b[21], b[2], b[4], b[6], b[8], b[10], b[12])
		o = checkRubik(b)
	if not o:
		b = a
		(b[2], b[4], b[6], b[8], b[10], b[12], b[23], b[21]) = (b[6], b[8], b[10], b[12], b[23], b[21], b[2], b[4])
		o = checkRubik(b)
	if not o:
		b = a
		(b[13], b[14], b[5], b[6], b[17], b[18], b[21], b[22]) = (b[21], b[22], b[13], b[14], b[5], b[6], b[17], b[18])
		o = checkRubik(b)
	if not o:
		b = a
		(b[13], b[14], b[5], b[6], b[17], b[18], b[21], b[22]) = (b[5], b[6], b[17], b[18], b[21], b[22], b[13], b[14])
		o = checkRubik(b)
	if not o:
		b = a
		(b[15], b[16], b[7], b[8], b[19], b[20], b[23], b[24]) = (b[23], b[24], b[15], b[16], b[7], b[8], b[19], b[20])
		o = checkRubik(b)
	if not o:
		b = a
		(b[15], b[16], b[7], b[8], b[19], b[20], b[23], b[24]) = (b[7], b[8], b[19], b[20], b[23], b[24], b[15], b[16])
		o = checkRubik(b)
	if not o:
		b = a
		(b[3], b[4], b[17], b[19], b[10], b[9], b[16], b[14]) = (b[16], b[14], b[3], b[4], b[17], b[19], b[10], b[9])
		o = checkRubik(b)
	if not o:
		b = a
		(b[3], b[4], b[17], b[19], b[10], b[9], b[16], b[14]) = (b[17], b[19], b[10], b[9], b[16], b[14], b[3], b[4])
		o = checkRubik(b)
	if not o:
		b = a
		(b[1], b[2], b[18], b[20], b[12], b[11], b[15], b[13]) = (b[15], b[13], b[1], b[2], b[18], b[20], b[12], b[11])
		o = checkRubik(b)
	if not o:
		b = a
		(b[1], b[2], b[18], b[20], b[12], b[11], b[15], b[13]) = (b[18], b[20], b[12], b[11], b[15], b[13], b[1], b[2])
		o = checkRubik(b)
	if not o:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


l = list(map(int, input().split()))
l.insert(0, 0)
c1 = [1, 6, 3, 8, 5, 10, 7, 12, 9, 23, 11, 21, 13, 14, 15, 16, 17, 18, 19, 20, 4, 22, 2, 24]
c2 = [1, 23, 3, 21, 5, 2, 7, 4, 9, 6, 11, 8, 13, 14, 15, 16, 17, 18, 19, 20, 12, 22, 10, 24]
c3 = [1, 2, 3, 4, 5, 6, 15, 16, 9, 10, 11, 12, 13, 14, 23, 24, 17, 18, 7, 8, 21, 22, 19, 20]
c4 = [1, 2, 3, 4, 5, 6, 19, 20, 9, 10, 11, 12, 13, 14, 7, 8, 17, 18, 23, 24, 21, 22, 15, 16]
c5 = [1, 2, 16, 14, 5, 6, 7, 8, 19, 17, 11, 12, 13, 9, 15, 10, 3, 18, 4, 20, 21, 22, 23, 24]
c6 = [1, 2, 17, 19, 5, 6, 7, 8, 14, 16, 11, 12, 13, 4, 15, 3, 10, 18, 9, 20, 21, 22, 23, 24]
flag = 0
mark = 0
for i in range(6):
	if l[c1[4 * i]] == l[c1[4 * i + 1]] == l[c1[4 * i + 2]] == l[c1[4 * i + 3]]:
		mark = 1
	else:
		mark = 0
		break
if mark:
	flag = 1
mark = 0
for i in range(6):
	if l[c2[4 * i]] == l[c2[4 * i + 1]] == l[c2[4 * i + 2]] == l[c2[4 * i + 3]]:
		mark = 1
	else:
		mark = 0
		break
if mark:
	flag = 1
mark = 0
for i in range(6):
	if l[c3[4 * i]] == l[c3[4 * i + 1]] == l[c3[4 * i + 2]] == l[c3[4 * i + 3]]:
		mark = 1
	else:
		mark = 0
		break
if mark:
	flag = 1
mark = 0
for i in range(6):
	if l[c4[4 * i]] == l[c4[4 * i + 1]] == l[c4[4 * i + 2]] == l[c4[4 * i + 3]]:
		mark = 1
	else:
		mark = 0
		break
if mark:
	flag = 1
mark = 0
for i in range(6):
	if l[c5[4 * i]] == l[c5[4 * i + 1]] == l[c5[4 * i + 2]] == l[c5[4 * i + 3]]:
		mark = 1
	else:
		mark = 0
		break
if mark:
	flag = 1
mark = 0
for i in range(6):
	if l[c6[4 * i]] == l[c6[4 * i + 1]] == l[c6[4 * i + 2]] == l[c6[4 * i + 3]]:
		mark = 1
	else:
		mark = 0
		break
if mark:
	flag = 1
if flag:
	print('YES')
else:
	print('NO')


import copy

def check(n):
	for i in range(1, 25, 4):
		if n[i:i + 4] != [n[i]] * 4:
			return
	print('YES')
	exit(0)
c = [''] + input().split(' ')
n = copy.deepcopy(c)
n[2] = c[6]
n[4] = c[8]
n[6] = c[10]
n[8] = c[12]
n[10] = c[23]
n[12] = c[21]
n[23] = c[2]
n[21] = c[4]
check(n)
n = copy.deepcopy(c)
n[2] = c[23]
n[4] = c[21]
n[6] = c[2]
n[8] = c[4]
n[10] = c[6]
n[12] = c[8]
n[23] = c[10]
n[21] = c[12]
check(n)
n = copy.deepcopy(c)
n[13] = c[5]
n[14] = c[6]
n[5] = c[17]
n[6] = c[18]
n[17] = c[21]
n[18] = c[22]
n[21] = c[13]
n[22] = c[14]
check(n)
n = copy.deepcopy(c)
n[13] = c[21]
n[14] = c[22]
n[5] = c[13]
n[6] = c[14]
n[17] = c[5]
n[18] = c[6]
n[21] = c[17]
n[22] = c[18]
check(n)
n = copy.deepcopy(c)
n[3] = c[17]
n[4] = c[19]
n[14] = c[4]
n[16] = c[3]
n[9] = c[14]
n[10] = c[16]
n[17] = c[10]
n[19] = c[9]
check(n)
n = copy.deepcopy(c)
n[3] = c[16]
n[4] = c[14]
n[14] = c[9]
n[16] = c[10]
n[9] = c[19]
n[10] = c[17]
n[17] = c[3]
n[19] = c[4]
check(n)
print('NO')


cube = [-1] + list(map(int, input().split()))

def ok(cube):
	counter = 0
	last = cube[1]
	for i in cube:
		if i == -1:
			continue
		elif last == i:
			counter += 1
		elif counter != 4:
			return False
		else:
			counter = 1
			last = i
	return True

def rotl(cube):
	cube_n = cube[:]
	cube_n[1] = cube[3]
	cube_n[2] = cube[1]
	cube_n[3] = cube[4]
	cube_n[4] = cube[2]
	cube_n[5] = cube[17]
	cube_n[6] = cube[18]
	cube_n[17] = cube[21]
	cube_n[18] = cube[22]
	cube_n[21] = cube[13]
	cube_n[22] = cube[14]
	cube_n[13] = cube[5]
	cube_n[14] = cube[6]
	return cube_n

def rotr(cube):
	cube_n = cube[:]
	cube_n[1] = cube[2]
	cube_n[2] = cube[4]
	cube_n[3] = cube[1]
	cube_n[4] = cube[3]
	cube_n[5] = cube[13]
	cube_n[6] = cube[14]
	cube_n[17] = cube[5]
	cube_n[18] = cube[6]
	cube_n[21] = cube[17]
	cube_n[22] = cube[18]
	cube_n[13] = cube[21]
	cube_n[14] = cube[22]
	return cube_n

def next(cube):
	cube_n = cube[:]
	cube_n[1] = cube[5]
	cube_n[2] = cube[6]
	cube_n[3] = cube[7]
	cube_n[4] = cube[8]
	cube_n[5] = cube[9]
	cube_n[6] = cube[10]
	cube_n[7] = cube[11]
	cube_n[8] = cube[12]
	cube_n[9] = cube[24]
	cube_n[10] = cube[23]
	cube_n[11] = cube[22]
	cube_n[12] = cube[21]
	cube_n[13] = cube[14]
	cube_n[14] = cube[16]
	cube_n[15] = cube[13]
	cube_n[16] = cube[15]
	cube_n[17] = cube[19]
	cube_n[18] = cube[17]
	cube_n[19] = cube[20]
	cube_n[20] = cube[18]
	cube_n[21] = cube[4]
	cube_n[22] = cube[3]
	cube_n[23] = cube[2]
	cube_n[24] = cube[1]
	return cube_n

def next2(cube):
	cube_n = cube[:]
	cube_n[1] = cube[3]
	cube_n[2] = cube[1]
	cube_n[3] = cube[4]
	cube_n[4] = cube[2]
	cube_n[5] = cube[17]
	cube_n[6] = cube[18]
	cube_n[7] = cube[19]
	cube_n[8] = cube[20]
	cube_n[9] = cube[10]
	cube_n[10] = cube[12]
	cube_n[11] = cube[9]
	cube_n[12] = cube[11]
	cube_n[13] = cube[5]
	cube_n[14] = cube[6]
	cube_n[15] = cube[7]
	cube_n[16] = cube[8]
	cube_n[17] = cube[21]
	cube_n[18] = cube[22]
	cube_n[19] = cube[23]
	cube_n[20] = cube[24]
	cube_n[21] = cube[13]
	cube_n[22] = cube[14]
	cube_n[23] = cube[15]
	cube_n[24] = cube[16]
	return cube_n

def main(cube):
	return ok(rotl(cube)) or ok(rotr(cube))
for i in range(4):
	cube = next(cube)
	if main(next(cube)):
		print('YES')
		return
for i in range(4):
	cube = next2(cube)
	if main(next(cube)):
		print('YES')
		return
print('NO')


qube = list(map(int, input().split()))
g = 1
change = {}
kostka1 = [1, 2, 1, 2, 3, 1, 3, 1, 4, 3, 4, 3, 5, 5, 5, 5, 6, 6, 6, 6, 4, 2, 4, 2]
kostka2 = [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 4, 1, 4, 1, 5, 2, 5, 2, 6, 6, 6, 6]
kostka3 = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 2, 2, 3, 3, 6, 6, 6, 6, 5, 5]
kostka4 = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 3, 3, 5, 5, 6, 6, 2, 2, 5, 5, 6, 6]
kostka5 = [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 2, 5, 2, 5, 1, 4, 1, 4, 6, 6, 6, 6]
kostka6 = [1, 2, 1, 2, 2, 3, 2, 3, 3, 4, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 1, 4, 1, 4]
for i in range(len(qube)):
	if qube[i] not in change:
		j = qube[i]
		change[j] = change.get(j, g)
		g += 1
	qube[i] = change[qube[i]]
if qube == kostka1 or qube == kostka2 or qube == kostka3 or (qube == kostka4) or (qube == kostka5) or (qube == kostka6):
	print('YES')
else:
	print('NO')


PMP = [1, 0, 3, 2, 5, 4, 7, 6]

def Pedy(arr1, arr2):
	global PMP
	for i in range(8):
		h = i
		if i % 2:
			continue
		hh = 0
		anss = 1
		while h != (i - 1 + 8) % 8 and anss:
			if arr1[h] != arr2[hh]:
				anss = 0
			if arr1[h] != arr1[PMP[h]]:
				anss = 0
			h += 1
			hh += 1
			if h == 8:
				h = 0
		if anss and arr1[h] == arr2[hh] and (i == 0 or i == 2 or i == 6):
			return 1
	return 0
a = list(map(int, input().split()))
b = []
for j in range(6):
	i = j * 4
	if a[i] == a[i + 1] and a[i + 1] == a[i + 2] and (a[i + 2] == a[i + 3]):
		b.append(0)
	else:
		b.append(1)
c = []
c.append(b[0] or b[2])
c.append(b[1] or b[5])
c.append(b[3] or b[4])
if c[0] + c[1] + c[2] == 3 or c[0] + c[1] + c[2] == 1:
	print('NO')
if c[0] + c[1] + c[2] == 0:
	print('NO')
if c[0] + c[1] + c[2] == 2:
	if c[0] + c[1] == 2:
		arr1 = []
		arr2 = []
		arr1.append(a[0])
		arr1.append(a[2])
		arr1.append(a[4])
		arr1.append(a[6])
		arr1.append(a[8])
		arr1.append(a[10])
		arr1.append(a[21])
		arr1.append(a[23])
		arr2.append(a[1])
		arr2.append(a[3])
		arr2.append(a[5])
		arr2.append(a[7])
		arr2.append(a[9])
		arr2.append(a[11])
		arr2.append(a[20])
		arr2.append(a[22])
		if Pedy(arr1, arr2):
			print('YES')
		else:
			print('NO')
	if c[0] + c[2] == 2:
		arr1 = []
		arr2 = []
		arr1.append(a[0])
		arr1.append(a[1])
		arr1.append(a[17])
		arr1.append(a[19])
		arr1.append(a[11])
		arr1.append(a[10])
		arr1.append(a[14])
		arr1.append(a[12])
		arr2.append(a[2])
		arr2.append(a[3])
		arr2.append(a[16])
		arr2.append(a[18])
		arr2.append(a[9])
		arr2.append(a[8])
		arr2.append(a[15])
		arr2.append(a[13])
		if Pedy(arr1, arr2):
			print('YES')
		else:
			print('NO')
	if c[1] + c[2] == 2:
		arr1 = []
		arr2 = []
		arr1.append(a[12])
		arr1.append(a[13])
		arr1.append(a[4])
		arr1.append(a[5])
		arr1.append(a[16])
		arr1.append(a[17])
		arr1.append(a[20])
		arr1.append(a[21])
		arr2.append(a[14])
		arr2.append(a[15])
		arr2.append(a[6])
		arr2.append(a[7])
		arr2.append(a[18])
		arr2.append(a[19])
		arr2.append(a[22])
		arr2.append(a[23])
		if Pedy(arr1, arr2):
			print('YES')
		else:
			print('NO')


from copy import *
r = [[] for i in range(6)]
r[1] = [[1, 5, 9, 24], [3, 7, 11, 22]]
r[2] = [[2, 6, 10, 23], [4, 8, 12, 21]]
r[3] = [[13, 5, 17, 21], [14, 6, 18, 22]]
r[4] = [[15, 7, 19, 23], [16, 8, 20, 24]]
r[5] = [[14, 9, 19, 4], [16, 10, 17, 3]]
r[0] = [[13, 11, 20, 2], [15, 12, 18, 1]]
arr = [0] + input().split(' ')

def solve(arr, rot):
	for cycle in rot:
		tmp = arr[cycle[0]]
		arr[cycle[0]] = arr[cycle[1]]
		arr[cycle[1]] = arr[cycle[2]]
		arr[cycle[2]] = arr[cycle[3]]
		arr[cycle[3]] = tmp
	arr = arr[1:]
	res = all((all([arr[x] == arr[i] for x in range(i, i + 4)]) for i in range(0, 24, 4)))
	return res
solved = False
for i in range(6):
	if solve(copy(arr), r[i]):
		print('YES')
		solved = True
		break
if not solved:
	print('NO')


a = [[1, 3, 5, 7, 9, 11, 24, 22], [2, 4, 6, 8, 10, 12, 23, 21], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [2, 1, 13, 15, 11, 12, 20, 18], [4, 3, 14, 16, 9, 10, 19, 17]]
cube = [0] + list(map(int, input().split()))

def rubik(cube):
	if cube[1] == cube[2] == cube[3] == cube[4] and cube[5] == cube[6] == cube[7] == cube[8] and (cube[9] == cube[10] == cube[11] == cube[12]) and (cube[13] == cube[14] == cube[15] == cube[16]) and (cube[17] == cube[18] == cube[19] == cube[20]) and (cube[21] == cube[22] == cube[23] == cube[24]):
		return True
	else:
		return False
for row in a:
	b = cube[:]
	for i in range(8):
		b[row[i]] = cube[row[(i + 2) % 8]]
	if rubik(b):
		print('YES')
		break
	b = cube[:]
	for i in range(8):
		b[row[i]] = cube[row[(8 + i - 2) % 8]]
	if rubik(b):
		print('YES')
		break
else:
	print('NO')


a = [(1, 5), (3, 7), (5, 9), (7, 11), (9, 24), (11, 22), (22, 3), (24, 1)]
b = [(2, 6), (4, 8), (6, 10), (8, 12), (10, 23), (12, 21), (23, 2), (21, 4)]
c = [(5, 13), (6, 14), (17, 5), (18, 6), (21, 17), (22, 18), (14, 22), (13, 21)]
d = [(7, 15), (8, 16), (19, 7), (20, 8), (23, 19), (24, 20), (16, 24), (15, 23)]
e = [(3, 17), (4, 19), (17, 10), (19, 9), (10, 16), (9, 14), (16, 3), (14, 4)]
f = [(1, 18), (2, 20), (18, 12), (20, 11), (12, 15), (11, 13), (15, 1), (13, 2)]
hh = list(map(int, input().split(' ')))
flag = False
for i in [a, b, c, d, e, f]:
	f = True
	h = [hh[j] for j in range(24)]
	for (j, k) in i:
		h[j - 1] = hh[k - 1]
	for j in range(6):
		z = []
		for k in range(4):
			num = j * 4 + k
			z.append(h[num])
		cnt = 0
		for c in range(1, 7):
			if c in z:
				cnt += 1
		if cnt != 1:
			f = False
	if f:
		flag = True
	f = True
	h = [hh[j] for j in range(24)]
	for (j, k) in i:
		h[k - 1] = hh[j - 1]
	for j in range(6):
		z = []
		for k in range(4):
			num = j * 4 + k
			z.append(h[num])
		cnt = 0
		for c in range(1, 7):
			if c in z:
				cnt += 1
		if cnt != 1:
			f = False
	if f:
		flag = True
if flag:
	print('YES')
else:
	print('NO')


def xd(a, b, c, d):
	global s
	if s[a - 1] == s[b - 1] and s[b - 1] == s[c - 1] and (s[c - 1] == s[d - 1]):
		return 1
	else:
		return 0
s = list(map(int, input().split()))
pd = 0
if xd(13, 14, 15, 16) and xd(17, 18, 19, 20) and xd(1, 3, 6, 8) and xd(5, 7, 10, 12) and xd(9, 11, 21, 23) and xd(2, 4, 22, 24):
	pd = 1
if xd(13, 14, 15, 16) and xd(17, 18, 19, 20) and xd(1, 3, 21, 23) and xd(5, 7, 2, 4) and xd(9, 11, 6, 8) and xd(22, 24, 10, 12):
	pd = 1
if xd(1, 2, 3, 4) and xd(9, 10, 11, 12) and xd(5, 6, 19, 20) and xd(17, 18, 23, 24) and xd(21, 22, 15, 16) and xd(13, 14, 7, 8):
	pd = 1
if xd(1, 2, 3, 4) and xd(9, 10, 11, 12) and xd(5, 6, 15, 16) and xd(17, 18, 7, 8) and xd(21, 22, 19, 20) and xd(13, 14, 23, 24):
	pd = 1
if xd(5, 6, 7, 8) and xd(21, 22, 23, 24) and xd(3, 4, 13, 15) and xd(14, 16, 11, 12) and xd(9, 10, 18, 20) and xd(17, 19, 1, 2):
	pd = 1
if xd(5, 6, 7, 8) and xd(21, 22, 23, 24) and xd(3, 4, 18, 20) and xd(14, 16, 1, 2) and xd(9, 10, 13, 15) and xd(17, 19, 11, 12):
	pd = 1
if pd == 1:
	print('YES')
else:
	print('NO')


colors = list(map(int, input().split()))
can = False
if colors[16] == colors[17] == colors[22] == colors[23]:
	if colors[4] == colors[5] == colors[18] == colors[19]:
		if colors[12] == colors[13] == colors[6] == colors[7]:
			if colors[20] == colors[21] == colors[14] == colors[15]:
				if colors[0] == colors[1] == colors[2] == colors[3]:
					if colors[8] == colors[9] == colors[10] == colors[11]:
						can = True
if colors[12] == colors[13] == colors[22] == colors[23]:
	if colors[20] == colors[21] == colors[18] == colors[19]:
		if colors[16] == colors[17] == colors[6] == colors[7]:
			if colors[4] == colors[5] == colors[14] == colors[15]:
				if colors[0] == colors[1] == colors[2] == colors[3]:
					if colors[8] == colors[9] == colors[10] == colors[11]:
						can = True
if colors[14] == colors[12] == colors[2] == colors[3]:
	if colors[0] == colors[1] == colors[16] == colors[18]:
		if colors[17] == colors[19] == colors[8] == colors[9]:
			if colors[10] == colors[11] == colors[13] == colors[15]:
				if colors[20] == colors[21] == colors[22] == colors[23]:
					if colors[4] == colors[5] == colors[6] == colors[7]:
						can = True
if colors[17] == colors[19] == colors[2] == colors[3]:
	if colors[10] == colors[11] == colors[16] == colors[18]:
		if colors[0] == colors[1] == colors[13] == colors[15]:
			if colors[14] == colors[12] == colors[8] == colors[9]:
				if colors[20] == colors[21] == colors[22] == colors[23]:
					if colors[4] == colors[5] == colors[6] == colors[7]:
						can = True
if colors[1] == colors[3] == colors[21] == colors[23]:
	if colors[5] == colors[7] == colors[0] == colors[2]:
		if colors[9] == colors[11] == colors[4] == colors[6]:
			if colors[20] == colors[22] == colors[8] == colors[10]:
				if colors[16] == colors[17] == colors[18] == colors[19]:
					if colors[12] == colors[13] == colors[14] == colors[15]:
						can = True
if colors[9] == colors[11] == colors[21] == colors[23]:
	if colors[20] == colors[22] == colors[0] == colors[2]:
		if colors[5] == colors[7] == colors[8] == colors[10]:
			if colors[1] == colors[3] == colors[4] == colors[6]:
				if colors[16] == colors[17] == colors[18] == colors[19]:
					if colors[12] == colors[13] == colors[14] == colors[15]:
						can = True
if can:
	print('YES')
else:
	print('NO')


a = [int(i) for i in input().split()]
a1 = [[a[j * 4 + i] for i in range(4)] for j in range(6)]
ver = a1[0]
per = a1[1]
niz = a1[2]
lev = a1[3]
prav = a1[4]
zad = a1[5]
res = 'NO'
if len(set(lev)) == 1 and len(set(prav)) == 1:
	per1 = 1 if per[1] == per[3] else 0
	ver1 = 1 if ver[1] == ver[3] else 0
	niz1 = 1 if niz[1] == niz[3] else 0
	zad1 = 1 if zad[0] == zad[2] else 0
	per2 = 1 if per[0] == per[2] else 0
	ver2 = 1 if ver[0] == ver[2] else 0
	niz2 = 1 if niz[0] == niz[2] else 0
	zad2 = 1 if zad[1] == zad[3] else 0
	if (per1 == ver2 and per[1] == ver[0]) and (ver1 == zad2 and zad[1] == ver[1]) and (zad1 == niz2 and zad[0] == niz[0]) and (niz1 == per2 and per[0] == niz[1]):
		res = 'YES'
	elif (per1 == niz2 and per[1] == niz[0]) and (ver1 == per2 and per[0] == ver[1]) and (zad1 == ver2 and zad[0] == ver[0]) and (niz1 == zad2 and zad[1] == niz[1]):
		res = 'YES'
elif len(set(niz)) == 1 and len(set(ver)) == 1:
	per1 = 1 if per[0] == per[1] else 0
	lev1 = 1 if lev[0] == lev[1] else 0
	prav1 = 1 if prav[0] == prav[1] else 0
	zad1 = 1 if zad[0] == zad[1] else 0
	per2 = 1 if per[2] == per[3] else 0
	lev2 = 1 if lev[2] == lev[3] else 0
	prav2 = 1 if prav[2] == prav[3] else 0
	zad2 = 1 if zad[2] == zad[3] else 0
	if (per1 == lev2 and per[0] == lev[2]) and (lev1 == zad2 and zad[2] == lev[0]) and (zad1 == prav2 and zad[0] == prav[2]) and (prav1 == per2 and per[2] == prav[0]):
		res = 'YES'
	elif (per1 == prav2 and per[0] == prav[2]) and (prav1 == zad2 and zad[2] == prav[0]) and (zad1 == lev2 and zad[0] == lev[2]) and (lev1 == per2 and per[2] == lev[0]):
		res = 'YES'
elif len(set(per)) == 1 and len(set(zad)) == 1:
	ver1 = 1 if ver[2] == ver[3] else 0
	lev1 = 1 if lev[3] == lev[1] else 0
	prav1 = 1 if prav[0] == prav[2] else 0
	niz1 = 1 if niz[0] == niz[1] else 0
	ver2 = 1 if ver[0] == ver[1] else 0
	lev2 = 1 if lev[2] == lev[0] else 0
	prav2 = 1 if prav[1] == prav[3] else 0
	niz2 = 1 if niz[2] == niz[3] else 0
	if (ver1 == lev2 and ver[2] == lev[2]) and (lev1 == niz2 and niz[2] == lev[3]) and (niz1 == prav2 and niz[0] == prav[1]) and (prav1 == ver2 and ver[0] == prav[0]):
		res = 'YES'
	elif (ver1 == prav2 and ver[2] == prav[1]) and (prav1 == niz2 and niz[2] == prav[0]) and (niz1 == lev2 and niz[0] == lev[2]) and (lev1 == ver2 and ver[0] == lev[3]):
		res = 'YES'
if len(set(per)) == 1 and len(set(zad)) == 1 and (len(set(niz)) == 1) and (len(set(ver)) == 1) and (len(set(lev)) == 1) and (len(set(prav)) == 1):
	res = 'NO'
print(res)


a = list(map(int, input().split()))

def magic(b):
	for i in range(4):
		if not b[i * 4] == b[i * 4 + 2] == b[(i * 4 + 5) % 16] == b[(i * 4 + 7) % 16]:
			break
	else:
		print('YES')
		return
	for i in range(4):
		if not b[4 * i + 1] == b[4 * i + 3] == b[(4 * i + 4) % 16] == b[(4 * i + 6) % 16]:
			break
	else:
		print('YES')
		return
	print('NO')
	return
if a[0] == a[2] == a[3] == a[1] and a[8] == a[10] == a[11] == a[9]:
	magic([a[14], a[12], a[15], a[13], a[6], a[4], a[7], a[5], a[18], a[16], a[19], a[17], a[22], a[20], a[23], a[21]])
elif a[12] == a[14] == a[15] == a[13] and a[16] == a[18] == a[17] == a[19]:
	magic(a[:12] + a[23:19:-1])
elif a[4] == a[6] == a[7] == a[5] and a[20] == a[22] == a[23] == a[23]:
	magic([a[2], a[0], a[3], a[1], a[16], a[17], a[18], a[19], a[9], a[11], a[8], a[10], a[15], a[14], a[13], a[12]])
else:
	print('NO')


cb = [int(item) for item in input().split()]
cbb = [cb[i:i + 4] for i in range(0, 24, 4)]
cons = [[i] * 4 for i in range(1, 7)]
k = 0
completeFaces = []

def v(x, y):
	return cb[x - 1] == cb[y - 1]

def rot(thing):
	for (p, xx) in enumerate(thing):
		x = [xx[:2], xx[2:]]
		for i in range(2):
			for j in range(i + 1, 2):
				(x[i][j], x[j][i]) = (x[j][i], x[i][j])
		if p != 5:
			(x[0][0], x[1][0]) = (x[1][0], x[0][0])
			(x[0][1], x[1][1]) = (x[1][1], x[0][1])
		else:
			x[0] = x[0][::-1]
			x[1] = x[1][::-1]
		thing[p] = x[0] + x[1]
	return thing
for i in range(0, 24, 4):
	if cb[i:i + 4] in cons:
		k += 1
		completeFaces.append(i // 4 + 1)
if k != 2 or completeFaces not in [[1, 3], [4, 5], [2, 6]]:
	print('NO')
else:
	if completeFaces == [1, 3]:
		(cbb[0], cbb[2], cbb[3], cbb[4]) = (cbb[4].copy(), cbb[3].copy(), cbb[0].copy(), cbb[2].copy())
		cbb = rot(cbb)
	elif completeFaces == [2, 6]:
		(cbb[1], cbb[3], cbb[4], cbb[5]) = (cbb[4].copy(), cbb[1].copy(), cbb[5].copy(), cbb[3].copy())
		cbb[0] = [cbb[0][2], cbb[0][0], cbb[0][3], cbb[0][1]]
		cbb[2] = [cbb[2][1], cbb[2][3], cbb[2][0], cbb[2][2]]
	cb = cbb[0] + cbb[1] + cbb[2] + cbb[3] + cbb[4] + cbb[5]
	case1 = v(5, 10) and v(7, 12) and v(1, 6) and v(3, 8) and v(2, 22) and v(4, 24) and v(9, 21) and v(11, 23) and v(5, 7) and v(10, 12) and v(1, 3) and v(6, 8) and v(2, 4) and v(22, 24) and v(9, 11) and v(21, 23)
	case2 = v(5, 2) and v(7, 4) and v(9, 6) and v(11, 8) and v(1, 21) and v(3, 23) and v(10, 22) and v(12, 24) and v(5, 7) and v(2, 4) and v(9, 11) and v(6, 8) and v(1, 3) and v(21, 23) and v(10, 12) and v(22, 24)
	if case1 or case2:
		print('YES')
	else:
		print('NO')


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline

def solved(a):
	side1 = set(a[:4])
	side2 = set(a[4:8])
	side3 = set(a[8:12])
	side4 = set(a[12:16])
	side5 = set(a[16:20])
	side6 = set(a[20:24])
	for side in [side1, side2, side3, side4, side5, side6]:
		if len(side) != 1:
			return False
	return True
a = list(map(int, input().split()))
turn1 = {1: 5, 3: 7, 5: 9, 7: 11, 9: 24, 11: 22, 24: 1, 22: 3}
turn2 = {2: 6, 4: 8, 6: 10, 8: 12, 10: 21, 12: 23, 23: 2, 21: 4}
turn3 = {5: 13, 6: 14, 17: 5, 18: 6, 21: 17, 22: 18, 13: 21, 14: 22}
turn4 = {7: 15, 8: 16, 19: 7, 20: 8, 23: 19, 24: 20, 16: 24, 15: 23}
turn5 = {17: 10, 19: 9, 9: 14, 10: 16, 14: 4, 16: 3, 4: 19, 3: 17}
turn6 = {18: 12, 20: 11, 11: 13, 12: 15, 13: 2, 15: 1, 2: 20, 1: 18}
for turn in [turn1, turn2, turn3, turn4, turn5, turn6]:
	new_a = [ai for ai in a]
	for (old, new) in turn.items():
		new_a[old - 1] = a[new - 1]
	if solved(new_a):
		print('YES')
		break
else:
	print('NO')


import sys
import copy
n = list(map(int, input().strip().split()))
j = 1
mx = [[0 for i in range(8)] for j in range(6)]
for i in range(6):
	mx[i][2] = j
	mx[i][3] = j + 1
	j += 2
for i in range(2, 4):
	mx[i][0] = j
	mx[i][1] = j + 1
	j = j + 2
for i in range(2, 4):
	mx[i][4] = j
	mx[i][5] = j + 1
	j = j + 2
for i in range(2, 4):
	mx[i][6] = j
	mx[i][7] = j + 1
	j = j + 2
for i in range(6):
	for j in range(8):
		if mx[i][j] != 0:
			mx[i][j] = n[mx[i][j] - 1]
mv = []
for i in range(12):
	mv.append(copy.deepcopy(mx))
j = 0
for i in range(2):
	mv[j][0][2 + i] = mx[2][2 + i]
	mv[j][1][2 + i] = mx[3][2 + i]
	mv[j][2][2 + i] = mx[4][2 + i]
	mv[j][3][2 + i] = mx[5][2 + i]
	mv[j][4][2 + i] = mx[3][7 - i]
	mv[j][5][2 + i] = mx[2][7 - i]
	mv[j][3][7 - i] = mx[0][2 + i]
	mv[j][2][7 - i] = mx[1][2 + i]
	mv[j + 1][0][2 + i] = mx[3][7 - i]
	mv[j + 1][1][2 + i] = mx[2][7 - i]
	mv[j + 1][2][2 + i] = mx[0][2 + i]
	mv[j + 1][3][2 + i] = mx[1][2 + i]
	mv[j + 1][4][2 + i] = mx[2][2 + i]
	mv[j + 1][5][2 + i] = mx[3][2 + i]
	mv[j + 1][3][7 - i] = mx[4][2 + i]
	mv[j + 1][2][7 - i] = mx[5][2 + i]
	mv[j + 2][2 + i][0] = mx[2 + i][2]
	mv[j + 2][2 + i][1] = mx[2 + i][3]
	mv[j + 2][2 + i][2] = mx[2 + i][4]
	mv[j + 2][2 + i][3] = mx[2 + i][5]
	mv[j + 2][2 + i][4] = mx[2 + i][6]
	mv[j + 2][2 + i][5] = mx[2 + i][7]
	mv[j + 2][2 + i][6] = mx[2 + i][0]
	mv[j + 2][2 + i][7] = mx[2 + i][1]
	mv[j + 3][2 + i][0] = mx[2 + i][6]
	mv[j + 3][2 + i][1] = mx[2 + i][7]
	mv[j + 3][2 + i][2] = mx[2 + i][0]
	mv[j + 3][2 + i][3] = mx[2 + i][1]
	mv[j + 3][2 + i][4] = mx[2 + i][2]
	mv[j + 3][2 + i][5] = mx[2 + i][3]
	mv[j + 3][2 + i][6] = mx[2 + i][4]
	mv[j + 3][2 + i][7] = mx[2 + i][5]
	mv[j + 4][i][2] = mx[3][i]
	mv[j + 4][i][3] = mx[2][i]
	mv[j + 4][2][i] = mx[5 - i][2]
	mv[j + 4][3][i] = mx[5 - i][3]
	mv[j + 4][5 - i][2] = mx[3][5 - i]
	mv[j + 4][5 - i][3] = mx[2][5 - i]
	mv[j + 4][2][5 - i] = mx[i][2]
	mv[j + 4][3][5 - i] = mx[i][3]
	mv[j + 5][i][2] = mx[2][5 - i]
	mv[j + 5][i][3] = mx[3][5 - i]
	mv[j + 5][2][i] = mx[i][3]
	mv[j + 5][3][i] = mx[i][2]
	mv[j + 5][5 - i][2] = mx[2][i]
	mv[j + 5][5 - i][3] = mx[3][i]
	mv[j + 5][2][5 - i] = mx[5 - i][3]
	mv[j + 5][3][5 - i] = mx[5 - i][2]
	j = j + 6
l = 0
for k in mv:
	l = l + 1
	i = j = 0
	while i < 5:
		while j < 7:
			if False == (k[i][j] == k[i][j + 1] and k[i][j] == k[i + 1][j] and (k[i][j] == k[i + 1][j + 1])):
				i = j = 8
			j = j + 2
		i = i + 2
		j = 0
	if i != 10:
		print('YES')
		sys.exit()
print('NO')


colors = ['SHIT'] + list(map(int, input().split()))
faces = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12), (13, 14, 15, 16), (17, 18, 19, 20), (21, 22, 23, 24)]

def is_good(colors):
	return all([all([colors[i] == colors[face[0]] for i in face]) for face in faces])
rotations = {(1, 2, 3, 4): ([13, 5, 17, 21], [14, 6, 18, 22]), (5, 6, 7, 8): ([14, 9, 19, 4], [16, 10, 17, 3]), (9, 10, 11, 12): ([7, 15, 23, 19], [8, 16, 24, 20]), (13, 14, 15, 16): ([5, 1, 24, 9], [7, 3, 22, 11]), (17, 18, 19, 20): ([6, 10, 23, 2], [8, 12, 21, 4]), (21, 22, 23, 24): ([1, 18, 12, 15], [2, 20, 11, 13])}

def rotate(colors, face):
	result1 = colors.copy()
	(rule1, rule2) = rotations[face]
	for i in range(4):
		result1[rule1[i]] = colors[rule1[(i + 1) % 4]]
		result1[rule2[i]] = colors[rule2[(i + 1) % 4]]
	result2 = colors.copy()
	for i in range(4):
		result2[rule1[(i + 1) % 4]] = colors[rule1[i]]
		result2[rule2[(i + 1) % 4]] = colors[rule2[i]]
	return (result1, result2)
for face in faces:
	rotated = rotate(colors, face)
	if is_good(rotated[0]) or is_good(rotated[1]):
		print('YES')
		break
else:
	print('NO')


def g(l1, l2):
	dic = {}
	for ls in [l1, l2]:
		ls.append(ls[0])
		ls.append(ls[1])
		num = 2 if ls == l1 else 1
		for i in range(len(ls) - num):
			dic[ls[i + num]] = ls[i]
	return (dic, dict(((val, key) for (key, val) in dic.items())))
(left, left_) = g([1, 3, 5, 7, 9, 11, 24, 22], [13, 14, 16, 15])
(top, top_) = g([13, 14, 5, 6, 17, 18, 21, 22], [1, 3, 4, 2])
(right, right_) = g([4, 2, 21, 23, 12, 10, 8, 6], [17, 18, 20, 19])
(bottom, bottom_) = g([15, 16, 7, 8, 19, 20, 23, 24], [9, 10, 12, 11])
(back, back_) = g([1, 2, 18, 20, 12, 11, 15, 13], [21, 23, 24, 22])
(center, center_) = g([3, 4, 17, 19, 10, 9, 16, 14], [5, 6, 8, 7])
all_dics = [left, left_, right, right_, top, top_, bottom, bottom_, back, back_, center, center_]
vals = [int(elem) for elem in input().split(' ')]

def f(vals):
	for dic in all_dics:
		aux = list(vals)
		for val in dic:
			aux[val - 1] = vals[dic[val] - 1]
		for i in range(6):
			found = True
			if len(set(aux[4 * i:4 * (i + 1)])) != 1:
				found = False
				break
		if found:
			print('YES')
			return
	print('NO')
f(vals)


import sys
input = sys.stdin.readline

def read():
	return list(map(int, input().split()))

def check(x):
	for i in range(0, 24, 4):
		if x[i:i + 4] != [x[i]] * 4:
			return False
	return True
a = read()
if check(a):
	print('NO')
	quit()
b = list(a)
(b[2], b[3], b[16], b[18], b[9], b[8], b[15], b[13]) = (b[15], b[13], b[2], b[3], b[16], b[18], b[9], b[8])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[2], b[3], b[16], b[18], b[9], b[8], b[15], b[13]) = (b[16], b[18], b[9], b[8], b[15], b[13], b[2], b[3])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[0], b[1], b[17], b[19], b[11], b[10], b[14], b[12]) = (b[14], b[12], b[0], b[1], b[17], b[19], b[11], b[10])
if check(b):
	print('YES')
	quit()
	b = list(a)
(b[0], b[1], b[17], b[19], b[11], b[10], b[14], b[12]) = (b[17], b[19], b[11], b[10], b[14], b[12], b[0], b[1])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[4], b[5], b[12], b[13], b[20], b[21], b[16], b[17]) = (b[12], b[13], b[20], b[21], b[16], b[17], b[4], b[5])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[4], b[5], b[12], b[13], b[20], b[21], b[16], b[17]) = (b[16], b[17], b[4], b[5], b[12], b[13], b[20], b[21])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[6], b[7], b[14], b[15], b[22], b[23], b[18], b[19]) = (b[14], b[15], b[22], b[23], b[18], b[19], b[6], b[7])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[6], b[7], b[14], b[15], b[22], b[23], b[18], b[19]) = (b[18], b[19], b[6], b[7], b[14], b[15], b[22], b[23])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[1], b[3], b[5], b[7], b[9], b[11], b[22], b[20]) = (b[5], b[7], b[9], b[11], b[22], b[20], b[1], b[3])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[1], b[3], b[5], b[7], b[9], b[11], b[22], b[20]) = (b[22], b[20], b[1], b[3], b[5], b[7], b[9], b[11])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[0], b[2], b[4], b[6], b[8], b[10], b[23], b[21]) = (b[4], b[6], b[8], b[10], b[23], b[21], b[0], b[2])
if check(b):
	print('YES')
	quit()
b = list(a)
(b[0], b[2], b[4], b[6], b[8], b[10], b[23], b[21]) = (b[23], b[21], b[0], b[2], b[4], b[6], b[8], b[10])
if check(b):
	print('YES')
	quit()
print('NO')


import copy

def r1(x):
	(x[7], x[8], x[19], x[20], x[23], x[24], x[15], x[16]) = (x[15], x[16], x[7], x[8], x[19], x[20], x[23], x[24])
	return x

def r2(x):
	(x[5], x[6], x[17], x[18], x[21], x[22], x[13], x[14]) = (x[13], x[14], x[5], x[6], x[17], x[18], x[21], x[22])
	return x

def r3(x):
	(x[5], x[7], x[9], x[11], x[24], x[22], x[1], x[3]) = (x[9], x[11], x[24], x[22], x[1], x[3], x[5], x[7])
	return x

def r4(x):
	(x[6], x[8], x[10], x[12], x[23], x[21], x[2], x[4]) = (x[10], x[12], x[23], x[21], x[2], x[4], x[6], x[8])
	return x

def r5(x):
	(x[3], x[4], x[17], x[19], x[9], x[10], x[14], x[16]) = (x[14], x[16], x[3], x[4], x[17], x[19], x[9], x[10])
	return x

def r6(x):
	(x[1], x[2], x[18], x[20], x[11], x[12], x[13], x[15]) = (x[13], x[15], x[1], x[2], x[18], x[20], x[11], x[12])
	return x

def judge(x):
	for i in range(6):
		if (x[i * 4 + 4] != x[i * 4 + 1] or x[i * 4 + 2] != x[i * 4 + 1]) or x[i * 4 + 2] != x[i * 4 + 3]:
			return False
	return True
a = [int(i) for i in input('').split()]
ans = False
b = ['fuck']
for i in a:
	b.append(i)
if judge(r1(b)):
	ans = True
b = ['fuck']
for i in a:
	b.append(i)
if judge(r2(b)):
	ans = True
b = ['fuck']
for i in a:
	b.append(i)
if judge(r3(b)):
	ans = True
b = ['fuck']
for i in a:
	b.append(i)
if judge(r4(b)):
	ans = True
b = ['fuck']
for i in a:
	b.append(i)
if judge(r5(b)):
	ans = True
b = ['fuck']
for i in a:
	b.append(i)
if judge(r6(b)):
	ans = True
if ans:
	print('YES')
else:
	print('NO')


n = list(input().split())

def newMap(n, transPair):
	new_list = n[:]
	for pair in transPair:
		new_list[pair[0] - 1] = n[pair[1] - 1]
	return new_list

def isOK(n):
	for f in range(0, 6):
		for i in range(0, 3):
			if n[f * 4 + i] != n[f * 4 + i + 1]:
				return False
	return True

def cal(n):
	new = n
	for _ in range(0, 4):
		new = newMap(new, [(1, 5), (5, 9), (9, 24), (24, 1), (3, 7), (7, 11), (11, 22), (22, 3)])
		if _ % 2 == 1:
			continue
		res = isOK(new)
		if res:
			print('YES')
			return
	new = n
	for _ in range(0, 4):
		new = newMap(new, [(13, 5), (5, 17), (17, 21), (21, 13), (14, 6), (6, 18), (18, 22), (22, 14)])
		if _ % 2 == 1:
			continue
		res = isOK(new)
		if res:
			print('YES')
			return
	new = n
	for _ in range(0, 4):
		new = newMap(new, [(4, 14), (14, 9), (9, 19), (19, 4), (3, 16), (16, 10), (10, 17), (17, 3)])
		if _ % 2 == 1:
			continue
		res = isOK(new)
		if res:
			print('YES')
			return
	print('NO')
cal(n)


a = [[1, 3, 5, 7, 9, 11, 24, 22], [2, 4, 6, 8, 10, 12, 23, 21], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [16, 14, 3, 4, 17, 19, 10, 9], [15, 13, 1, 2, 18, 20, 12, 11]]

def rotate(b, i1, i2, i3, i4, i5, i6, i7, i8):
	(b[i1], b[i2], b[i3], b[i4], b[i5], b[i6], b[i7], b[i8]) = (b[i7], b[i8], b[i1], b[i2], b[i3], b[i4], b[i5], b[i6])
	y = 1
	for k in range(1, 24, 4):
		y &= all(map(lambda x: x == b[k], b[k:k + 4]))
	return y
b = list(map(int, input().split()))
b.insert(0, 0)
y = 0
for i in a:
	y |= rotate(list(b), *i)
	y |= rotate(list(b), *reversed(i))
print('YES' if y else 'NO')


a = [int(i) for i in input().split()][0:24]
cnt = 0
fin = []
for i in range(0, 24, 4):
	if a[i] == a[i + 1] == a[i + 2] == a[i + 3]:
		cnt += 1
		fin.append(i)
if cnt == 0:
	print('NO')
elif cnt == 2:
	if fin == [12, 16]:
		if a[0] == a[2] == a[5] == a[7] and a[4] == a[6] == a[9] == a[11] and (a[8] == a[10] == a[20] == a[22]) and (a[1] == a[3] == a[21] == a[23]):
			print('YES')
		elif a[0] == a[2] == a[20] == a[22] and a[4] == a[6] == a[1] == a[3] and (a[8] == a[10] == a[5] == a[7]) and (a[1] == a[3] == a[4] == a[6]):
			print('YES')
		else:
			print('NO')
	elif fin == [4, 20]:
		if a[0] == a[1] == a[16] == a[18] and a[2] == a[3] == a[12] == a[14] and (a[10] == a[11] == a[13] == a[15]) and (a[8] == a[9] == a[17] == a[19]):
			print('YES')
		elif a[0] == a[1] == a[13] == a[15] and a[2] == a[3] == a[17] == a[19] and (a[10] == a[11] == a[16] == a[18]) and (a[8] == a[9] == a[12] == a[14]):
			print('YES')
		else:
			print('NO')
	elif fin == [0, 8]:
		if a[12] == a[13] == a[6] == a[7] and a[4] == a[5] == a[18] == a[19] and (a[16] == a[17] == a[23] == a[22]) and (a[20] == a[21] == a[14] == a[15]):
			print('YES')
		elif a[12] == a[13] == a[22] == a[23] and a[4] == a[5] == a[14] == a[15] and (a[16] == a[17] == a[6] == a[7]) and (a[20] == a[21] == a[18] == a[19]):
			print('YES')
		else:
			print('NO')
else:
	print('NO')


original = input().split()
original = [int(x) for x in original]

def transform(T, a):
	b = a[:]
	for i in range(0, 24):
		b[T[i]] = a[i]
	return b

def generate_transformation(delta):
	ans0 = [x for x in range(0, 24)]
	ans1 = [x for x in range(0, 24)]
	for (k, v) in delta.items():
		ans0[k - 1] = v - 1
		ans1[v - 1] = k - 1
	return (ans0, ans1)
facegroup = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]

def check_done(facegroup, faces):
	for fg in facegroup:
		for cell in fg:
			if faces[cell - 1] != faces[fg[0] - 1]:
				return False
	return True
tl = {1: 5, 3: 7, 5: 9, 7: 11, 9: 24, 11: 22, 24: 1, 22: 3, 14: 16, 16: 15, 15: 13, 13: 14}
tr = {2: 6, 4: 8, 6: 10, 8: 12, 10: 23, 12: 21, 23: 2, 21: 4, 17: 19, 19: 20, 20: 18, 18: 17}
tt = {13: 5, 14: 6, 5: 17, 6: 18, 17: 21, 18: 2, 21: 13, 22: 14, 1: 3, 3: 4, 4: 2, 2: 1}
td = {15: 7, 16: 8, 7: 19, 8: 20, 19: 23, 20: 24, 23: 15, 24: 16, 9: 10, 10: 12, 12: 11, 11: 9}
tf = {5: 6, 6: 7, 7: 8, 8: 6, 14: 9, 16: 10, 9: 19, 10: 17, 19: 4, 17: 3, 4: 14, 3: 16}
tb = {23: 21, 21: 22, 22: 24, 24: 23, 2: 13, 1: 15, 13: 11, 15: 12, 11: 20, 12: 18, 20: 2, 18: 1}
t = [tl, tr, tt, td, tf, tb]
ok = False
for trans in t:
	(u, v) = generate_transformation(trans)
	if check_done(facegroup, transform(u, original)):
		ok = True
		break
	if check_done(facegroup, transform(v, original)):
		ok = True
		break
if ok:
	print('YES')
else:
	print('NO')


from functools import reduce
kubik = list(map(int, input().split()))
kubik = [None] + kubik
sides = [[4 * i + j for j in range(1, 5)] for i in range(6)]
loops = [[1, 3, 5, 7, 9, 11, 24, 22], [2, 4, 6, 8, 10, 12, 23, 21], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [1, 2, 18, 20, 12, 11, 15, 13], [3, 4, 17, 19, 10, 9, 16, 14]]

def side_solved(kubik, indices) -> bool:
	return all((kubik[indices[i - 1]] == kubik[indices[i]] for i in range(1, len(indices))))

def kubik_solved(kubik) -> bool:
	return all((side_solved(kubik, side) for side in sides))

def move_solved(kubik, side, side_shift, loop, loop_shift):
	kubik2 = kubik[:]
	s = sides[side]
	for i in range(len(s)):
		kubik2[s[(i + side_shift) % len(s)]] = kubik[s[i]]
	l = loops[loop]
	for i in range(len(l)):
		kubik2[l[(i + loop_shift) % len(l)]] = kubik[l[i]]
	return kubik_solved(kubik2)
if any((move_solved(kubik, s, ss, l, ls) for (s, ss, l, ls) in [[3, +1, 0, +2], [3, -1, 0, -2], [4, -1, 1, +2], [4, +1, 1, -2], [0, -1, 2, +2], [0, +1, 2, -2], [2, +1, 3, +2], [2, -1, 3, -2], [5, -1, 4, +2], [5, +1, 4, -2], [1, +1, 5, +2], [1, -1, 5, -2]])):
	print('YES')
else:
	print('NO')


a = [int(w) for w in input().split()]
cycles = [[5, 6, 17, 18, 21, 22, 13, 14], [9, 10, 19, 17, 4, 3, 14, 16], [8, 7, 16, 15, 24, 23, 20, 19], [7, 5, 3, 1, 22, 24, 11, 9], [6, 8, 10, 12, 23, 21, 2, 4], [18, 20, 12, 11, 15, 13, 1, 2]]
cycles = [[i - 1 for i in cycle] for cycle in cycles]
cycles += [list(reversed(cycle)) for cycle in cycles]

def rotate(a, cycle):
	b = a[:]
	for i in range(8):
		b[cycle[(i + 2) % 8]] = a[cycle[i]]
	return b

def ordered(a):
	for side in range(6):
		if not a[side * 4] == a[side * 4 + 1] == a[side * 4 + 2] == a[side * 4 + 3]:
			return False
	return True
for cycle in cycles:
	if ordered(rotate(a, cycle)):
		print('YES')
		break
else:
	print('NO')


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
A = [0] + [int(x) for x in input().split()]
cc = collections.Counter(A[1:])
if any([x != 4 for x in cc.values()]):
	print('NO')
	exit(0)
goodFace = []
for i in range(6):
	s = i * 4 + 1
	if all([A[j] == A[s] for j in range(s, s + 4)]):
		goodFace.append(i)
if len(goodFace) != 2:
	print('NO')
	exit(0)
gfd = ''.join(map(str, goodFace))
if gfd not in {'02', '34', '15'}:
	print('NO')
	exit(0)
(f1, f2) = ([], [])
if gfd == '02':
	f1 = [A[i] for i in [13, 14, 5, 6, 17, 18, 21, 22]]
	f2 = [A[i] for i in [15, 16, 7, 8, 19, 20, 23, 24]]
elif gfd == '34':
	f1 = [A[i] for i in [1, 3, 5, 7, 9, 11, 22, 24]]
	f2 = [A[i] for i in [2, 4, 6, 8, 10, 12, 21, 23]]
else:
	f1 = [A[i] for i in [3, 4, 17, 19, 10, 9, 16, 14]]
	f2 = [A[i] for i in [1, 2, 18, 20, 12, 11, 15, 13]]
for i in range(4):
	if i != 2 and f1 == f2:
		print('YES')
		exit(0)
	f1 = f1[-2:] + f1[:-2]
print('NO')


A1 = [[0, 2, 4, 6, 8, 10, 21, 23], [1, 3, 5, 7, 9, 11, 20, 22], [2, 3, 16, 18, 9, 8, 15, 13], [0, 1, 17, 19, 11, 10, 14, 12], [12, 13, 4, 5, 16, 17, 20, 21], [14, 15, 6, 7, 18, 19, 22, 23]]
flag = False
B = list(map(int, input().split()))
for j in range(6):
	A = list(B)
	for i in range(2):
		b = A[A1[j][0]]
		A[A1[j][0]] = A[A1[j][1]]
		A[A1[j][1]] = A[A1[j][2]]
		A[A1[j][2]] = A[A1[j][3]]
		A[A1[j][3]] = A[A1[j][4]]
		A[A1[j][4]] = A[A1[j][5]]
		A[A1[j][5]] = A[A1[j][6]]
		A[A1[j][6]] = A[A1[j][7]]
		A[A1[j][7]] = b
		if (A[0] == A[1] == A[2] == A[3]) & (A[4] == A[5] == A[6] == A[7]) & (A[8] == A[9] == A[10] == A[11]) & (A[12] == A[13] == A[14] == A[15]) & (A[16] == A[17] == A[18] == A[19]) & (A[20] == A[21] == A[22] == A[23]):
			flag = True
			break
	A = list(B)
	for i in range(2):
		b = A[A1[j][7]]
		A[A1[j][7]] = A[A1[j][6]]
		A[A1[j][6]] = A[A1[j][5]]
		A[A1[j][5]] = A[A1[j][4]]
		A[A1[j][4]] = A[A1[j][3]]
		A[A1[j][3]] = A[A1[j][2]]
		A[A1[j][2]] = A[A1[j][1]]
		A[A1[j][1]] = A[A1[j][0]]
		A[A1[j][0]] = b
		if (A[0] == A[1] == A[2] == A[3]) & (A[4] == A[5] == A[6] == A[7]) & (A[8] == A[9] == A[10] == A[11]) & (A[12] == A[13] == A[14] == A[15]) & (A[16] == A[17] == A[18] == A[19]) & (A[20] == A[21] == A[22] == A[23]):
			flag = True
			break
	if flag:
		break
if flag:
	print('YES')
else:
	print('NO')


def check(dat):
	mark = 0
	for i in range(6):
		if dat[4 * i] == dat[4 * i + 1] and dat[4 * i] == dat[4 * i + 2] and (dat[4 * i] == dat[4 * i + 3]):
			mark += 1
	if mark == 6:
		return True
	return False
data = list(map(int, input().split()))
for i in range(1):
	data2 = data.copy()
	data2[0] = data[14]
	data2[1] = data[12]
	data2[14] = data[11]
	data2[12] = data[10]
	data2[11] = data[17]
	data2[10] = data[19]
	data2[17] = data[0]
	data2[19] = data[1]
	if check(data2):
		print('YES')
		exit(0)
	data2 = data.copy()
	data2[0] = data[17]
	data2[1] = data[19]
	data2[17] = data[11]
	data2[19] = data[10]
	data2[11] = data[14]
	data2[10] = data[12]
	data2[14] = data[0]
	data2[12] = data[1]
	if check(data2):
		print('YES')
		exit(0)
	data2 = data.copy()
	data2[0] = data[4]
	data2[2] = data[6]
	data2[4] = data[8]
	data2[6] = data[10]
	data2[8] = data[23]
	data2[10] = data[21]
	data2[23] = data[0]
	data2[21] = data[2]
	if check(data2):
		print('YES')
		exit(0)
	data2 = data.copy()
	data2[0] = data[23]
	data2[2] = data[21]
	data2[23] = data[8]
	data2[21] = data[10]
	data2[8] = data[4]
	data2[10] = data[6]
	data2[4] = data[0]
	data2[6] = data[2]
	if check(data2):
		print('YES')
		exit(0)
	data2 = data.copy()
	data2[4] = data[16]
	data2[5] = data[17]
	data2[16] = data[20]
	data2[17] = data[21]
	data2[20] = data[12]
	data2[21] = data[13]
	data2[12] = data[4]
	data2[13] = data[5]
	if check(data2):
		print('YES')
		exit(0)
	data2 = data.copy()
	data2[4] = data[12]
	data2[5] = data[13]
	data2[12] = data[20]
	data2[13] = data[21]
	data2[20] = data[16]
	data2[21] = data[17]
	data2[16] = data[4]
	data2[17] = data[5]
	if check(data2):
		print('YES')
		exit(0)
print('NO')


def same(i, j, k, l):
	return c[i] == c[j] == c[k] == c[l]
check = [[9, 11, 6, 8, 22, 24, 10, 12, 1, 3, 21, 23, 5, 7, 2, 4, 13, 14, 16, 15, 17, 19, 20, 18], [1, 3, 6, 8, 5, 7, 10, 12, 9, 11, 21, 23, 22, 24, 2, 4, 13, 14, 16, 15, 17, 19, 20, 18], [13, 14, 7, 8, 5, 6, 19, 20, 17, 18, 23, 24, 21, 22, 15, 16, 1, 2, 3, 4, 9, 10, 11, 12], [17, 18, 7, 8, 21, 22, 19, 20, 13, 14, 23, 24, 5, 6, 15, 16, 1, 2, 3, 4, 9, 10, 11, 12], [1, 2, 14, 16, 9, 10, 13, 15, 11, 12, 17, 19, 3, 4, 18, 20, 5, 6, 7, 8, 21, 22, 23, 24], [11, 12, 14, 16, 3, 4, 13, 15, 1, 2, 17, 19, 9, 10, 18, 20, 5, 6, 7, 8, 21, 22, 23, 24]]
c = [0] + list(map(int, input().split()))
for L in check:
	if all((same(*L[i:i + 4]) for i in range(0, 24, 4))):
		print('YES')
		break
else:
	print('NO')


def full(x):
	if x.count(x[0]) == 4:
		return True
	else:
		return False

def gor(x):
	if x[0] == x[1] and x[2] == x[3] and (x[0] != x[2]):
		return True
	else:
		return False

def vert(x):
	if x[0] == x[2] and x[1] == x[3] and (x[0] != x[1]):
		return True
	else:
		return False
l = list(map(int, input().split()))
a = l[:4]
b = l[4:8]
c = l[8:12]
d = l[12:16]
e = l[16:20]
f = l[20:24]
if full(a) and full(c) and gor(d) and gor(b) and gor(e) and gor(f) and (d[0] == b[3] and b[0] == e[3] and (e[0] == f[3]) and (f[0] == d[3]) or (d[0] == f[3] and b[0] == d[3] and (e[0] == b[3]) and (f[0] == e[3]))):
	print('YES')
elif full(d) and full(e) and vert(a) and vert(b) and vert(c) and vert(f) and (a[0] == b[3] and b[0] == c[3] and (c[0] == f[0]) and (f[3] == a[3]) or (a[0] == f[0] and b[0] == a[3] and (c[0] == b[3]) and (f[3] == c[3]))):
	print('YES')
elif full(b) and full(f) and vert(d) and gor(a) and vert(e) and gor(c) and (d[0] == a[3] and a[0] == e[0] and (e[3] == c[0]) and (c[3] == d[3]) or (d[0] == c[0] and c[3] == e[0] and (e[3] == a[3]) and (a[0] == d[3]))):
	print('YES')
else:
	print('NO')


import math, copy
from collections import defaultdict, Counter
from itertools import permutations

def fact(n):
	return 1 if n == 1 or n == 0 else n * fact(n - 1)

def prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def inp():
	l = list(map(int, input().split()))
	return l

def one(l, i, s):
	a = False
	b = False
	for ii in range(i - 1, -1, -1):
		if l[ii] == 0 and s[ii] == 0:
			a = ii
			break
	for ii in range(i + 1, len(l)):
		if l[ii] == 0 and s[ii] == 0:
			b = ii
			break
	if a == False:
		return b
	elif b == False:
		return a
	elif abs(a - i) > abs(b - i):
		return b
	else:
		return a

def main():
	l = inp()
	p = [0] * 25
	for i in range(1, 25):
		p[i] = l[i - 1]
	if p[17] == p[18] == p[19] == p[20] and p[13] == p[14] == p[15] == p[16] and (p[1] == p[2] == p[3] == p[4]) and (p[9] == p[10] == p[11] == p[12]) and (p[5] == p[6] == p[7] == p[8]) and (p[21] == p[22] == p[23] == p[24]):
		print('NO')
	elif p[17] == p[18] == p[19] == p[20] and p[13] == p[14] == p[15] == p[16]:
		if p[5] == p[7] == p[10] == p[12] and p[9] == p[11] == p[21] == p[23] and (p[2] == p[4] == p[22] == p[24]) and (p[1] == p[3] == p[6] == p[8]):
			print('YES')
		elif p[5] == p[7] == p[2] == p[4] and p[9] == p[11] == p[6] == p[8] and (p[12] == p[10] == p[22] == p[24]) and (p[1] == p[3] == p[21] == p[23]):
			print('YES')
		else:
			print('NO')
	elif p[1] == p[2] == p[3] == p[4] and p[9] == p[10] == p[11] == p[12]:
		if p[5] == p[6] == p[19] == p[20] and p[7] == p[8] == p[13] == p[14] and (p[17] == p[18] == p[23] == p[24]) and (p[21] == p[22] == p[16] == p[15]):
			print('YES')
		elif p[5] == p[6] == p[15] == p[16] and p[17] == p[18] == p[7] == p[8] and (p[19] == p[20] == p[22] == p[21]) and (p[14] == p[13] == p[24] == p[23]):
			print('YES')
		else:
			print('NO')
	elif p[5] == p[6] == p[7] == p[8] and p[21] == p[22] == p[23] == p[24]:
		if p[19] == p[17] == p[1] == p[2] and p[9] == p[10] == p[18] == p[20] and (p[11] == p[12] == p[14] == p[16]) and (p[13] == p[15] == p[3] == p[4]):
			print('YES')
		elif p[18] == p[20] == p[3] == p[4] and p[17] == p[19] == p[11] == p[12] and (p[13] == p[15] == p[9] == p[10]) and (p[1] == p[2] == p[14] == p[16]):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
import os, sys
from io import BytesIO, IOBase
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')
main()

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)


def f(i):
	nonlocal cube
	return cube[i - 1]
cube = input().split()
if f(1) == f(2) and f(1) == f(3) and (f(1) == f(4)):
	if f(9) == f(10) and f(9) == f(11) and (f(9) == f(12)):
		if f(5) == f(6) and f(5) == f(15) and (f(5) == f(16)):
			if f(13) == f(14) and f(13) == f(23) and (f(13) == f(24)):
				if f(7) == f(8) and f(7) == f(17) and (f(7) == f(18)):
					if f(21) == f(22) and f(21) == f(19) and (f(21) == f(20)):
						print('YES')
						return
		if f(13) == f(14) and f(13) == f(7) and (f(13) == f(8)):
			if f(5) == f(6) and f(5) == f(19) and (f(5) == f(20)):
				if f(17) == f(18) and f(17) == f(23) and (f(17) == f(24)):
					if f(21) == f(22) and f(21) == f(15) and (f(21) == f(16)):
						print('YES')
						return
if f(17) == f(18) and f(17) == f(19) and (f(17) == f(20)):
	if f(13) == f(14) and f(13) == f(15) and (f(13) == f(16)):
		if f(24) == f(22) and f(24) == f(10) and (f(24) == f(12)):
			if f(1) == f(3) and f(1) == f(23) and (f(1) == f(21)):
				if f(5) == f(7) and f(5) == f(2) and (f(5) == f(4)):
					if f(9) == f(11) and f(9) == f(6) and (f(9) == f(8)):
						print('YES')
						return
		if f(24) == f(22) and f(24) == f(2) and (f(24) == f(4)):
			if f(1) == f(3) and f(1) == f(6) and (f(1) == f(8)):
				if f(5) == f(7) and f(5) == f(10) and (f(5) == f(12)):
					if f(9) == f(11) and f(9) == f(23) and (f(9) == f(21)):
						print('YES')
						return
if f(5) == f(6) and f(5) == f(7) and (f(5) == f(8)):
	if f(21) == f(22) and f(21) == f(23) and (f(21) == f(24)):
		if f(3) == f(4) and f(17) == f(19) and (f(10) == f(9)) and (f(16) == f(14)):
			if f(1) == f(2) and f(18) == f(20) and (f(12) == f(11)) and (f(15) == f(13)):
				if f(3) == f(18) and f(17) == f(12) and (f(10) == f(15)) and (f(16) == f(1)):
					print('YES')
					return
				if f(3) == f(15) and f(17) == f(1) and (f(10) == f(18)) and (f(16) == f(12)):
					print('YES')
					return
print('NO')


moves = [[(1, 24), (3, 22), (5, 1), (7, 3), (9, 5), (11, 7), (24, 9), (22, 11), (14, 13), (13, 15), (15, 16), (16, 13)], [(14, 4), (16, 3), (9, 14), (10, 16), (19, 9), (17, 10), (3, 17), (4, 19), (5, 6), (6, 8), (8, 7), (7, 5)], [(5, 13), (6, 14), (17, 5), (18, 6), (21, 17), (22, 18), (14, 22), (13, 21), (1, 2), (2, 4), (4, 3), (3, 1)]]
moves_len = len(moves)
for i in range(moves_len):
	moves.append([])
	for t in range(len(moves[i])):
		moves[-1].append((moves[i][t][1], moves[i][t][0]))
colors = input().split()

def is_solved(col):
	for s in range(6):
		for i in range(s * 4 + 1, s * 4 + 4):
			if col[i] != col[s * 4]:
				return False
	return True

def check_move(col, move):
	col_temp = colors[:]
	for t in move:
		col_temp[t[1] - 1] = colors[t[0] - 1]
	return is_solved(col_temp)
solved = False
for m in moves:
	solved = check_move(colors, m)
	if solved:
		break
print('YES' if solved else 'NO')


import sys
rotations = [[1, 3, 5, 7, 9, 11, 22, 24], [2, 4, 6, 8, 10, 12, 21, 23], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [3, 4, 17, 19, 10, 9, 16, 14], [1, 2, 18, 20, 12, 11, 15, 13]]

def rotation_backwards(cube: list, rotation: list):
	aux = cube.copy()
	aux_1 = aux[rotation[len(rotation) - 1] - 1]
	aux_2 = aux[rotation[len(rotation) - 1] - 1]
	for index in range(len(rotation) - 1, -1, -1):
		aux[rotation[index] - 1] = aux[rotation[(index - 2) % len(rotation)] - 1]
	aux[rotation[0] - 1] = aux_1
	aux[rotation[1] - 1] = aux_2
	return aux

def rotation_forwards(cube: list, rotation: list):
	aux = cube.copy()
	aux_1 = aux[rotation[0] - 1]
	aux_2 = aux[rotation[1] - 1]
	for index in range(len(rotation)):
		aux[rotation[index] - 1] = aux[rotation[(index + 2) % len(rotation)] - 1]
	aux[rotation[len(rotation) - 1] - 1] = aux_1
	aux[rotation[len(rotation) - 1] - 1] = aux_2
	return aux

def verify(cube: list):
	equals = 0
	for i in range(0, len(cube), 4):
		if cube[i] == cube[i + 1] and cube[i] == cube[i + 2] and (cube[i] == cube[i + 3]):
			equals += 1
		else:
			break
	if equals == 6:
		print('YES')
		sys.exit(0)
cube = list(map(int, input().split(' ')))
for r in rotations:
	verify(rotation_backwards(cube, r))
	verify(rotation_forwards(cube, r))
print('NO')


take = list(map(int, input().split()))
big = []
big.append([2, 4, 6, 8, 10, 12, 23, 21])
big.append([1, 3, 5, 7, 9, 11, 24, 22])
big.append([15, 16, 7, 8, 19, 20, 23, 24])
big.append([13, 14, 5, 6, 17, 18, 21, 22])
big.append([3, 4, 17, 19, 10, 9, 16, 14])
big.append([1, 2, 18, 20, 12, 11, 15, 13])
for i in big:
	(temp1, temp2) = (take[:], take[:])
	for j in range(0, 8):
		temp1[i[j] - 1] = take[i[(j + 2) % 8] - 1]
		temp2[i[j] - 1] = take[i[(j + 2) % 8] - 1]
	(k, l) = (0, 0)
	while k <= 21:
		if temp1[k] == temp1[k + 1] == temp1[k + 2] == temp1[k + 3]:
			l += 1
		k += 4
	if l == 6:
		print('YES')
		exit()
print('NO')


line = input().split()
a = []
for i in line:
	a.append(int(i))

def isValid(b):
	flag = 0
	if b[flag] != b[flag + 1] or b[flag + 1] != b[flag + 2] or b[flag + 2] != b[flag + 3]:
		return False
	flag = 4
	if b[flag] != b[flag + 1] or b[flag + 1] != b[flag + 2] or b[flag + 2] != b[flag + 3]:
		return False
	flag = 8
	if b[flag] != b[flag + 1] or b[flag + 1] != b[flag + 2] or b[flag + 2] != b[flag + 3]:
		return False
	flag = 12
	if b[flag] != b[flag + 1] or b[flag + 1] != b[flag + 2] or b[flag + 2] != b[flag + 3]:
		return False
	flag = 16
	if b[flag] != b[flag + 1] or b[flag + 1] != b[flag + 2] or b[flag + 2] != b[flag + 3]:
		return False
	flag = 20
	if b[flag] != b[flag + 1] or b[flag + 1] != b[flag + 2] or b[flag + 2] != b[flag + 3]:
		return False
	return True

def rotate():
	q = []
	for i in a:
		q.append(i)
	(q[4], q[6], q[8], q[10], q[21], q[23], q[0], q[2]) = (q[0], q[2], q[4], q[6], q[8], q[10], q[21], q[23])
	if isValid(q):
		return True
	q.clear()
	for i in a:
		q.append(i)
	(q[0], q[2], q[4], q[6], q[8], q[10], q[21], q[23]) = (q[4], q[6], q[8], q[10], q[21], q[23], q[0], q[2])
	if isValid(q):
		return True
	q.clear()
	for i in a:
		q.append(i)
	(q[12], q[13], q[4], q[5], q[16], q[17], q[20], q[21]) = (q[20], q[21], q[12], q[13], q[4], q[5], q[16], q[17])
	if isValid(q):
		return True
	q.clear()
	for i in a:
		q.append(i)
	(q[20], q[21], q[12], q[13], q[4], q[5], q[16], q[17]) = (q[12], q[13], q[4], q[5], q[16], q[17], q[20], q[21])
	if isValid(q):
		return True
	q.clear()
	for i in a:
		q.append(i)
	(q[15], q[13], q[2], q[3], q[16], q[18], q[9], q[8]) = (q[2], q[3], q[16], q[18], q[9], q[8], q[15], q[13])
	if isValid(q):
		return True
	q.clear()
	for i in a:
		q.append(i)
	(q[2], q[3], q[16], q[18], q[9], q[8], q[15], q[13]) = (q[15], q[13], q[2], q[3], q[16], q[18], q[9], q[8])
	if isValid(q):
		return True
	return False
if rotate():
	print('YES')
else:
	print('NO')


def f(a, b, c, d):
	return a == b == c == d
a = [0]
a.extend(list(map(int, input().split())))
if f(a[13], a[14], a[15], a[16]) and f(a[17], a[18], a[19], a[20]):
	if f(a[6], a[8], a[1], a[3]) and f(a[2], a[4], a[22], a[24]):
		if f(a[21], a[23], a[9], a[11]) and f(a[10], a[12], a[5], a[7]):
			print('YES')
			exit()
	if f(a[6], a[8], a[9], a[11]) and f(a[10], a[12], a[22], a[24]):
		if f(a[21], a[23], a[1], a[3]) and f(a[2], a[4], a[5], a[7]):
			print('YES')
			exit()
if f(a[5], a[6], a[7], a[8]) and f(a[21], a[22], a[23], a[24]):
	if f(a[17], a[19], a[1], a[2]) and f(a[3], a[4], a[13], a[15]):
		if f(a[14], a[16], a[11], a[12]) and f(a[9], a[10], a[18], a[20]):
			print('YES')
			exit()
	if f(a[18], a[20], a[3], a[4]) and f(a[1], a[2], a[14], a[16]):
		if f(a[13], a[15], a[9], a[10]) and f(a[11], a[12], a[17], a[19]):
			print('YES')
			exit()
if f(a[9], a[10], a[11], a[12]) and f(a[1], a[2], a[3], a[4]):
	if f(a[13], a[14], a[7], a[8]) and f(a[5], a[6], a[19], a[20]):
		if f(a[17], a[18], a[23], a[24]) and f(a[21], a[22], a[15], a[16]):
			print('YES')
			exit()
	if f(a[15], a[16], a[5], a[6]) and f(a[7], a[8], a[17], a[18]):
		if f(a[19], a[20], a[21], a[22]) and f(a[23], a[24], a[13], a[14]):
			print('YES')
			exit()
print('NO')


arr = list(map(int, input().split()))

def cycle(p, q, r, s, b):
	if b:
		(arr[p], arr[q], arr[r], arr[s]) = (arr[q], arr[r], arr[s], arr[p])
	else:
		(arr[s], arr[r], arr[q], arr[p]) = (arr[r], arr[q], arr[p], arr[s])

def solved():
	for i in range(6):
		for j in range(1, 4):
			if arr[4 * i + j] != arr[4 * i]:
				return False
	return True

def rotate(k, b):
	cycle(4 * k, 4 * k + 1, 4 * k + 3, 4 * k + 2, b)
	if k == 0:
		cycle(21, 17, 5, 13, b)
		cycle(12, 20, 16, 4, b)
	elif k == 1:
		cycle(2, 16, 9, 15, b)
		cycle(3, 18, 8, 13, b)
	elif k == 2:
		cycle(6, 18, 22, 14, b)
		cycle(7, 19, 23, 15, b)
	elif k == 3:
		cycle(0, 4, 8, 23, b)
		cycle(2, 6, 10, 21, b)
	elif k == 4:
		cycle(3, 20, 11, 7, b)
		cycle(1, 22, 9, 5, b)
	elif k == 5:
		cycle(1, 12, 10, 19, b)
		cycle(0, 14, 11, 17, b)
for i in range(6):
	for j in range(2):
		rotate(i, j)
		if solved():
			print('YES')
			exit()
		rotate(i, 1 - j)
print('NO')


def R(b):
	c = []
	for i in b:
		c.append(i)
	c[1] = b[5]
	c[3] = b[7]
	c[5] = b[9]
	c[7] = b[11]
	c[9] = b[22]
	c[11] = b[20]
	c[22] = b[1]
	c[20] = b[3]
	d = []
	for i in range(23):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	if len(d) == 6:
		return True
	else:
		return False

def Rp(b):
	c = []
	for i in b:
		c.append(i)
	c[5] = b[1]
	c[7] = b[3]
	c[9] = b[5]
	c[11] = b[7]
	c[22] = b[9]
	c[20] = b[11]
	c[1] = b[22]
	c[3] = b[20]
	d = []
	for i in range(23):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	if len(d) == 6:
		return True
	else:
		return False

def U(b):
	c = []
	for i in b:
		c.append(i)
	c[4] = b[16]
	c[5] = b[17]
	c[16] = b[20]
	c[17] = b[21]
	c[20] = b[12]
	c[21] = b[13]
	c[12] = b[4]
	c[13] = b[5]
	d = []
	for i in range(23):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	if len(d) == 6:
		return True
	else:
		return False

def Up(b):
	c = []
	for i in b:
		c.append(i)
	c[16] = b[4]
	c[17] = b[5]
	c[20] = b[16]
	c[21] = b[17]
	c[12] = b[20]
	c[13] = b[21]
	c[4] = b[12]
	c[5] = b[13]
	d = []
	for i in range(23):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	if len(d) == 6:
		return True
	else:
		return False

def F(b):
	c = []
	for i in b:
		c.append(i)
	c[13] = b[3]
	c[15] = b[2]
	c[8] = b[13]
	c[9] = b[15]
	c[18] = b[8]
	c[16] = b[9]
	c[3] = b[18]
	c[2] = b[16]
	d = []
	for i in range(23):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	if len(d) == 6:
		return True
	else:
		return False

def Fp(b):
	c = []
	for i in b:
		c.append(i)
	c[3] = b[13]
	c[2] = b[15]
	c[13] = b[8]
	c[15] = b[9]
	c[8] = b[18]
	c[9] = b[16]
	c[18] = b[3]
	c[16] = b[2]
	d = []
	for i in range(23):
		if c[i] != c[i + 1]:
			d.append(c[i])
	d.append(c[-1])
	if len(d) == 6:
		return True
	else:
		return False
a = list(map(int, input().split()))
if R(a) or Rp(a) or Up(a) or U(a) or F(a) or Fp(a):
	print('yes')
else:
	print('no')


from sys import stdin
s = list(map(int, stdin.readline().strip().split()))
l1 = [s[0], s[2], s[4], s[6], s[8], s[10], s[-3], s[-1]]
l2 = [s[1], s[3], s[5], s[7], s[9], s[11], s[-4], s[-2]]
l3 = [s[12], s[13], s[4], s[5], s[16], s[17], s[20], s[21]]
l4 = [s[14], s[15], s[6], s[7], s[18], s[19], s[22], s[23]]
l5 = [s[0], s[1], s[17], s[19], s[11], s[10], s[14], s[12]]
l6 = [s[2], s[3], s[16], s[18], s[9], s[8], s[15], s[13]]
t1 = True
t12 = True
t2 = False
t32 = True
t3 = True
t4 = False
t5 = True
t52 = True
t6 = False
for i in range(2, 8 + 2):
	if l1[i % 8] != l2[i - 2]:
		t1 = False
for i in range(6, 8 + 6):
	if l1[i % 8] != l2[i - 6]:
		t12 = False
if l3[0] == l4[0] and l3[1] == l4[1] and (l3[0] == l3[1]) and (l3[4] == l4[4]) and (l3[5] == l4[5]) and (l3[4] == l3[5]):
	t2 = True
for i in range(2, 8 + 2):
	if l3[i % 8] != l4[i - 2]:
		t3 = False
for i in range(6, 8 + 6):
	if l3[i % 8] != l4[i - 6]:
		t32 = False
if l1[0] == l2[0] and l1[1] == l2[1] and (l1[0] == l1[1]) and (l1[4] == l2[4]) and (l1[5] == l2[5]) and (l1[4] == l1[5]):
	t4 = True
for i in range(2, 8 + 2):
	if l5[i % 8] != l6[i - 2]:
		t5 = False
for i in range(6, 8 + 6):
	if l5[i % 8] != l6[i - 6]:
		t52 = False
if l1[2] == l2[2] and l1[3] == l2[3] and (l1[2] == l1[3]) and (l1[6] == l2[6]) and (l1[7] == l2[7]) and (l1[6] == l1[7]):
	t6 = True
t3 = t3 or t32
t1 = t1 or t12
t5 = t5 or t52
if t1 and t2 or (t3 and t4) or (t5 and t6):
	print('YES')
else:
	print('NO')


faces = [[5, 6, 17, 18, 21, 22, 13, 14], [7, 8, 19, 20, 23, 24, 15, 16], [1, 3, 5, 7, 9, 11, 24, 22], [2, 4, 6, 8, 10, 12, 23, 21], [3, 4, 17, 19, 10, 9, 16, 14], [1, 2, 18, 20, 12, 11, 15, 13]]
cube = input().split(' ')

def legit(cube):
	for i in range(6):
		for j in range(4):
			if cube[4 * i] != cube[4 * i + j]:
				return False
	return True
t = False
for rotato in faces:
	cubea = cube.copy()
	for i in range(8):
		cubea[rotato[i] - 1] = cube[rotato[(i + 2) % 8] - 1]
	cubeb = cubea.copy()
	for i in range(8):
		cubeb[rotato[i] - 1] = cubea[rotato[(i + 2) % 8] - 1]
	cubec = cubeb.copy()
	for i in range(8):
		cubec[rotato[i] - 1] = cubeb[rotato[(i + 2) % 8] - 1]
	if legit(cubea) or legit(cubec):
		t = True
if not t:
	print('NO')
else:
	print('YES')


import sys

def check(h):
	for i in range(1, 7):
		if h[4 * i - 1] == h[4 * i - 2] == h[4 * i - 3] == h[4 * i - 4]:
			c = 1
		else:
			return False
	return True
a = list(map(int, input().split()))
h = [i for i in a]
t = h[20]
w = h[22]
h[20] = h[3]
h[22] = h[1]
p = t
k = w
t = h[9]
w = h[11]
h[9] = p
h[11] = k
p = t
k = w
t = h[5]
w = h[7]
h[5] = p
h[7] = k
p = t
k = w
h[1] = p
h[3] = k
p = t
k = w
if check(h):
	print('YES')
	sys.exit()
h = [i for i in a]
t = h[1]
w = h[3]
h[1] = h[22]
h[3] = h[20]
p = t
k = w
t = h[5]
w = h[7]
h[5] = p
h[7] = k
p = t
k = w
t = h[9]
w = h[11]
h[9] = p
h[11] = k
p = t
k = w
h[22] = p
h[20] = k
p = t
k = w
if check(h):
	print('YES')
	sys.exit()
h = [i for i in a]
t = h[12]
w = h[13]
h[12] = h[20]
h[13] = h[21]
p = t
k = w
t = h[4]
w = h[5]
h[4] = p
h[5] = k
p = t
k = w
t = h[16]
w = h[17]
h[16] = p
h[17] = k
p = t
k = w
h[20] = p
h[21] = k
p = t
k = w
if check(h):
	print('YES')
	sys.exit()
h = [i for i in a]
t = h[14]
w = h[15]
h[14] = h[22]
h[15] = h[23]
p = t
k = w
t = h[6]
w = h[7]
h[6] = p
h[7] = k
p = t
k = w
t = h[18]
w = h[19]
h[18] = p
h[19] = k
p = t
k = w
h[22] = p
h[23] = k
p = t
k = w
if check(h):
	print('YES')
	sys.exit()
h = [i for i in a]
t = h[2]
w = h[3]
h[2] = h[15]
h[3] = h[13]
p = t
k = w
t = h[16]
w = h[18]
h[16] = p
h[18] = k
p = t
k = w
t = h[8]
w = h[9]
h[8] = k
h[9] = p
p = t
k = w
h[13] = p
h[15] = k
p = t
k = w
if check(h):
	print('YES')
	sys.exit()
h = [i for i in a]
t = h[2]
w = h[3]
h[2] = h[16]
h[3] = h[18]
p = t
k = w
t = h[13]
w = h[15]
h[13] = k
h[15] = p
p = t
k = w
t = h[8]
w = h[9]
h[8] = p
h[9] = k
p = t
k = w
h[16] = k
h[18] = p
p = t
k = w
if check(h):
	print('YES')
	sys.exit()
print('NO')


a = list(map(int, input().split()))
trans = [{1: 5, 3: 7, 5: 9, 7: 11, 9: 22, 11: 24, 22: 1, 24: 3}, {5: 17, 6: 18, 17: 21, 18: 22, 21: 13, 22: 14, 13: 5, 14: 6}, {3: 17, 4: 19, 17: 10, 19: 9, 9: 14, 10: 16, 14: 4, 16: 3}]

def check(c):
	for i in range(6):
		if len(set((c[i * 4 + j] for j in range(4)))) != 1:
			return False
	return True

def rotate(b, s, t):
	c = b[:]
	for (i, j) in zip(s, t):
		c[i - 1] = b[j - 1]
	return c
for k in trans:
	if check(rotate(a, *zip(*k.items()))):
		print('YES')
		exit()
	if check(rotate(a, *list(zip(*k.items()))[::-1])):
		print('YES')
		exit()
print('NO')