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):
class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
    
    def counterclockwise(self):
        temp = self.back
        self.back = self.left
        self.left = self.front
        self.front = self.right
        self.right = temp
    
    def clockwise(self):
        temp = self.back
        self.back = self.right
        self.right = self.front
        self.front = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
    def fix_up(self, up):
        if self.down == up:
            self.north()
            self.north()
        elif self.right == up:
            self.west()
        elif self.left == up:
            self.east()
        elif self.front == up:
            self.south()
        elif self.back == up:
            self.north()

    def fix_back_with_fixed_up(self, back):
        if self.right == back:
            self.clockwise()
        elif self.left == back:
            self.counterclockwise()
        elif self.front == back:
            self.clockwise()
            self.clockwise()
            
    def equals_narrow_sense(self, dice):
        if self.up == dice.up and self.down == dice.down and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.front == dice.front:
            return True
        else:
            return False
            
            
up, back, right, left, front, down = map(int, input().split())
dice1 = Dice(up, back, right, left, front, down)

up, back, right, left, front, down = map(int, input().split())
dice2 = Dice(up, back, right, left, front, down)

equal_flag = False
for i in range(6):
    if 0 < i <= 3:
        dice1.north()
    elif i == 4:
        dice1.west()
    elif i == 5:
        dice1.east()
        dice1.east()
    
    for l in range(4):
        dice1.clockwise()
        
        for j in range(6):
            if 0 < j <= 3:
                dice2.north()
            elif j == 4:
                dice2.west()
            elif j == 5:
                dice2.east()
                dice2.east()
                
            for k in range(4):
                dice2.clockwise()

                if dice1.equals_narrow_sense(dice2):
                    equal_flag = True
                    break

        if equal_flag:
            break

if equal_flag:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys

class Dice():
    top=0
    n=1
    e=3
    w=2
    s=4
    bottom=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.bottom,self.n,self.s = self.n,5-self.n,5-self.top,self.top
        elif(direction=="E"):
            self.top,self.bottom,self.e,self.w = self.e,5-self.e,5-self.top,self.top
        elif(direction=="W"):
            self.top,self.bottom,self.e,self.w = self.w,5-self.w,self.top,5-self.top
        elif(direction=="S"):
            self.top,self.bottom,self.n,self.s = self.s,5-self.s,self.top,5-self.top

    def equal(self,another):
        if(self.dice[self.top] != another.dice[another.top]):
            return False
        if(self.dice[self.n] != another.dice[another.n]):
            return False
        if(self.dice[self.e] != another.dice[another.e]):
            return False
        if(self.dice[self.w] != another.dice[another.w]):
            return False
        if(self.dice[self.s] != another.dice[another.s]):
            return False
        if(self.dice[self.bottom] != another.dice[another.bottom]):
            return False

        return True


dicea=Dice(list(map(int,input().split())))
diceb=Dice(list(map(int,input().split())))

roll_order="NNNNWNNNWNNNENNNENNNWNNNN"
for i in range(len(roll_order)):
    if(dicea.equal(diceb)):
        print("Yes")
        sys.exit()
    else:
        diceb.roll(roll_order[i])
print("No")

Solution (Python):
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
    
    def rot(self,way):
        
        if way == 0:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c
        
        if way == 1:
            c = self.e
            self.e = self.n
            self.n = self.w
            self.w = self.s
            self.s = c
        
        if way == 2:
            c = self.w
            self.w = self.d
            self.d = self.e
            self.e = self.u
            self.u = c

u,s,e,w,n,d = map(int,input().split())
dice1 = Dice(u,s,e,w,n,d)
uu,ss,ee,ww,nn,dd = map(int,input().split())
dice2 = Dice(uu,ss,ee,ww,nn,dd)

