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):
d = input().split()
a = input().split()
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]
ts = [i for i, x in enumerate(d) if x == a[0]]
fs = [i for i, x in enumerate(d) if x == a[1]]
b = 0
for t in ts:
  for f in fs:
    if t == f: continue
    r = p[t][f]
    if r == -1: continue
    l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
    if a == l: b += 1; break
print("Yes") if b > 0 else print("No")

Solution (Python):
class Dice3():
    def check(self,dice1,dice2):
        
        for i in range(4):
            dice1[0],dice1[1],dice1[5],dice1[4]=dice1[4],dice1[0],dice1[1],dice1[5]
        
            for j in range(4):
                dice1[0],dice1[2],dice1[5],dice1[3]=dice1[3],dice1[0],dice1[2],dice1[5]
        
                for k in range(4):
                    dice1[1],dice1[2],dice1[4],dice1[3]=dice1[2],dice1[4],dice1[3],dice1[1]
                    if dice1 == dice2:
                        print('Yes')
                        return 0
        return

        

dc3 = Dice3()
Dice1 = [int(i) for i in input().split()]
Dice2 = [int(i) for i in input().split()]
ck = dc3.check(Dice1,Dice2)
if ck != 0:
    print('No')

Solution (Python):
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]
 
def set_top(dice, top):
    return [dice[i] for i in mask[top]]
 
def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]
 
def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
         
dice1 = input().split()
dice2 = input().split()
 
print('Yes' if equal(dice1, dice2) else 'No')

Solution (Python):
class Dice:
    TOP, SOUTH, EAST, WEST, NORTH, BOTTOM = 0, 1, 2, 3, 4, 5
    def __init__(self, d):
        self.dice = d[:]
        self.top = d[0]
        self.south = d[1]
        self.east = d[2]
        self.west = d[3]
        self.north = d[4]
        self.bottom = d[5]

    def __eq__(self, other):
        a = self.permutations()
        a.sort()

        d2 = Dice(other.dice)
        b = d2.permutations()
        b.sort()

        return a == b

    def permutations(self):
        copy = self.dice[:]
        perm = []
        for d in [(), ("S"), ("N"), ("E"), ("W"), ("W", "W")]:
            t = Dice(copy)
            for m in d:
                t.move(m)

            perm.append(t.dice[:])
            for i in range(3):
                t.move("R")
                perm.append(t.dice[:])

        return perm
        
    def set_top_front(self, top, front):
        for i, n in enumerate(self.dice):
            if n == top:
                if i == Dice.TOP: pass
                elif i == Dice.SOUTH: self.move("N")
                elif i == Dice.EAST: self.move("W")
                elif i == Dice.WEST: self.move("E")
                elif i == Dice.NORTH: self.move("S")
                elif i == Dice.BOTTOM:
                    self.move("S")
                    self.move("S")

                break
        else:
            return False
        
        for i, n in enumerate(self.dice):
            if n == front:
                if i == Dice.TOP: return False
                elif i == Dice.SOUTH: pass
                elif i == Dice.EAST: self.move("R")
                elif i == Dice.WEST: self.move("L")
                elif i == Dice.NORTH:
                    self.move("R")
                    self.move("R")
                elif i == Dice.BOTTOM: return False

                break
        else:
            return False

        return True
        
    def move(self, d):
        if d == "N":
            self.move_north()
        elif d == "W":
            self.move_west()
        elif d == "S":
            self.move_south()
        elif d == "E":
            self.move_east()
        elif d == "R":
            self.move_right()
        elif d == "L":
            self.move_left()

        self.dice = [
            self.top,
            self.south,
            self.east,
            self.west,
            self.north,
            self.bottom,
        ]

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

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

    def move_north(self):
        self.top, self.south, self.bottom, self.north \
            = self.south, self.bottom, self.north, self.top

    def move_south(self):
        self.top, self.south, self.bottom, self.north \
            = self.north, self.top, self.south, self.bottom

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

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

if __name__ == "__main__":
    import re

    nums1 = [int(n) for n in re.split(r"\s+", input().strip())]
    dice1 = Dice(nums1)

    nums2 = [int(n) for n in re.split(r"\s+", input().strip())]
    dice2 = Dice(nums2)

    if dice1 == dice2:
        print("Yes")
    else:
        print("No")

Solution (Python):
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List
dice = list(map(int, input().split()))
D = [dice]
for i in range(0, 3):
    D.append(north(D[i]))
