Problem:
Dice III Write a program which reads the two dices constructed in the same way as Dice I , and determines whether these two dices are identical. You can roll a dice in the same way as Dice I , and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical. Input In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels. Output Print " Yes " if two dices are identical, otherwise " No " in a line. Constraints  $0 \leq $ the integer assigned to a face $ \leq 100$  Sample Input 1 1 2 3 4 5 6
6 2 4 3 5 1 Sample Output 1 Yes Sample Input 2 1 2 3 4 5 6
6 5 4 3 2 1 Sample Output 2 No

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 1], [0, 2, 1, 0], [2, 1, 0, 0], [1, 0, 2, 0], [2, 0, 1, 1], [1, 2, 0, 1]]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
            break
        if x[j] == y[z[i][j]]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
    else:
        if 2 in order or z[i][3] == sum(order) % 2:
            print('Yes')
            break
else:
    print('No')

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 1], [0, 2, 1, 0], [2, 1, 0, 0], [1, 0, 2, 0], [2, 0, 1, 1], [1, 2, 0, 1]]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
            break
        if x[j] == y[z[i][j]]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
    else:
        if 2 in order or z[i][3] == sum(order) % 2:
            print('Yes')
            break
else:
    print('No')

Solution (Python):
class Dice:
    def __init__(self,t,f,r,l,ba,bo):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.ba = ba
        self.bo = bo
    
    def E(self):
        a = self.t
        b = self.r
        c = self.bo
        d = self.l
        self.r = a
        self.bo = b
        self.l = c
        self.t = d
    
    def N(self):
        a = self.t
        b = self.ba
        c = self.bo
        d = self.f
        self.ba = a
        self.bo = b
        self.f = c
        self.t = d
    
    def S(self):
        a = self.t
        b = self.ba
        c = self.bo
        d = self.f
        self.f = a
        self.t = b
        self.ba = c
        self.bo = d
    
    def W(self):
        a = self.t
        b = self.r
        c = self.bo
        d = self.l
        self.l = a
        self.t = b
        self.r = c
        self.bo = d

s = input().split(" ")
dice1 = Dice(s[0],s[1],s[2],s[3],s[4],s[5])
s = input().split(" ")
dice2 = Dice(s[0],s[1],s[2],s[3],s[4],s[5])

if dice1.t == dice2.f:
    dice2.N()
elif dice1.t == dice2.r:
    dice2.W()
elif dice1.t == dice2.l:
    dice2.E()
elif dice1.t == dice2.ba:
    dice2.S()
elif dice1.t == dice2.bo:
    dice2.E()
    dice2.E()
if dice1.bo != dice2.bo:
    dice2.N()
    for i in range(4):
        if dice1.t == dice2.t and dice1.bo == dice2.bo:
            break
        dice2.E()
for i in range(4):
    if dice1.t == dice2.t and dice1.f == dice2.f and dice1.r == dice2.r and dice1.l == dice2.l and dice1.ba == dice2.ba and dice1.bo == dice2.bo:
        print("Yes")
        break
    dice2.N()
    dice2.E()
    dice2.S()
    if i == 3:
        print("No")

Solution (Python):
class Dice:
    def __init__(self):
        self.dice = [
                    [0, 1, 2, 3, 4, 5],
                    [0, 2, 4, 1, 3, 5],
                    [0, 4, 3, 2, 1, 5],
                    [0, 3, 1, 4, 2, 5],
                    [1, 5, 2, 3, 0, 4],
                    [1, 2, 0, 5, 3, 4],
                    [1, 0, 3, 2, 5, 4],
                    [1, 3, 5, 0, 2, 4],
                    [2, 1, 5, 0, 4, 3],
                    [2, 5, 4, 1, 0, 3],
                    [2, 4, 0, 5, 1, 3],
                    [2, 0, 1, 4, 5, 3],
                    [3, 1, 0, 5, 4, 2],
                    [3, 0, 4, 1, 5, 2],
                    [3, 4, 5, 0, 1, 2],
                    [3, 5, 1, 4, 0, 2],
                    [4, 0, 2, 3, 5, 1],
                    [4, 2, 5, 0, 3, 1],
                    [4, 5, 3, 2, 0, 1],
                    [4, 3, 0, 5, 2, 1],
                    [5, 1, 3, 2, 4, 0],
                    [5, 2, 1, 4, 3, 0],
                    [5, 4, 2, 3, 1, 0],
                    [5, 3, 4, 1, 2, 0]]

    def math(self, dice_p1, dice_p2):
        dice_t = []
        same = "No"
        for dice_p in self.dice:
            for i in range(6):
                dice_t.append(dice_p1[dice_p[i]])
            if dice_t == dice_p2:
                same = "Yes"
            dice_t = []
        return same