count = 0
flag = 0
while True:
    if dice1.u == dice2.u:
        for s in range(5):
            if dice1.s == dice2.s and dice1.e == dice2.e and dice1.w == dice2.w and dice1.n == dice2.n:
                if dice1.d == dice2.d:
                    flag = 1
                    print('Yes')
                break
            else:
                dice2.rot(1)
        if not flag:
            if dice1.d == dice2.s and dice1.u == dice2.n:
                print('Yes')
                
            elif dice1.d == dice2.e and dice1.u == dice2.w:
                print('Yes')
                
            elif dice1.d == dice2.w and dice1.u == dice2.e:
                print('Yes')
                
            elif dice1.d == dice2.n and dice1.u == dice2.s:
                print('Yes')
            else:
                print('No')
        break
    elif count < 5:
        dice2.rot(0)
        count += 1
    elif count == 5:
        dice2.rot(1)
        count = 0

Solution (Python):
def roll(s, rolllist):
    news = list(s)
    for i in range(6):
        news[i] = s[rolllist[i]]
    return news


rl = {0: [0, 1, 2, 3, 4, 5],
      1: [1, 5, 2, 3, 0, 4],  
      2: [2, 1, 5, 0, 4, 3],  
      3: [3, 1, 0, 5, 4, 2],  
      4: [4, 0, 2, 3, 5, 1],  
      5: [5, 4, 2, 3, 1, 0]}
rollz = [0, 3, 1, 4, 2, 5]
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
if not (s1[0] in s2):
    print("No")
    exit()

tl = [i for i, x in enumerate(s2) if x == s1[0]]
for t in tl:
    s2 = roll(s2, rl[t])
    ss = s2
    for i in range(6):
        if s1 == ss:
            print("Yes")
            exit()
        ss = roll(ss, rollz)
print("No")

Solution (Python):
face = [0]*6
class Dice():

    def __init__(self):
        self.number = [inp[i] for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setnumbers(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def spin(self, command):
        for i in range(6):
            face[i] = self.number[i]
        if command == 'S':
            self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1])
            
        elif command == 'N':
            self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4])
            
        elif command == 'E':
            self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2])
            
        elif command == 'W':
            self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3])
            
    def equal(self, another):
        set = False
        for i in self.order:
            self.spin(i)
            FLAG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLAG = False
                    break
            if FLAG == True:
                return True
        return set
inp = list(map(int, input().split()))

dice1 = Dice()
dice2 = Dice()

dice1.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])
inp = list(map(int, input().split()))
dice2.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])
if dice1.equal(dice2):
    print('Yes')
else:
    print('No')

Solution (Python):
f = list(map(int, input().split()))
s = list(map(int, input().split()))
yes = 0

for _ in range(4):
    s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]
    for _ in range(4):
        s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
        if f == s:
            yes = 1

for _ in range(4):
    s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]
    for _ in range(4):
        s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
        if f == s:
            yes = 1

if yes == 1:
    print('Yes')
else:
    print('No')

Solution (Python):
import random

class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

    def top(self):
        return self.face[0]

dice1 = Dice()
dice2 = Dice()
dice1.setface(list(map(int,input().split())))
dice2.setface(list(map(int,input().split())))

for i in range(10000):
    dice2.roll(['E','N','S','W'][random.randint(0,3)])
    for j in range(6):
        if dice1.face[j]!=dice2.face[j]:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Solution (Python):
class dice:
    def __init__(self, f):
        assert(len(f) == 6)
        self.face = f
        self.N = [1, 5, 2, 3, 0, 4]
        self.S = [4, 0, 2, 3, 5, 1]
        self.E = [3, 1, 0, 5, 4, 2]
        self.W = [2, 1, 5, 0, 4, 3]
        self.R = [0, 2, 4, 1, 3, 5]

    def rotate(self, dir):
        rot = self.__getattribute__(dir)
        old = self.face
        new = [-1 for _ in range(6)]
        for i in range(6):
            new[i] = old[rot[i]]
        self.face = new

    def __eq__(self, E):
        D = self
        for _ in range(4):
            
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('N')
        for _ in range(4):
            
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('E')
        return False

A = dice(list(map(int, input().split())))
B = dice(list(map(int, input().split())))
print('Yes' if A == B else 'No')

Solution (Python):
diceA = list(map(int, input().split()))

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

diceB2 = [diceB1[0],diceB1[1],diceB1[2],diceB1[4],diceB1[3],diceB1[5]]