D.append(south(west(D[0])))
D.append(south(east(D[0])))
for i in range(6):
    for j in range(3):
        if j == 0:
            D.append(east(D[i + j]))
        else:
            D.append(east(D[5 + 3 * i + j]))

dice2 = list(map(int, input().split()))
k = 0
for i in range(len(D)):
    if dice2 == D[i]:
        print('Yes')
        k = 1
        break
if k == 0:
    print('No')

Solution (Python):



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

    def rotate(self, ope):
        if ope == 'S':
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif ope == 'N':
            self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
        elif ope == 'E':
            self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
        elif ope == 'W':
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif ope == 'R': 
            self.south, self.east, self.north, self.west = self.east, self.north, self.west, self.south
        elif ope == 'L': 
            self.south, self.east, self.north, self.west = self.west, self.north, self.east, self.south
        else:
            pass

    def get_surfaces(self):
        return [self.top, self.south, self.east, self.north, self.west, self.bottom]

dc1 = dice([int(x) for x in input().split(' ')])
dc2 = dice([int(x) for x in input().split(' ')])

judged = False
if len((dc1.get_surfaces() and dc2.get_surfaces())) == 6:
    opes = ['', 'S', 'E', 'S', 'E', 'S']
    for op in opes:
        dc2.rotate(op)
        for i in range(4):
            if dc1.get_surfaces() == dc2.get_surfaces():
                judged = True
                break
            dc2.rotate('R')
        if judged: break

if judged:
    print('Yes')
else:
    print('No')

Solution (Python):
d,e=[input().split()for _ in'12'];e[3:5]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3:5]=f[4:2:-1]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Solution (Python):
d,e=[input().split()for _ in'12'];e[3:5]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3:5]=f[4:2:-1]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Solution (Python):
import sys

class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    def west(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0]
    def north(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0]
    def south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]

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

south_cnt = 0

for i in range(8):
    for j in range(4):    
        if dice1.labels[0] == dice2.labels[0] and dice1.labels[1] == dice2.labels[1] and dice1.labels[2] == dice2.labels[2] and dice1.labels[3] == dice2.labels[3] and dice1.labels[4] == dice2.labels[4] and dice1.labels[5] == dice2.labels[5]:
            print("Yes")
            sys.exit()

        dice2.south()
        dice2.east()
        dice2.north()

    if south_cnt == 4:
        dice2.east()
    else:
        dice2.south()
        south_cnt += 1
    
print("No")

Solution (Python):



class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def __eq__(self, other):
        return self.upper == other.upper and self.backward == other.backward and self.right == other.right and self.left == other.left and self.ahead == other.ahead and self.bottom == other.bottom

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper

    def roll_side(self):
        self.ahead, self.right, self.backward, self.left = self.left, self.ahead, self.right, self.backward


def match_dice(dice1, dice2):
    for i in range(4):
        dice1.roll_north()

        for j in range(4):
            dice1.roll_east()

            for k in range(4):
                dice1.roll_side()

                if dice2 == dice1:
                    return 0
    return 1


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

if result is 0:
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[t,f,r,l,b,u]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d):
        self.a=[self.a[i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice1=Dice(t,f,r,l,b,u)
t,f,r,l,b,u=map(int,input().split())
dice2=Dice(t,f,r,l,b,u)
s='SSSWEEE'
w='YYYY'
ans='No'
for j in s:
    for r in w:
        if dice1.a==dice2.a:
            ans='Yes'
            break
        dice2.roll(r)
    else:
        dice2.roll(j)
        continue
    break
print(ans)

Solution (Python):
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[t,f,r,l,b,u]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d):
        self.a=[self.a[i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice1=Dice(t,f,r,l,b,u)
t,f,r,l,b,u=map(int,input().split())
dice2=Dice(t,f,r,l,b,u)
s='SSSEWWW'
w='YYYY'
ans='No'
for j in s:
    for r in w:
        if dice1.a==dice2.a:
            ans='Yes'
            break
        dice2.roll(r)
    else:
        dice2.roll(j)
        continue
    break
print(ans)

Solution (Python):




command = " SSESS"  
check = []  
check.append([2, 3, 5, 4])
check.append([3, 5, 4, 2])
check.append([5, 4, 2 ,3])
check.append([4, 2, 3, 5])

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

class dice:
    def __init__(self):
        self.data = [0 for i in range(8)]
        a = intinput()
        for i in range(1, 7): self.data[i] = a[i - 1]  
        for i in range(6): self.data[0] += a[i]  
        self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3]  
        
        

    def d_read(self, a):
        
        b = []
        for i in range(len(a)): b.append(self.data[a[i]])
        return b

    def d_write(self, b, c):
        
        if len(b) != len(c): return     
        for i in range(len(b)): self.data[c[i]] = b[i]

    def roll(self, direction):
        
        
        if direction == ' ': return
        if direction == 'S':
            self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5])
            
        elif direction == 'N':
            self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5])
            
        elif direction == 'W':
            self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4])
            
        elif direction == 'E':
            self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4])

    def get_label(self, i):  
        return self.data[i]

    def get_index(self, n):  
        for i in range(1, 7):
            if self.data[i] == n: return i
        return -1  

