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(object):
 
    def __init__(self, d):

        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]
 
    def move_next_rows(self):
        temp = self.rows.pop(0)
        self.rows.append(temp)
        self.__update(self.cols, self.rows)

    def move_prev_rows(self):
        temp = self.rows.pop(3)
        self.rows.insert(0, temp)
        self.__update(self.cols, self.rows)
    
    def move_next_cols(self):
        temp = self.cols.pop(0)
        self.cols.append(temp)
        self.__update(self.rows, self.cols)
 
    def move_prev_cols(self):
        temp = self.cols.pop(3)
        self.cols.insert(0, temp)
        self.__update(self.rows, self.cols)

    def __update(self, x, y):
        x[0] = y[0]
        x[2] = y[2]
 
class DiceChecker(object):

    def __init__(self, dice1, dice2):
        self.dice1 = dice1
        self.dice2 = dice2
        self.dice1_top = self.dice1.rows[0]
        self.dice1_front = self.dice1.rows[3]
        
    def check_same_dice(self):

        is_same = False
        for _ in range(4):
            for _ in range(4):
                for _ in range(4):
                    is_same_element = self.dice1.rows == self.dice2.rows and self.dice1.cols == self.dice2.cols
                    if is_same_element: 
                        is_same = True
                    self.__rot(self.dice2)
                self.dice2.move_next_rows()
            self.dice2.move_next_cols()
            
        if is_same:
            print("Yes")
        else:
            print("No")
    
    def __rot(self, dice):
        temp = dice.rows[1]
        dice.rows[1] = dice.cols[3]
        dice.cols[3] = dice.rows[3]
        dice.rows[3] = dice.cols[1]
        dice.cols[1] = temp

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

dice_checker = DiceChecker(dice1, dice2)
dice_checker.check_same_dice()

Solution (Python):
import sys


class Daise:
    def __init__(self, info_list):
        self.T = info_list[0]
        self.S = info_list[1]
        self.E = info_list[2]
        self.W = info_list[3]
        self.N = info_list[4]
        self.B = info_list[5]
    
    def change(self, axis):
        if axis == 'S':
            self.T, self.B, self.S, self.N = self.N, self.S, self.T, self.B
        
        elif axis == 'E':
            self.T, self.B, self.E, self.W = self.W, self.E, self.T, self.B
        
        elif axis == 'W':
            self.T, self.B, self.W, self.E = self.E, self.W, self.T, self.B
        
        elif axis == 'N':
            self.T, self.B, self.N, self.S = self.S, self.N, self.T, self.B
        
        elif axis == 'Turn':
            self.S, self.E, self.N, self.W = self.E, self.N, self.W, self.S
    

    def output(self):
        return [self.T, self.S, self.E, self.W, self.N, self.B]
    

    def set_info(self, top, front):
        if front in (self.T, self.B):
            self.change("S")

        while self.S != front:
            self.change('Turn')
 
        while self.T != top:
            self.change('E')



if __name__ == '__main__':
    daiseA = Daise(list(map(str, input().split())))
    daiseB = Daise(list(map(str, input().split())))
    
    for _ in range(4):
        for _ in range(4):
            if daiseA.output() == daiseB.output():
                print('Yes')
                sys.exit()
            for _ in range(4):
                if daiseA.output() == daiseB.output():
                    print('Yes')
                    sys.exit()
                daiseB.change('Turn')
            daiseB.change('S')
        daiseB.change('W')
    print('No')

Solution (Python):
class Dice:
    def __init__(self, dice: list):
        self.top = dice[0]
        self.bottom = dice[5]
        self.front = dice[1]
        self.behind = dice[4]
        self.right = dice[2]
        self.left = dice[3]

    def __eq__(self, other):
        if not isinstance(other, Dice):
            return NotImplemented
        return self.top == other.top and self.bottom == other.bottom and self.front == other.front \
                and self.behind == other.behind and self.right == other.right

    def roll(self, direction: str):
        buffer = self.top
        if direction == 'E':
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = buffer
        elif direction == 'N':
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.behind
            self.behind = buffer
        elif direction == 'S':
            self.top = self.behind
            self.behind = self.bottom
            self.bottom = self.front
            self.front = buffer
        else:
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = buffer

    def turn(self):
        buffer = self.front
        self.front = self.right
        self.right = self.behind
        self.behind = self.left
        self.left = buffer


def main():
    dice1, dice2 = [Dice(list(map(int, input().split()))) for _ in range(2)]
    for _ in range(2):
        for _ in range(4):
            for _ in range(4):
                if dice1 == dice2:
                    print('Yes')
                    return
                dice2.turn()
            dice2.roll('N')
        dice2.roll('E')
    print('No')


if __name__ == '__main__':
    main()

Solution (Python):
class Dice:

    def __init__(self):
        
        
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        
        