diceC = [[1,2,3,5,4,2,3,5,6],[2,1,4,6,3,1,4,6,5],[3,1,2,6,5,1,2,6,4],[4,1,5,6,2,1,5,6,3],[5,1,3,6,4,1,3,6,2],[6,2,4,5,3,2,4,5,1]]

for i in range(6):
  if diceB2[0] == diceA[i]:
    for j in range(1,5):
      if diceB2[1] == diceA[diceC[i][j]-1]:
        for k in range(1,4):
          if diceB2[1+k] == diceA[diceC[i][j+k]-1]:
            m = "Yes"
          else:
            m = "No"
            break
        if m == "Yes":
          if diceB2[5] == diceA[diceC[i][8]-1]:
            m = "Yes"

print(m)

Solution (Python):

class Dice():

    def __init__(self, d):
        self.d = d
        self.north = [2, 6, 3, 4, 1, 5]
        self.south = [5, 1, 3, 4, 6, 2]
        self.east = [4, 2, 1, 6, 5, 3]
        self.west = [3, 2, 6, 1, 5, 4]
        self.label = [(self.d[0], self.d[1], self.d[2])]

    def roll(self, direction):
        if direction == 'S':
            self.d = [ self.d[self.south[i]-1] for i in range(6) ]
        elif direction == 'N':
            self.d = [ self.d[self.north[i]-1] for i in range(6) ]
        elif direction == 'E':
            self.d = [ self.d[self.east[i]-1] for i in range(6) ]
        elif direction == 'W':
            self.d = [ self.d[self.west[i]-1] for i in range(6) ]

    def rollAll(self):
        for i in range(4):
            for i in range(4):
                self.roll('E')
                self.label.append((self.d[0], self.d[1], self.d[2]))
            self.roll('S')
        self.roll('E')
        self.roll('S')
        for i in range(4):
            self.roll('E')
            self.label.append((self.d[0], self.d[1], self.d[2]))
        self.roll('S')
        self.roll('S')
        for i in range(4):
            self.roll('E')
            self.label.append((self.d[0], self.d[1], self.d[2]))

    def getLabel(self):
        return set(self.label)

    def getDice(self):
        return self.d

s1= [ int(s) for s in input().split() ]
s2= [ int(s) for s in input().split() ]
dice1 = Dice(s1)
dice2 = Dice(s2)
dice1.rollAll()
dice2.rollAll()

l = dice1.getLabel()
l2 = dice2.getLabel()
if l == l2:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys


class Dice:
    def __init__(self, top, bottom, front, rear, right, left):
        self.top = top
        self.front = front
        self.right = right
        self.bottom = bottom
        self.rear = rear
        self.left = left

    def rotate_front(self):
        t, b, f, r = self.top, self.bottom, self.front, self.rear
        self.top = r
        self.bottom = f
        self.front = t
        self.rear = b

    def rotate_rear(self):
        t, b, f, r = self.top, self.bottom, self.front, self.rear
        self.top = f
        self.bottom = r
        self.front = b
        self.rear = t

    def rotate_right(self):
        t, b, r, l = self.top, self.bottom, self.right, self.left
        self.top = l
        self.bottom = r
        self.right = t
        self.left = b

    def rotate_left(self):
        t, b, r, l = self.top, self.bottom, self.right, self.left
        self.top = r
        self.bottom = l
        self.right = b
        self.left = t

    def get_tfr(self):
        return [self.top, self.front, self.right]

    def get_all(self):
        return (self.top, self.bottom, self.front, self.rear, self.right, self.left)

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    top, front, right, left, rear, bottom = map(int, input().split())
    top2, front2, right2, left2, rear2, bottom2 = map(int, input().split())
    d = Dice(top, bottom, front, rear, right, left)
    states = set()

    states.add(d.get_all())
    for _ in range(3):
        d.rotate_right()
        states.add(d.get_all())
    d.rotate_front()
    d.rotate_front()
    states.add(d.get_all())
    for _ in range(3):
        d.rotate_right()
        states.add(d.get_all())

    d.rotate_front()
    states.add(d.get_all())
    for _ in range(3):
        d.rotate_right()
        states.add(d.get_all())
    d.rotate_front()
    d.rotate_front()
    states.add(d.get_all())
    for _ in range(3):
        d.rotate_right()
        states.add(d.get_all())

    d.rotate_right()
    d.rotate_front()
    states.add(d.get_all())
    for _ in range(3):
        d.rotate_right()
        states.add(d.get_all())
    d.rotate_front()
    d.rotate_front()
    states.add(d.get_all())
    for _ in range(3):
        d.rotate_right()
        states.add(d.get_all())
    

    if (top2, bottom2, front2, rear2, right2, left2) in states:
        print("Yes")
    else:
        print("No")