def side_check(d1, d2):
    
    for i in range(4):
        j = 2
        while j < 6:
            if d2.get_label(check[0][j - 2]) != d1.get_label(check[i][j - 2]): break
            j += 1
        if j == 6: return True
    return False

def is_equal(d1, d2):
    if d1.get_label(0) != d2.get_label(0): return False
    if d1.get_label(7) != d2.get_label(7): return False
    
    for i in range(6):
        d2.roll(command[i])  
        if d2.get_label(1) != d1.get_label(1): continue
        if d2.get_label(6) != d2.get_label(6): continue
        if side_check(d1, d2): return True
    return False

def main():
    d1 = dice()
    d2 = dice()
    if is_equal(d1, d2): print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()

Solution (Python):
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.n, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top
    def rotMany(self, command):
        for dir in command:
            self.rot(dir)



li = list(map(int, input().split()))
D1 = Dice(li)
li = list(map(int, input().split()))
D2 = Dice(li)

cmd_list = [
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENE",
    "SEN", "SEN", "SEN", "SENEE",
    "SEN", "SEN", "SEN", ""
]

for cmd in cmd_list:
    if D1.top == D2.top and D1.s == D2.s and D1.w == D2.w and D1.e == D2.e and D1.n == D2.n and D1.bot == D2.bot:
        print("Yes")
        exit(0)
    else:
        D1.rotMany(cmd)
print("No")

Solution (Python):
class Dice:
    def __init__(self):
        self.side = {"top": 0, "front": 0, "right": 0, "left": 0, "back": 0, "bottom": 0}

    
    def roll(self, direction):
        self.direction = direction
        if self.direction == "N":
            w = self.side["top"]
            self.side["top"] = self.side["front"]
            self.side["front"] = self.side["bottom"]
            self.side["bottom"] = self.side["back"]
            self.side["back"] = w
        elif self.direction == "S":
            w = self.side["top"]
            self.side["top"] = self.side["back"]
            self.side["back"] = self.side["bottom"]
            self.side["bottom"] = self.side["front"]
            self.side["front"] = w
        elif self.direction == "E":
            w = self.side["top"]
            self.side["top"] = self.side["left"]
            self.side["left"] = self.side["bottom"]
            self.side["bottom"] = self.side["right"]
            self.side["right"] = w
        elif self.direction == "W":
            w = self.side["top"]
            self.side["top"] = self.side["right"]
            self.side["right"] = self.side["bottom"]
            self.side["bottom"] = self.side["left"]
            self.side["left"] = w

    
    def position_relation(self, top, front):
        
        if top == "top" and front == "front"\
        or top == "front" and front == "bottom"\
        or top == "bottom" and front == "back"\
        or top == "back" and front == "top":
            self.right = self.side["right"]
        
        if top == "top" and front == "back"\
        or top == "back" and front == "bottom"\
        or top == "bottom" and front == "front"\
        or top == "front" and front == "top":
            self.right = self.side["left"]
        
        if top == "top" and front == "right"\
        or top == "right" and front == "bottom"\
        or top == "bottom" and front == "left"\
        or top == "left" and front == "top":
            self.right = self.side["back"]
        
        if top == "top" and front == "left"\
        or top == "left" and front == "bottom"\
        or top == "bottom" and front == "right"\
        or top == "right" and front == "top":
            self.right = self.side["front"]
        
        if top == "front" and front == "right"\
        or top == "right" and front == "back"\
        or top == "back" and front == "left"\
        or top == "left" and front == "front":
            self.right = self.side["top"]
        
        if top == "front" and front == "left"\
        or top == "left" and front == "back"\
        or top == "back" and front == "right"\
        or top == "right" and front == "front":
            self.right = self.side["bottom"]