def main():
    import random

    t1,s1,e1,w1,n1,b1 = map(int, input().split())
    t2,s2,e2,w2,n2,b2 = map(int, input().split())

    dice1 = Dice(t1,s1,e1,w1,n1,b1)
    dice2 = Dice(t2,s2,e2,w2,n2,b2)

    flag = 0

    for _ in range(10000):

        if (dice1.t, dice1.s, dice1.e, dice1.w, dice1.n, dice1.b) == (dice2.t, dice2.s, dice2.e, dice2.w, dice2.n, dice2.b):
            flag = 1
            break
        else:
            seed = random.randint(0, 3)
            dice2.rot(seed)

    if flag == 1:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    def __init__(self,num):
        self.num = num.copy()
        
    def east(self):
        temp = self.num.copy()
        self.num[1-1] = temp[4-1]
        self.num[4-1] = temp[6-1]
        self.num[6-1] = temp[3-1]
        self.num[3-1] = temp[1-1]

    def north(self):
        temp = self.num.copy()
        self.num[1-1] = temp[2-1]
        self.num[2-1] = temp[6-1]
        self.num[6-1] = temp[5-1]
        self.num[5-1] = temp[1-1]

    def south(self):
        temp = self.num.copy()
        self.num[1-1] = temp[5-1]
        self.num[5-1] = temp[6-1]
        self.num[6-1] = temp[2-1]
        self.num[2-1] = temp[1-1]

    def west(self):
        temp = self.num.copy()
        self.num[1-1] = temp[3-1]
        self.num[3-1] = temp[6-1]
        self.num[6-1] = temp[4-1]
        self.num[4-1] = temp[1-1]

    def right(self):
        temp = self.num.copy()
        self.num[2-1] = temp[4-1]
        self.num[4-1] = temp[5-1]
        self.num[5-1] = temp[3-1]
        self.num[3-1] = temp[2-1]

num1 = list(map(int,input().split()))
num2 = list(map(int,input().split()))
dice1,dice2 = Dice(num1),Dice(num2)
if num1.sort() != num2.sort(): print('No')
else:
    flag = False
    for i in range(20):
        if flag == True: break
        dice2.north()
        for _ in range(20):
            if flag == True:
                break
            dice2.east()
            for _ in range(20):
                dice2.right()
                if dice1.num == dice2.num:
                    flag = True
                    break
    if flag: print("Yes")
    else: print("No")

Solution (Python):
c1=[int(i) for i in input().split()]
c2=[int(i) for i in input().split()]
d=[(0,0,1),(-1,0,0),(0,1,0),(0,-1,0),(1,0,0),(0,0,-1)]
def crosspro(y,x):
    return (y[1]*x[2]-y[2]*x[1],y[2]*x[0]-y[0]*x[2],y[0]*x[1]-y[1]*x[0])
def north(r):
    res=[]
    for p in r:
        res.append((p[2],p[1],-p[0]))
    return res
def south(r):
    res=[]
    for p in r:
        res.append((-p[2],p[1],p[0]))
    return res
def east(r):
    res=[]
    for p in r:
        res.append((p[0],p[2],-p[1]))
    return res
def west(r):
    res=[]
    for p in r:
        res.append((p[0],-p[2],p[1]))
    return res
def left(r):
    res=[]
    for p in r:
        res.append((p[1],-p[0],p[2]))
    return res
def right(r):
    res=[]
    for p in r:
        res.append((-p[1],p[0],p[2]))
    return res
T=["","N","E","W","S","NN"]
U=["","L","LL","LLL"]
def change(S):
    D=d
    for i in S:
        if i=="N":
            D=north(D)
        elif i=="E":
            D=east(D)
        elif i=="W":
            D=west(D)
        elif i=="S":
            D=south(D)
        elif i=="L":
            D=left(D)
        else:
            D=right(D)
    return D
for i in T:
    for j in U:
        D=change(i+j)
        flag=0
        for x in range(6):
            for y in range(6):
                if d[x]==D[y]:
                    if c1[x]!=c2[y]:
                        flag=1
        if flag==0:
            print("Yes")
            exit()
print("No")

Solution (Python):
dice_1 = input().split()
dice_2 = input().split()

rolls = {' ':[0, 1, 2, 3, 4, 5], 
         'W':[2, 1, 5, 0, 4, 3], 
         'N':[1, 5, 2, 3, 0, 4], 
         'E':[3, 1, 0, 5, 4, 2], 
         'S':[4, 0, 2, 3, 5, 1]
        }
orders = [' ', 'N', 'W', 'E', 'S', 'NN']
tf = 0
for order in orders:
    copy_2 = dice_2
    for d in order:
        roll = rolls[d]
        copy_2 = [copy_2[i] for i in roll]
    
    l = [1, 2, 4, 3]
    a0 = copy_2[0] == dice_1[0]
    a1 = copy_2[5] == dice_1[5]
    a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
    if  a0 and a1 and a2:
        tf += 1