main()

Solution (Python):
dice1 = list(map(int, input().split()))
dice2 = list(map(int, input().split()))

flag = False


for _ in range(4):
    temp = dice2[0]
    dice2[0] = dice2[2]
    dice2[2] = dice2[5]
    dice2[5] = dice2[3]
    dice2[3] = temp
    
    for _ in range(4):
        temp = dice2[1]
        dice2[1] = dice2[2]
        dice2[2] = dice2[4]
        dice2[4] = dice2[3]
        dice2[3] = temp
        
        if dice2 == dice1:
            flag = True
            

for _ in range(4):
    temp = dice2[0]
    dice2[0] = dice2[1]
    dice2[1] = dice2[5]
    dice2[5] = dice2[4]
    dice2[4] = temp
    
    for _ in range(4):
        temp = dice2[1]
        dice2[1] = dice2[2]
        dice2[2] = dice2[4]
        dice2[4] = dice2[3]
        dice2[3] = temp
        
        if dice2 == dice1:
            flag = True
            
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
dice1=list(map(int,input().split()))
dice2=list(map(int,input().split()))

def E(ls):
    ls=[ls[3],ls[1],ls[0],ls[5],ls[4],ls[2]]
    return ls

def N(ls):
    ls=[ls[1],ls[5],ls[2],ls[3],ls[0],ls[4]]
    return ls

def R(ls):
    ls=[ls[0],ls[2],ls[4],ls[1],ls[3],ls[5]]
    return ls
    
dice1_ls=[dice1,]

for i in range(3):
    dice1=E(dice1)
    dice1_ls.append(dice1)
dice1=E(dice1)
dice1=N(dice1)
dice1_ls.append(dice1)
dice1=N(N(dice1))
dice1_ls.append(dice1)
for i in range(6):
    dice=dice1_ls[i]
    for j in range(3):
        dice=R(dice)
        dice1_ls.append(dice)
if dice2 in dice1_ls:
    print('Yes')
else:
    print('No')

Solution (Python):
def rotate(arr,i):
    if i=='W':
        arr=[arr[k-1] for k in [3,2,6,1,5,4]]
    if i=='E':
        arr=[arr[k-1] for k in [4,2,1,6,5,3]]
    if i=='N':
        arr=[arr[k-1] for k in [2,6,3,4,1,5]]
    if i=='S':
        arr=[arr[k-1] for k in [5,1,3,4,6,2]]
    return arr
arr=input().split()
deck=[]
for i in 'W'*4:
    arr=rotate(arr,i)
    for k in 'NNNN':
        arr=rotate(arr,k)
        deck.append(arr)
arr=rotate(arr,'N')
arr=rotate(arr,'W')
for k in 'NNNN':
    arr=rotate(arr,k)
    deck.append(arr)
arr=rotate(arr,'W')
arr=rotate(arr,'W')
for k in 'NNNN':
    arr=rotate(arr,k)
    deck.append(arr)
arr2=input().split()
if arr2 in deck:
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    
    def __init__(self, U, S, E, W, N, D):
        self.u, self.d = U, D
        self.e, self.w = E, W
        self.s, self.n = S, N       
    
    def roll(self, command):
        if command == 'E':
            self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
        elif command == 'W':
            self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
        elif command == 'S':
            self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
        else:
            self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n


    def __eq__(self, other):

        other_hex = [other.u, other.s, other.e, other.w, other.n, other.d]
        self_hex = [self.u, self.s, self.e, self.w, self.n, self.d]
        if sorted(other_hex) != sorted(self_hex):
            print('No')
            return
        for i in 'NNNNENNNENNNWNNNWNNNENNN':
            self.roll(i)
            if other.u == self.u and other.s == self.s and other.e == self.e \
            and other.w == self.w and other.n == self.n and other.d == self.d:
                   print('Yes')
                   break
        else:
            print('No')

                