dice = Dice()
for s, n in zip(dice.side, input().split()):
    dice.side[s] = int(n)


dice2 = Dice()
for s, n in zip(dice2.side, input().split()):
    dice2.side[s] = int(n)

import random
for i in range(1000):
    dice.roll(random.choice(["N", "S", "E", "S"]))
    if dice.side == dice2.side:
        
        print("Yes")
        break
    else:
        
        continue
else:
    print("No")

Solution (Python):
import sys
  
IDX_TBL = {1:[2,3,5,4], 2:[3,1,4,6], 3:[1,2,6,5],4:[1,5,6,2], 5:[1,3,6,4], 6:[2,4,5,3]}
l1=["_"] + raw_input().split(" ")
l2=["_"] + raw_input().split(" ")
if l1[1] in l2:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]
    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])
        if nums2 in nums1*2:
            print "Yes"
            sys.exit(0)
print "No"

Solution (Python):
class Dice:
	
	def __init__(self, faces):
		self.faces = faces
		self.t = faces[0]
		self.s = faces[1]
		self.e = faces[2]
		self.w = faces[3]
		self.n = faces[4]
		self.b = faces[5]

	def roll(self, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = n_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def rotate_right(self):
		s_ = self.s
		w_ = self.w
		n_ = self.n
		e_ = self.e
		self.s = e_
		self.w = s_
		self.n = w_
		self.e = n_

	def set_top(self, face):
		if self.t == face:
			return
		elif self.s == face:
			self.roll('N')
		elif self.e == face:
			self.roll('W')
		elif self.w == face:
			self.roll('E')
		elif self.n == face:
			self.roll('S')
		else:
			self.roll('N')
			self.roll('N')
			
	def get_right_face(self, f):
		if self.s == f:
			return self.e
		elif self.e == f:
			return self.n
		elif self.w == f:
			return self.s
		else:
			return self.w
	
	def is_identical(self, other):		
		directions = 'NWWEESEES'
		for direction in directions:
			for i in range(4):
				if self.is_matchall(other): return True
				self.rotate_right()		
			self.roll(direction)
		return False
	
	def is_identical_(self, other):
		
		if self.is_matchall(other):return True
		self.roll('S')
		if self.is_matchall(other):return True
		self.roll('N')
		self.roll('E')
		if self.is_matchall(other):return True
		self.roll('W')
		self.roll('W')
		if self.is_matchall(other):return True
		self.roll('E')
		self.roll('N')
		if self.is_matchall(other):return True
		self.roll('N')
		if self.is_matchall(other):return True
		self.roll('S')
		self.roll('S')
		self.roll('E')
		self.roll('E')
		if self.is_matchall(other):return True
		return False


	def is_matchall(self, other):
		if self.t != other.t: return False
		if self.s != other.s: return False
		if self.e != other.e: return False
		if self.w != other.w: return False
		if self.n != other.n: return False
		if self.b != other.b: return False
		return True
		
faces1 = list(map(int, input().split()))
faces2 = list(map(int, input().split()))
dice1 = Dice(faces1)
dice2 = Dice(faces2)

if dice1.is_identical(dice2):
	print('Yes')
else:
	print('No')

Solution (Python):
class Dice:
	
	def __init__(self, faces):
		self.faces = faces
		self.t = faces[0]
		self.s = faces[1]
		self.e = faces[2]
		self.w = faces[3]
		self.n = faces[4]
		self.b = faces[5]

	def roll(self, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = n_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def rotate_right(self):
		s_ = self.s
		w_ = self.w
		n_ = self.n
		e_ = self.e
		self.s = e_
		self.w = s_
		self.n = w_
		self.e = n_
	
	def is_identical(self, other):		
		directions = 'NWWWNN'
		for direction in directions:
			for i in range(4):
				if self.is_matchall(other): return True
				self.rotate_right()
			self.roll(direction)
		return False

	def is_matchall(self, other):
		if self.t != other.t: return False
		if self.s != other.s: return False
		if self.e != other.e: return False
		if self.w != other.w: return False
		if self.n != other.n: return False
		if self.b != other.b: return False
		return True
		
faces1 = list(map(int, input().split()))
faces2 = list(map(int, input().split()))
dice1 = Dice(faces1)
dice2 = Dice(faces2)

if dice1.is_identical(dice2):
	print('Yes')
else:
	print('No')

Solution (Python):
class Dice:
	
	def __init__(self, faces):
		self.faces = faces
		self.t = faces[0]
		self.s = faces[1]
		self.e = faces[2]
		self.w = faces[3]
		self.n = faces[4]
		self.b = faces[5]

	def roll(self, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = n_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def rotate_right(self):
		s_ = self.s
		w_ = self.w
		n_ = self.n
		e_ = self.e
		self.s = e_
		self.w = s_
		self.n = w_
		self.e = n_
	
	def is_identical(self, other):		
		directions = 'NWNNWW'
		for direction in directions:
			for i in range(4):
				self.rotate_right()
				if self.is_matchall(other): return True
			self.roll(direction)

		return False

	def is_matchall(self, other):
		if self.t != other.t: return False
		if self.s != other.s: return False
		if self.e != other.e: return False
		if self.w != other.w: return False
		if self.n != other.n: return False
		if self.b != other.b: return False
		return True
		
faces1 = list(map(int, input().split()))
faces2 = list(map(int, input().split()))
dice1 = Dice(faces1)
dice2 = Dice(faces2)

if dice1.is_identical(dice2):
	print('Yes')
else:
	print('No')

Solution (Python):
class Dice:
	
	def __init__(self, faces):
		self.faces = faces
		self.t = faces[0]
		self.s = faces[1]
		self.e = faces[2]
		self.w = faces[3]
		self.n = faces[4]
		self.b = faces[5]

	def roll(self, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = n_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def rotate_right(self):
		s_ = self.s
		w_ = self.w
		n_ = self.n
		e_ = self.e
		self.s = e_
		self.w = s_
		self.n = w_
		self.e = n_
	
	def is_identical(self, other):		
		directions = 'NWNNWW'
		for direction in directions:
			for i in range(4):
				self.rotate_right()
				if self.is_matchall(other): return True
			self.roll(direction)
		return False

	def is_matchall(self, other):
		if self.t != other.t: return False
		if self.s != other.s: return False
		if self.e != other.e: return False
		if self.w != other.w: return False
		if self.n != other.n: return False
		if self.b != other.b: return False
		return True
		
faces1 = list(map(int, input().split()))
faces2 = list(map(int, input().split()))
dice1 = Dice(faces1)
dice2 = Dice(faces2)

if dice1.is_identical(dice2):
	print('Yes')
else:
	print('No')

Solution (Python):
class Dice(object):

    def __init__(self, nums):
        self.nums = nums
        self.ifaces = [(1,2,3), (2,3,1), (3,1,2),
                       (1,4,2), (4,2,1), (2,1,4),
                       (1,5,4), (5,4,1), (4,1,5),
                       (1,3,5), (3,5,1), (5,1,3),
                       (2,6,3), (6,3,2), (3,2,6),
                       (2,4,6), (4,6,2), (6,2,4),
                       (4,5,6), (5,6,4), (6,4,5),
                       (3,6,5), (6,5,3), (5,3,6),]

    def index(self, num):
        return self.nums.index(num)

    def face(self, iface):
        return [self.nums[i-1] for i in iface]

    def all_face(self):
        for iface in self.ifaces:
            yield self.face(iface)

def is_same(d1, d2):
    for f1 in d1.all_face():
        found = False
        for f2 in d2.all_face():
            if f1 == f2:
                found = True
                break
        if not found:
            return False
    return True

d1 = Dice([int(i) for i in input().split()])
d2 = Dice([int(i) for i in input().split()])

if is_same(d1, d2):
    print('Yes')
else:
    print('No')

Solution (Python):
import random
def dice(a,b,c,d,e,f,l):
    if l == "N":
        return [b,f,c,d,a,e]
    if l == "S":
        return [e,a,c,d,f,b]
    if l == "E":
        return [d,b,a,f,e,c]
    if l == "W":
        return [c,b,f,a,e,d]
d = list(map(int, input().split()))
s = ["W","N","E","S"]
a,b,c,g,e,f = map(int ,input().split())
j = 0
while j <= 10000:
    k = random.randrange(4)
    d = dice(d[0],d[1],d[2],d[3],d[4],d[5],s[k])
    if d[0] == a and d[1] == b and d[2] == c and d[3] == g and d[4] == e and d[5] == f:
        print("Yes")
        break
    if j == 10000:
        print("No")
    j += 1