d = Dice()
dice_p1 = [int(dice_p1) for dice_p1 in input().split()]
dice_p2 = [int(dice_p2) for dice_p2 in input().split()]
print(d.math(dice_p1, dice_p2))

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 0], [0, 2, 1, 1], [2, 1, 0, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0]]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if x[j] == y[z[i][j]] and x[-j-1] == y[-z[i][j]-1]:
            pass
        elif x[j] == y[-z[i][j]-1] and x[-j-1] == y[z[i][j]]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
        else:
            break
    else:
        if 2 in order or z[i][3] == sum(order) % 2:
            print('Yes')
            break
else:
    print('No')

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = z[-1:] + z[:-1]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = z[-1:] + z[:-1]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = [z[2], z[0], z[1]]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

Solution (Python):
x = input().split()
y = input().split()
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = [z[2], z[0], z[1]]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

Solution (Python):
x = input().split()
y = input().split()
a = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        k = a[j]
        if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
            break
        if x[j] == y[k]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    a = [a[2], a[0], a[1]]
    if i == 2:
        a = [a[0], a[2], a[1]]
else:
    print('No')

Solution (Python):
class Dice:
    same_dice_index = ('123456', '135246', '142536', '154326',
                       '214365', '231645', '246135', '263415',
                       '312564', '326154', '351624', '365214',
                       '415263', '421653', '456123', '462513',
                       '513462', '536142', '541632', '564312',
                       '624351', '632541', '645231', '653421')
 
    def __init__(self, num_list):
        self.faces = num_list
 
    def is_same(self, dice):
        for i in Dice.same_dice_index:
            example_faces = []
            for j in i:
                example_faces.append(self.faces[int(j) - 1])
            if example_faces == dice.faces:
                return 'Yes'
        return 'No'
 
num_list1 = list(map(int, input().split()))
num_list2 = list(map(int, input().split()))
 
dice1 = Dice(num_list1)
dice2 = Dice(num_list2)
 
ans = dice1.is_same(dice2)
 
print(ans)

Solution (Python):
import sys
x1=[int(i)for i in input().split()]
x2=[int(i)for i in input().split()]
for i in range(6):
    if x2[i]==x1[0]:
        count=i
        if x2[5-i]==x1[5]:
            break
if x2[count]==x1[0] and x2[5-count]==x1[5]:
    if count==0 or count==5:
        if count==5:
            for i in range(2):
                x2[1],x2[0]=x2[0],x2[1]
                x2[5],x2[1]=x2[1],x2[5]
                x2[4],x2[5]=x2[5],x2[4]
    else:
        if count==1 or count==4:
            while x1[0]!=x2[0] or x1[5]!=x2[5]:
                x2[1],x2[0]=x2[0],x2[1]
                x2[5],x2[1]=x2[1],x2[5]
                x2[4],x2[5]=x2[5],x2[4]
        else:
            while x1[0]!=x2[0] or x1[5]!=x2[5]:
                x2[3],x2[0]=x2[0],x2[3]
                x2[5],x2[3]=x2[3],x2[5]
                x2[2],x2[5]=x2[5],x2[2]
    for i in range(4):
        if x2[2]==x1[2] and x2[3]==x1[3] and x2[4]==x1[4] and x2[1]==x1[1] :
            print('Yes')
            break
        else:
            x2[1],x2[2]=x2[2],x2[1]
            x2[2],x2[4]=x2[4],x2[2]
            x2[4],x2[3]=x2[3],x2[4]
        if i==3:
            print('No')