U, S, E, W, N, D = [int(i) for i in input().split()]
dice1 = Dice(U, S, E, W, N, D)
U, S, E, W, N, D = [int(i) for i in input().split()]
dice2 = Dice(U, S, E, W, N, D)
dice1 == dice2

Solution (Python):
class Dice:
    def __init__(self, label):
        self.label = label.copy()
    
    def rotateS(self):
        """[1, 2, 6, 5] -> [5, 1, 2, 6]"""
        t = self.label[1]
        self.label[1] = self.label[5]
        self.label[5] = self.label[6]
        self.label[6] = self.label[2]
        self.label[2] = t

    def rotateN(self):
        t = self.label[1]
        self.label[1] = self.label[2]
        self.label[2] = self.label[6]
        self.label[6] = self.label[5]
        self.label[5] = t
    
    def rotateW(self):
        t = self.label[1]
        self.label[1] = self.label[3]
        self.label[3] = self.label[6]
        self.label[6] = self.label[4]
        self.label[4] = t
    
    def rotateE(self):
        t = self.label[1]
        self.label[1] = self.label[4]
        self.label[4] = self.label[6]
        self.label[6] = self.label[3]
        self.label[3] = t

    def rotateR(self):
        t = self.label[3]
        self.label[3] = self.label[2]
        self.label[2] = self.label[4]
        self.label[4] = self.label[5]
        self.label[5] = t

    def rotateL(self):
        t = self.label[3]
        self.label[3] = self.label[5]
        self.label[5] = self.label[4]
        self.label[4] = self.label[2]
        self.label[2] = t

def debugprint(dice1, dice2, label=''):
    debug=False
    if (debug):
        print(label)
        print('dice1: {}'.format(dice1.label))
        print('dice2: {}'.format(dice2.label))
        print('')

def compare(dice1, dice2):
    if (dice1.label == dice2.label):
        return True
    else:
        return False

def verify(dice1, dice2):
    dice_t = Dice(dice2.label)
    numS = 0
    for i in range(0,4):
        numR = 0
        for _ in range(0,4):
            debugprint(dice1, dice_t)
            if (compare(dice1, dice_t)):
                return True
            dice_t.rotateR()
            numR += 1
        
        dice_t.rotateS()
        numS += 1
    

    dice_t.rotateE()
    for _ in range(0,4):
        debugprint(dice1, dice_t)
        if (compare(dice1, dice_t)):
            return True
        dice_t.rotateR()

    dice_t.rotateE()
    dice_t.rotateE()
    for _ in range(0,4):
        debugprint(dice1, dice_t)
        if (compare(dice1, dice_t)):
            return True
        dice_t.rotateR()

    return False




label1 = []
label1.append(-1)
label1[1:] = map(int,input().split())
dice1 = Dice(label1)


label2 = []
label2.append(-1)
label2[1:] = map(int,input().split())
dice2 = Dice(label2)


debugprint(dice1, dice2, 'before rotate')

label1.sort()
label2.sort()
if (label1 != label2):
    print("No")
    exit()

if (verify(dice1, dice2)):
    print('Yes')
else:
    print('No')

Solution (Python):
D = [
    (1, 5, 2, 3, 0, 4), 
    (3, 1, 0, 5, 4, 2), 
    (4, 0, 2, 3, 5, 1), 
    (2, 1, 5, 0, 4, 3), 
]

*L1, = map(int, input().split())
*L2, = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)*3
ok = 0
for k in p:
    if L1 == L2:
        ok = 1
    L2[:] = [L2[e] for e in D[k]]

print("Yes" if ok else "No")

Solution (Python):
import random

class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if way==0:
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c

flag=0
lst=["W","S","E","N"]
u,s,e,w,n,d=map(int,input().split())
dice_1=Dice(u,w,s,e,n,d)
u,s,e,w,n,d=map(int,input().split())
dice_2=Dice(u,w,s,e,n,d)
for i in range(1000):
    if dice_1.u==dice_2.u and dice_1.w==dice_2.w and dice_1.s==dice_2.s and dice_1.e==dice_2.e and dice_1.n==dice_2.n and dice_1.d==dice_2.d:
        flag=1
    dice_1.rot(random.choice(lst))
