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.

Difficulty: MEDIUM

Solutions:
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')


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


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


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


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


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


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


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