if tf>0:
    print('Yes')
else:
    print('No')

Solution (Python):
dice_1 = input().split()
dice_2 = input().split()

rolls = {' ':[0, 1, 2, 3, 4, 5], 
         'W':[2, 1, 5, 0, 4, 3], 
         'N':[1, 5, 2, 3, 0, 4], 
         'E':[3, 1, 0, 5, 4, 2], 
         'S':[4, 0, 2, 3, 5, 1]
        }
orders = [' ', 'N', 'W', 'E', 'S', 'NN']
tf = 0
for order in orders:
    copy_2 = dice_2
    for d in order:
        roll = rolls[d]
        copy_2 = [copy_2[i] for i in roll]    
    l = [1, 2, 4, 3]
    a0 = copy_2[0] == dice_1[0]
    a1 = copy_2[5] == dice_1[5]
    a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
    if  a0 and a1 and a2:
        tf += 1
if tf>0:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def R(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_R(dice1, dice2) -> bool:
    """横回転をチェックする."""
    for _i in range(4):
        dice1.R()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False



data1 = [int(i) for i in input().split()]
data2 = [int(i) for i in input().split()]






dice1 = Dice(data1)
dice2 = Dice(data2)


for _i in range(4):
    dice1.S()
    if dice1.get_upper_value() == dice2.get_upper_value():
        if check_R(dice1, dice2):
            print('Yes')
            sys.exit()

for _i in range(4):
    dice1.E()
    if dice1.get_upper_value() == dice2.get_upper_value():
        if check_R(dice1, dice2):
            print('Yes')
            sys.exit()

print('No')

Solution (Python):
from sys import stdin
from copy import deepcopy
import queue

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

d1_nums = [int(x) for x in stdin.readline().rstrip().split()]
d2_nums = [int(x) for x in stdin.readline().rstrip().split()]
if set(d1_nums) != set(d2_nums):
    print("No")

d1 = Dice(d1_nums)
d2 = Dice(d2_nums)


memo = [[False] * 7 for i in range(7)]
memo[d1.pos["T"]][d1.pos["S"]] = ""


res = {}
for j in ["T", "S", "E"]:
    if d1.labels[d1.pos[j]] != d2.labels[d2.pos[j]]:
        break        
    else:
        res[memo[d1.pos["T"]][d1.pos["S"]]] = d1




def solve(dice=d1):
    que = queue.Queue()
    que.put(dice)
    sol_q = ["E", "N", "S", "W"]
    
    while not que.empty():
        d = que.get()
        for i in sol_q:
            d_next = Dice.rolled(d, i)
            if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                que.put(d_next)
                memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                for j in ["T", "S", "E"]:
                    if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                        break
                else:
            	    res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next
    else:
        return True

solve()
check_pos = ["N", "W", "B"]
if len(res) == 0:
	print("No")
else:
    for k, v in res.items():
        for i in check_pos:
            if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                break
        else:
            print("Yes")
            break
    else:
        print("No")

Solution (Python):
from sys import stdin
from copy import deepcopy
import queue

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

    def isDiceSame(d1, d2):
        if not isinstance(d1, Dice) or not isinstance(d2, Dice):
            return False

        if set(d1.labels[1:]) != set(d2.labels[1:]):
            return False

        else:
            q = ["T", "S", "E", "N", "W", "B"]
            memo = [[False] * 7 for i in range(7)]
            memo[d1.pos["T"]][d1.pos["S"]] = ""
            res = {}
            for i in q[:3]:
                if d1.labels[d1.pos[i]] != d2.labels[d2.pos[i]]:
                    break
            else:
                res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

            def bfs_isDiceSame():
                que = queue.Queue()
                que.put(d1)

                while not que.empty():
                    d = que.get()
                    for i in q[1:5]:
                        d_next = Dice.rolled(d, i)
                        if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                            que.put(d_next)
                            memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                            for j in q[:3]:
                                if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                                    break
                            else:
                                res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next

            bfs_isDiceSame()
            if len(res) == 0:
                return False
            else:
                for k, v in res.items():
                    for i in q[3:]:
                        if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                            break
                    else:
                        return True
                else:
                    return False

d1_nums = [int(x) for x in stdin.readline().rstrip().split()]
d2_nums = [int(x) for x in stdin.readline().rstrip().split()]
d1 = Dice(d1_nums)
d2 = Dice(d2_nums)
if Dice.isDiceSame(d1, d2):
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face
  def check_face(self, face1):
    for i in range(4):
      if face1 == self.face:
        return self.face
      else:
        self.face[1],self.face[2],self.face[4],self.face[3] = self.face[2],self.face[4],self.face[3],self.face[1]

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = Dice()
dice2 = Dice()
dice1.make_dice(num1)
for i in range(6):
  dice2.make_dice(num2)
  if i == 0:
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 1:
    dice2.move("N")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 2:
    dice2.move("E")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 3:
    dice2.move("S")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 4:
    dice2.move("W")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 5:
    dice2.move("N")
    dice2.move("N")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
    else:
      print("No")
      break

Solution (Python):


import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    dice1 = Dice(*map(int, raw_input().split()))
    dice2 = Dice(*map(int, raw_input().split()))

    ref1 = set()
    ref2 = set()
    for _ in range(1000):
        if len(ref1) > 23:
            break

        ref1.add((dice1.top, dice1.s, dice1.e))
        ref2.add((dice2.top, dice2.s, dice2.e))

        dist = 'NSEW'[random.randint(0,3)]
        dice1.rotate(dist)
        dice2.rotate(dist)

    print 'Yes' if ref1==ref2 else 'No'

Solution (Python):
d1=list(map(int,input().split()))
d2=list(map(int,input().split()))
n=0

for i in range(4):
	d2[0],d2[1],d2[4],d2[5]=d2[1],d2[5],d2[0],d2[4]
	for i in range(4):
		d2[1],d2[3],d2[4],d2[2]=d2[3],d2[4],d2[2],d2[1]
		if d1[0]==d2[0] and d1[1]==d2[1] and d1[2]==d2[2] and d1[3]==d2[3] and d1[4]==d2[4] and d1[5]==d2[5]:
			n+=1
for i in range(4):
	d2[0],d2[3],d2[5],d2[2]=d2[3],d2[5],d2[2],d2[0]
	for i in range(4):
		d2[1],d2[3],d2[4],d2[2]=d2[3],d2[4],d2[2],d2[1]
		if d1[0]==d2[0] and d1[1]==d2[1] and d1[2]==d2[2] and d1[3]==d2[3] and d1[4]==d2[4] and d1[5]==d2[5]:
			n+=1		

if n==0:
	print('No')
elif n>0:
	print('Yes')

Solution (Python):
import copy


class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    def __eq__(self, other):
        if other is None or not isinstance(other, Dice):
            return False

        
        dups = []
        for _ in range(6):
            dups.append(copy.copy(self))
        dups[1].roll('W')
        dups[2].roll('SW')
        dups[3].roll('NW')
        dups[4].roll('E')
        dups[5].roll('WW')

        for dup in dups:
            for _ in range(4):
                dup.roll('N')
                if other.eyes == dup.eyes:
                    return True

        return False

    @property
    def eyes(self):
        return self._eyes[1:6]

    def roll(self, direction_text):
        for d in direction_text:
            self.roll_once(d)

    def roll_once(self, direction):
        a = self._eyes
        if direction == 'N':
            self._eyes = ['dummy', a[2], a[6], a[3], a[4], a[1], a[5]]
        elif direction == 'S':
            self._eyes = ['dummy', a[5], a[1], a[3], a[4], a[6], a[2]]
        elif direction == 'W':
            self._eyes = ['dummy', a[3], a[2], a[6], a[1], a[5], a[4]]
        elif direction == 'E':
            self._eyes = ['dummy', a[4], a[2], a[1], a[6], a[5], a[3]]
        else:
            raise ValueError('NEWS箱推し')


dice1 = Dice(input().split())
dice2 = Dice(input().split())
if dice1 == dice2:
    result = 'Yes'
else:
    result = 'No'
print(result)

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

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

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

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

Solution (Python):
import random


class Cube:
    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 rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    u1, s1, e1, w1, n1, d1 = map(int, input().split())
    u2, s2, e2, w2, n2, d2 = map(int, input().split())
    cube1 = Cube(u1, s1, e1, w1, n1, d1)
    cube2 = Cube(u2, s2, e2, w2, n2, d2)

    ret = "No"
    for i in range(10000):
        cube2.rotate(random.choice("NWES"))
        if cube1.u == cube2.u and cube1.n == cube2.n and cube1.w == cube2.w and cube1.e == cube2.e and cube1.s == cube2.s and cube1.d == cube2.d:
            ret = "Yes"
            break
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):


import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}
    way = ("N","E","W","S")

    def __init__(self, data):
        self.label = data

    def move(self, data):
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare(self, dice2):
        ok = False
        for i in range(1000):
            check = True
            for i2 in range(6):
                if self.label[i2] == dice2.label[i2] :
                    continue
                else:
                    check = False
                    break

            if check :
                ok = True
                break
            else:
                self.move(self.way[random.randint(0,3)])
        return ok

dice1 = Dice(input().split())
dice2 = Dice(input().split())

if dice1.compare(dice2) :
    print ("Yes")
else:
    print ("No")