if flag==1:
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move(self, direction):
        if direction == "N":
            self.move_N()
        elif direction == "E":
            self.move_E()
        elif direction == "S":
            self.move_S()
        elif direction == "W":
            self.move_W()
        elif direction == "SIDE":
            self.move_SIDE()
        else:
            raise Exception
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    def move_SIDE(self):
        tmp = self.FRONT
        self.FRONT = self.RIGHT
        self.RIGHT = self.BACK
        self.BACK = self.LEFT
        self.LEFT = tmp

def is_same():
    for _ in range(4):
        dice.move("SIDE")
        for _ in range(4):
            dice.move("N")
            if dice.TOP == dice2.TOP and dice.FRONT == dice2.FRONT \
                and dice.RIGHT == dice2.RIGHT and dice.LEFT == dice2.LEFT \
                and dice.BACK == dice2.BACK and dice.BOTTOM == dice2.BOTTOM:
                return True
        for _ in range(4):
            dice.move("E")
            if dice.TOP == dice2.TOP and dice.FRONT == dice2.FRONT \
                and dice.RIGHT == dice2.RIGHT and dice.LEFT == dice2.LEFT \
                and dice.BACK == dice2.BACK and dice.BOTTOM == dice2.BOTTOM:
                return True
    return False
    
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
top2, front2, right2, left2, back2, bottom2 = map(int,input().split())
dice2 = Dice(top2, front2, right2, left2, back2, bottom2)

if is_same():
    
    
    print("Yes")
else:
    
    
    print("No")

Solution (Python):
class Dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
dice1 = Dice()
table1 = list(map(int,input().split()))
dice1.setNumber(table1[0], table1[1], table1[2], table1[3], table1[4], table1[5])
dice2 = Dice()
table2 = list(map(int,input().split()))
dice2.setNumber(table2[0], table2[1], table2[2], table2[3], table2[4], table2[5])
for loc in "NNNNWNNNWNNNENNNENNNWNNN":
  dice2.roll(loc)
  if dice2.number==dice1.number:
    print("Yes")
    exit()
print("No")

Solution (Python):
class dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def setnum(self,s):
        self.number = s

    def kai(self,h):
        tmp = self.number
        if h == 'E':
            self.number = [tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        elif h == 'S':
            self.number = [tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
        elif h == 'W':
            self.number = [tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        elif h == 'N':
            self.number = [tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]

    def Qright(self,up,flont,num):
        uf = (up,flont)
        if uf == (num[1],num[2]) or uf ==(num[2],num[4]) or uf ==(num[4],num[3]) or uf ==(num[3],num[1]):
            ans = num[0]
        elif uf == (num[0],num[3]) or uf ==(num[3],num[5]) or uf ==(num[5],num[2]) or uf ==(num[2],num[0]):
            ans = num[1]
        elif uf == (num[0],num[1]) or uf ==(num[1],num[5]) or uf ==(num[5],num[4]) or uf ==(num[4],num[0]):
            ans = num[2]
        elif uf == (num[0],num[4]) or uf ==(num[4],num[5]) or uf ==(num[5],num[1]) or uf ==(num[1],num[0]):
            ans = num[3]
        elif uf == (num[0],num[2]) or uf ==(num[2],num[5]) or uf ==(num[5],num[3]) or uf ==(num[3],num[0]):
            ans = num[4]
        elif uf == (num[1],num[3]) or uf ==(num[3],num[4]) or uf ==(num[4],num[2]) or uf ==(num[2],num[1]):
            ans = num[5]
        print(ans)




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

testall = 'NNNNENNNNENNNNENNNNENWNNNNEENNNN'

num2 = list(map(int,input().split()))
dice = dice()
dice.setnum(num)
for i in range(len(testall)):


    dice.kai(testall[i])
    if dice.number == num2:
        print("Yes")
        break
    if i == len(testall)-1:
        print("No")