else:
    print("No")

Solution (Python):
store=[]
str=["N","S","E","W"]
rep={
 "N":[4,0,2,3,5,1],
 "S":[1,5,2,3,0,4],
 "E":[2,1,5,0,4,3],
 "W":[3,1,0,5,4,2]}

def rotate_dice(b,s):
 result = [0]*6
 for i in range(6):result[i]=b[rep[s][i]]
 return result
     
def check(a,b):
 if not b in store:
  store.append(b)
  for s in str:
   check(a,rotate_dice(b,s))
 
a=input().split()
b=input().split()
r=check(a,b)
if a in store:
 print("Yes")
else:
 print("No")

Solution (Python):
store=[]
str=["N","S","E","W"]
rep={
 "N":[4,0,2,3,5,1],
 "S":[1,5,2,3,0,4],
 "E":[2,1,5,0,4,3],
 "W":[3,1,0,5,4,2]}
 
def rotate_dice(b,s):
 result = [0]*6
 for i in range(6):
  result[i]=b[rep[s][i]]
 return result
      
def check(a,b):
 if not b in store:
  store.append(b)
  for s in str:
   check(a,rotate_dice(b,s))
  
a=input().split()
b=input().split()
r=check(a,b)
if a in store:
 print("Yes")
else:
 print("No")

Solution (Python):


