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

Starter code:

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


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



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


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


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

import itertools, sys
id = '''
  12
  34
ef56ijmn
gh78klop
  9a
  bc
'''

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('rotate', rev, t)
        print('YES')
        return

print('NO')


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






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)


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

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

c = [0] + list(map(int, input().split()))
ans = False
if c[1] == c[2] == c[17] == c[19] and \
    c[18] == c[20] == c[9] == c[10] and \
    c[11] == c[12] == c[14] == c[16] and \
    c[13] == c[15] == c[3] == c[4] and \
    c[21] == c[22] == c[23] == c[24] and \
    c[5] == c[6] == c[7] == c[8]:
    ans = True
elif c[1] == c[2] == c[14] == c[16] and \
    c[18] == c[20] == c[3] == c[4] and \
    c[11] == c[12] == c[17] == c[19] and \
    c[13] == c[15] == c[9] == c[10] and \
    c[21] == c[22] == c[23] == c[24] and \
    c[5] == c[6] == c[7] == c[8]:
    ans = True
elif c[21] == c[22] == c[15] == c[16] and \
    c[13] == c[14] == c[7] == c[8] and \
    c[5] == c[6] == c[19] == c[20] and \
    c[17] == c[18] == c[23] == c[24] and \
    c[1] == c[2] == c[3] == c[4] and \
    c[9] == c[10] == c[11] == c[12]:
    ans = True
elif c[21] == c[22] == c[19] == c[20] and \
    c[13] == c[14] == c[23] == c[24] and \
    c[5] == c[6] == c[15] == c[16] and \
    c[17] == c[18] == c[7] == c[8] and \
    c[1] == c[2] == c[3] == c[4] and \
    c[9] == c[10] == c[11] == c[12]:
    ans = True
elif c[21] == c[23] == c[1] == c[3] and \
    c[2] == c[4] == c[5] == c[7] and \
    c[6] == c[8] == c[9] == c[11] and \
    c[10] == c[12] == c[22] == c[24] and \
    c[13] == c[14] == c[15] == c[16] and \
    c[17] == c[18] == c[19] == c[20]:
    ans = True
elif c[21] == c[23] == c[9] == c[11] and \
    c[2] == c[4] == c[22] == c[24] and \
    c[6] == c[8] == c[1] == c[3] and \
    c[10] == c[12] == c[5] == c[7] and \
    c[13] == c[14] == c[15] == c[16] and \
    c[17] == c[18] == c[19] == c[20]:
    ans = True
print('YES' if ans else '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")
                



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

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
        else:
            if 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")


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 list(faces.keys()):
	colors = faces[face]
	if max(colors) == min(colors):
		status[face] = 'ok'
	else:
		if 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'

# print(status)
# print(faces)

if 'bad' in list(status.values()):
	print('NO')
else:
	if 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')


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')
        return
    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')
        return
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')
        return
    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')
        return
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')
        return
    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')
        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]:
			# face1 = 0
			# for j in range(6):
			# 	if j != i and j != opp[i]:
			# 		face = j
			# 		break
			# face2 = 0
			# for j in range(6):
			# 	if j != face1 and j != i and j != opp[face1] and j != opp[i]:
			# 		face2 = j
			# 		break
			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")
							return
				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")
							return
			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")
							return
				if eq(cube,2,3,17,19) and eq(cube,16,18,10,11) and eq(cube,8,9,12,14):
					print("YES")
					return
			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")
					return
				if eq(cube,4,6,9,11) and eq(cube,8,10,20,22) and eq(cube,21,23,1,3):
					print("YES")
					return

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
#hh = [ i//4 + 1 for i in range(24)]

for i in [a,b,c,d,e,f]:
    # for j,k in i:
    #     count[j] += 1
    #     count[k] += 1
    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")


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(" ")
#print(inp)
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")
        return
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')



moves = [
    [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]
    ]
data = [0]+list(map(int, input().split()))

def check(data):
    if data[1]==data[2]==data[3]==data[4] and data[5]==data[6]==data[7]==data[8] and data[9]==data[10]==data[11]==data[12] and data[13]==data[14]==data[15]==data[16] and data[17]==data[18]==data[19]==data[20] and data[21]==data[22]==data[23]==data[24]:
        return True
    else:
        return False

for row in moves:
    temp = data[:]
    for i in range(8):
        temp[row[i]]=data[row[(i+2)%8]]
    if check(temp):
        print('YES')
        break
    temp = data[:]
    for i in range(8):
        temp[row[i]]=data[row[(8+i-2)%8]]
    if check(temp):
        print('YES')
        break
else:
    print('NO')