"""
???????????? 3

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""

class Dice:
    T = 0
    S = 1
    E = 2
    W = 3
    N = 4
    B = 5

    """ ????????????????????? """
    def __init__(self): 
        self.side = [1, 2, 3, 4, 5, 6]
        self.top = 0

    def setDice(self, arr):  
        self.side = arr[0:6]

    def Turn(self, dir): 
        s = self.side

        if dir == "N":     
            
            t = [s[Dice.S],s[Dice.B],s[Dice.E],s[Dice.W],s[Dice.T],s[Dice.N]]
        elif dir == "S": 
            t = [s[Dice.N],s[Dice.T],s[Dice.E],s[Dice.W],s[Dice.B],s[Dice.S]]
        elif dir == "E": 
            t = [s[Dice.W],s[Dice.S],s[Dice.T],s[Dice.B],s[Dice.N],s[Dice.E]]
        elif dir == "W": 
            t = [s[Dice.E],s[Dice.S],s[Dice.B],s[Dice.T],s[Dice.N],s[Dice.W]]
        elif dir == "L": 
            t = [s[Dice.T],s[Dice.W],s[Dice.S],s[Dice.N],s[Dice.E],s[Dice.B]]
        elif dir == "R": 
            t = [s[Dice.T],s[Dice.E],s[Dice.N],s[Dice.S],s[Dice.W],s[Dice.B]]

        self.side = t


    def Search(self, tval, sval, dir): 

    
        if self.side[Dice.E] == tval:
            self.Turn("W")
        elif self.side[Dice.W] == tval:
            self.Turn("E")
        elif self.side[Dice.N] == tval:
            self.Turn("S")
        elif self.side[Dice.S] == tval:
            self.Turn("N")
        elif self.side[Dice.B] == tval:
            self.Turn("N")
            self.Turn("N")

        for i in range(3): 
            if self.side[Dice.S] == sval:
                break
            self.Turn("L")
            
        return self.side[dir]


d1num = list(map(int,input().strip().split()))
d2num = list(map(int,input().strip().split()))
d1 = Dice()
d1.setDice(d1num)
d2 = Dice()
d2.setDice(d2num)
v1 = d1.Search(d1.side[Dice.T], d1.side[Dice.S], Dice.E)
v2 = d2.Search(d1.side[Dice.T], d1.side[Dice.S], Dice.E)
if v1 == v2:
    print("Yes")
else:
    print("No")

Solution (Python):
class dice:
	def __init__(self,data):
		self.faces = data
	
	def turn(self,direction):
		if direction == 'N':
			idx = [1,5,2,3,0,4]
			self.faces = [self.faces[i] for i in idx]
		elif direction == 'S':
			[self.turn('N') for i in range(3)]
		elif direction == 'E':
			idx = [3,1,0,5,4,2]
			self.faces = [self.faces[i] for i in idx]
		elif direction == 'W':
			[self.turn('E') for i in range(3)]
		elif direction == 'c':
			self.turn('N')
			self.turn('W')
			self.turn('S')

if __name__ == '__main__':
	data1 = [int(i) for i in input().split()]
	data2 = [int(i) for i in input().split()]
	d1 = dice(data1)
	d2 = dice(data2)
	
	for o in 'cccWcccEcccNcccWcccWccc':
		if d1.faces == d2.faces:
			break
		else:
			d2.turn(o)
	if d1.faces == d2.faces:
		print('Yes')
	else:
		print('No')

Solution (Python):
class Dice:
    __slots__ = ['n_list', 'pair_list']

    def __init__(self, n_tup):
        self.n_list = list(n_tup)
        self.pair_list = [self.return_dice_round_pair(self.n_list, 2, 3, 5, 4),
                          self.return_dice_round_pair(self.n_list, 1, 4, 6, 3),
                          self.return_dice_round_pair(self.n_list, 1, 2, 6, 5),
                          self.return_dice_round_pair(self.n_list, 1, 5, 6, 2),
                          self.return_dice_round_pair(self.n_list, 1, 3, 6, 4),
                          self.return_dice_round_pair(self.n_list, 2, 4, 5, 3)
                          ]

    @staticmethod
    def roll_switch(n_list, from_idx_list, to_idx_list):
        n_list[from_idx_list[0] - 1], \
        n_list[from_idx_list[1] - 1], \
        n_list[from_idx_list[2] - 1], \
        n_list[from_idx_list[3] - 1] \
            = n_list[to_idx_list[0] - 1], \
              n_list[to_idx_list[1] - 1], \
              n_list[to_idx_list[2] - 1], \
              n_list[to_idx_list[3] - 1]
        return n_list

    def roll(self, direction):
        if direction == "N":
            self.n_list = self.roll_switch(self.n_list, [1, 2, 6, 5], [2, 6, 5, 1])

        elif direction == "E":
            self.n_list = self.roll_switch(self.n_list, [1, 3, 6, 4], [4, 1, 3, 6])

        if direction == "S":
            self.n_list = self.roll_switch(self.n_list, [1, 2, 6, 5], [5, 1, 2, 6])

        if direction == "W":
            self.n_list = self.roll_switch(self.n_list, [1, 3, 6, 4], [3, 6, 4, 1])

    def spin(self):
        self.n_list = self.roll_switch(self.n_list, [2, 3, 5, 4], [3, 5, 4, 2])

    @staticmethod
    def return_dice_round_pair(n_list, a, b, c, d):
        return [(n_list[a - 1], n_list[b - 1]),
                (n_list[b - 1], n_list[c - 1]),
                (n_list[c - 1], n_list[d - 1]),
                (n_list[d - 1], n_list[a - 1])]

    def return_right_num(self, top, forward):
        for i in range(6):
            if (top, forward) in self.pair_list[i]:
                return self.n_list[i]


def comparison_dice(dice_src, dice_tmp):
    
    def compare_back(dice_tmp, dice_src):
        if dice_tmp.n_list[5] != dice_src.n_list[5]:
            return False
        else:
            if compare_with_spin(dice_tmp, dice_src):
                return True
            else:
                return False

    def compare_with_spin(dice_tmp, dice_src):
        
        for k in range(4):
            dice_tmp.spin()
            if dice_tmp.n_list == dice_src.n_list:
                print("Yes")
                return True
        else:
            return False

    
    for i in range(4):
        dice_tmp.roll("W")
        if dice_tmp.n_list[0] == dice_src.n_list[0]:
            if compare_back(dice_tmp, dice_src):
                break
    else:
        for j in range(4):
            dice_tmp.roll("N")
            if dice_tmp.n_list[0] == dice_src.n_list[0]:
                if compare_back(dice_tmp, dice_src):
                    break
        else:
            print("No")

dice_src = Dice([int(x) for x in input().split()])
dice_tmp = Dice([int(x) for x in input().split()])
comparison_dice(dice_src, dice_tmp)

Solution (Python):
def roll(die, d):
    if d == "E":
        return [die[3], die[1], die[0], die[5], die[4], die[2]]
    if d == "N":
        return [die[1], die[5], die[2], die[3], die[0], die[4]]
    if d == "S":
        return [die[4], die[0], die[2], die[3], die[5], die[1]]
    if d == "W":
        return [die[2], die[1], die[5], die[0], die[4], die[3]]
    if d == "L":
        return [die[0], die[3], die[1], die[4], die[2], die[5]]
    if d == "R":
        return [die[0], die[2], die[4], die[1], die[3], die[5]]

def checkdice(die1, die2):
    ans = "No"
    for d in "RRRNRRRNRRRSRRRSRRRNRRRR":
        if die1 == die2:
            ans = "Yes"
            break
        die2 = roll(die2, d)
    return ans

die1 = list(map(int, input().split()))
die2 = list(map(int, input().split()))
print(checkdice(die1, die2))

Solution (Python):

def r(D,s):
    if s==0:
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif s==2:
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif s==3:
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif s==1:
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t
    elif s==4:
        D=r(r(D,1),1)
    return D
def ch(C,D):
    k=0
    while k<6 and C[k]==D[k]:
        k+=1
    if k==6:
        return 1
    else:
        return 0
C=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
nd=0
if ch(C,D)==1:
    nd=1
i=0
while i<4 and nd==0:
    D=r(D,i)
    j=i+1
    j%=4
    k=0
    if ch(C,D)==1:
        nd=1
 
    
    while k<3 and nd==0:
        D=r(D,j)
        if ch(C,D)==1:
            nd=1
        k+=1
  
        
    D=r(D,j)
 
   
    m=i+2
    m%=4
 
    
    D=r(D,m)
 
 
    i+=1
i=0
while nd==0 and i<4:
    D=r(D,0)
    D=r(D,1)
    D=r(D,0)
    if ch(C,D)==1:
        nd=1
    D=r(r(D,0),0)
    if ch(C,D)==1:
        nd=1
    i+=1
if nd==1:
    p="Yes"
else:
    p="No"
print(p)

Solution (Python):
ans=chk=0
a=[0,2,5,3]
b=[0,1,5,4]
c=[1,2,4,3]

def sortdice(dice1,dice2,p,q,r):
    for i in range(4):
        dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
        for j in range(4):
            dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
            for k in range(4):
                dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
                if dice1==dice2:
                    print 'Yes'
                    exit()
    return 0
 
l1=map(int,raw_input().split())
l2=map(int,raw_input().split())
sortdice(l1,l2,a,b,c)
print 'No'

Solution (Python):
class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east
        
dice1 = Dice(list(map(int,input().split())))
dice2 = Dice(list(map(int,input().split())))

h=""

for i in range(4):
    dice2.rotate_west()
    if dice1.top == dice2.top:
        for _ in range(4):
            dice2.rotate_horizon()
            if dice1.south == dice2.south:
                if dice1.east == dice2.east and dice1.west == dice2.west:
                    h = "Yes"
for _ in range(4):
    dice2.rotate_north()
    if dice1.top == dice2.top:
        for m in range(4):
            dice2.rotate_horizon()
            if dice1.south == dice2.south:
                if dice1.east == dice2.east and dice1.west == dice2.west:
                    h = "Yes"
if h:
    print(h)
else:
    print("No")

Solution (Python):
class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east
        
dice1 = Dice(list(map(int,input().split())))
dice2 = Dice(list(map(int,input().split())))

h=""

for i in range(4):
    dice2.rotate_west()
    if dice1.top == dice2.top:
        for _ in range(4):
            dice2.rotate_horizon()
            if dice1.south == dice2.south:
                if dice1.east == dice2.east and dice1.west == dice2.west:
                    h = "Yes"
for _ in range(4):
    dice2.rotate_north()
    if dice1.top == dice2.top:
        for m in range(4):
            dice2.rotate_horizon()
            if dice1.south == dice2.south:
                if dice1.east == dice2.east and dice1.west == dice2.west:
                    h = "Yes"
if h:
    print(h)
else:
    print("No")

Solution (Python):
def North(dice):
    w = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = w
    return dice
def East(dice):
    w = dice[1]
    dice[1] = dice[2]
    dice[2] = dice[4]
    dice[4] = dice[3]
    dice[3] = w
    return dice

def West(dice):
    w = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = w
    return dice

maxloop = 4
Ncnt = 0
Ecnt = 0
Wcnt = 0

Dice1 = input().split()
Dice2 = input().split()

Flag = False
Nloop = True
Eloop = True
Wloop = True

while Eloop:
    while Nloop:
        while Wloop:
            if Dice1 == Dice2:
                Flag = True
                Nloop = False
                Eloop = False
                Wloop = False
                break
            Dice1 = West(Dice1)
            Wcnt += 1
            if Wcnt == maxloop:
                Wloop = False
        Dice1 = North(Dice1)
        Wcnt = 0
        Wloop = True
        Ncnt += 1
        if Ncnt == maxloop:
            Nloop = False
    Dice1 = East(Dice1)
    Ncnt = 0
    Nloop = True
    Ecnt += 1
    if Ecnt == maxloop:
        Eloop = False

if Flag == True:
    print("Yes")
else:
    print("No")

Solution (Python):
class Checker:
    d = {
        1: { 2: (3,4,5,6), 3: (5,2,4,6), 4: (2,5,3,6), 5: (4,3,2,6) },
        2: { 1: (4,3,6,5), 3: (1,6,4,5), 4: (6,1,3,5), 6: (3,4,1,5) },
        3: { 1: (2,5,6,4), 2: (6,1,5,4), 5: (1,6,2,4), 6: (5,2,1,4) },
        4: { 1: (5,2,6,3), 2: (1,6,5,3), 5: (6,1,2,3), 6: (2,5,1,3) },
        5: { 1: (3,4,6,2), 3: (6,1,4,2), 4: (1,6,3,2), 6: (4,3,1,2) },
        6: { 2: (4,3,5,1), 3: (2,5,4,1), 4: (5,2,3,1), 5: (3,4,2,1) }
        }

    def __init__(self, s):
        l = s.split()
        self.tbl = dict(zip(l, range(1,7)))
        self.pip = dict(zip(range(1,7), l))

    def __call__(self, s):
        l = s.split()
        if self.tbl[l[1]] in self.d[self.tbl[l[0]]]:
            for i,j in zip(self.d[self.tbl[l[0]]][self.tbl[l[1]]], range(2,6)):
                if self.pip[i] != l[j]:
                    return "No"
            return "Yes"
        else:
            return "No"

c = Checker(input())
print(c(input()))

Solution (Python):
class Dice3():

    def __init__(self, v): 
        self.view = v
        self.dTFRstr = {}
        for i, j, k in ((ii, (ii++2)%6, (ii+4)%6) for ii in  range(6)):
            self.dTFRstr[self.view[i]]=''.join([self.view[v] for v in (j, k, 5-j, 5-k, j)])


d3, d = Dice3(input().split()), input().split()
if ''.join(d[1:3]) in d3.dTFRstr[d[0]] :
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice(object):
    
    def __init__(self, line):
        self.top = 1
        self.bottom = 6
        self.south = 2
        self.east = 3
        self.west = 4
        self.north = 5
        self.convert = [int(s) for s in line.split()]
    
    def move(self, direction):
        if 'N' == direction:
            self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
        elif 'S' == direction:
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif 'W' == direction:
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif 'E' == direction:
            self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
    
    def rv(self, key):
        index_list = {
            'top' : self.top,
            'bottom' : self.bottom,
            'south' : self.south,
            'east' : self.east,
            'west' : self.west,
            'notrh' : self.north
        }
        return self.convert[index_list[key] - 1]
    
    def search(self, dice):
        
        for direction in 'NNNNWNNNN':
            self.move(direction)
            if self.rv('south') == dice.rv('south'):
                break
        
        if self.rv('south') != dice.rv('south') or self.rv('notrh') != dice.rv('notrh'):
            return 'No'            
        
        for direction in 'WWWW':
            self.move(direction)
            if self.rv('top') == dice.rv('top'):
                break
        
        if self.rv('top') != dice.rv('top'):
            return 'No'
        if self.rv('bottom') != dice.rv('bottom'):
            return 'No'
        if self.rv('east') != dice.rv('east'):
            return 'No'
        if self.rv('notrh') != dice.rv('notrh'):
            return 'No'
        
        return 'Yes'
    
dice = Dice(input())
dice2 = Dice(input())
print(dice.search(dice2))

Solution (Python):
class Dice:
    def __init__(self, faces = None):
        self.dice = {'N':2, 'E':4, 'S':5, 'W':3}
        self.faces = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6}
        self.currTop = 1
        if faces is not None:
            self.faces = faces

    def top(self):
        return self.currTop

    def topFace(self):
        return self.faces[self.currTop]

    def bottom(self):
        return 7 - self.currTop

    def bottomFace(self):
        return self.faces[self.bottom()]

    def rot(self, direction):
        newTop = self.dice[direction]
        currTop = self.currTop
        self.currTop = newTop
        if direction == 'N':
            self.dice['N'] = 7 - currTop
            self.dice['S'] = currTop
        elif direction == 'S':
            self.dice['N'] = currTop
            self.dice['S'] = 7 - currTop
        elif direction == 'E':
            self.dice['E'] = 7 - currTop
            self.dice['W'] = currTop
        elif direction == 'W':
            self.dice['E'] = currTop
            self.dice['W'] = 7 - currTop

    def yaw(self, direction):
        newDice = {}
        if direction == 'E':
            newDice['N'] = self.dice['E']
            newDice['E'] = self.dice['S']
            newDice['S'] = self.dice['W']
            newDice['W'] = self.dice['N']
        if direction == 'W':
            newDice['N'] = self.dice['W']
            newDice['E'] = self.dice['N']
            newDice['S'] = self.dice['E']
            newDice['W'] = self.dice['S']
        self.dice = newDice

dbg = False

faces1 = {k:v for k,v in zip(range(1,7), map(int, input().split()))}
faces2 = {k:v for k,v in zip(range(1,7), map(int, input().split()))}

d1 = Dice(faces1)
d2 = Dice(faces2)

d2indexes = [d2index for d2index,d2face in d2.faces.items() if d1.topFace() == d2face]

for d2topIndex in d2indexes:
    if dbg: print('d2topIndex:%d' % (d2topIndex) )

    
    key = [k for k,v in d2.dice.items() if d2topIndex == v]
    if len(key) == 0:
        d2.rot('N')
        key = [k for k,v in d2.dice.items() if d2topIndex == v]
    d2.rot(key[0])

    if d1.topFace() != d2.topFace() or d1.bottomFace() != d2.bottomFace():
        continue

    
    cnt = 0
    while True:
        if dbg: print('cnt:%d' % (cnt) )
        if cnt > 4:
            break
        d2.yaw('E')
        cnt += 1

        
        d1State = {k:d1.faces[v] for k,v in d1.dice.items()}
        d2State = {k:d2.faces[v] for k,v in d2.dice.items()}
        if d1State == d2State:
            print('Yes')
            exit()

print('No')