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):
        self.num = [0 for _ in range(6)]
    
    def set_num(self, n0, n1, n2, n3, n4, n5):
        self.num[0] = n0
        self.num[1] = n1
        self.num[2] = n2
        self.num[3] = n3
        self.num[4] = n4
        self.num[5] = n5
    
    
    def roll(self, order):
        tmp = self.num.copy()
        
        if order == "N":
            self.set_num(tmp[1], tmp[5], tmp[2], tmp[3], tmp[0], tmp[4])
        elif order == "S":
            self.set_num(tmp[4], tmp[0], tmp[2], tmp[3], tmp[5], tmp[1])
        elif order == "E":
            self.set_num(tmp[3], tmp[1], tmp[0], tmp[5], tmp[4], tmp[2])
        elif order == "W":
            self.set_num(tmp[2], tmp[1], tmp[5], tmp[0], tmp[4], tmp[3])
        elif order == "rot_Clock":
            self.set_num(tmp[0], tmp[2], tmp[4], tmp[1], tmp[3], tmp[5])
        else:
            print("Error: 不正な入力です")

    def get_top_num(self):
        return self.num[0]
        
    

init_num1 = [int(_) for _ in input().split()]
init_num2 = [int(_) for _ in input().split()]


dice1 = Dice()
dice2 = Dice()
dice1.set_num(init_num1[0], init_num1[1], init_num1[2], init_num1[3], init_num1[4], init_num1[5])
dice2.set_num(init_num2[0], init_num2[1], init_num2[2], init_num2[3], init_num2[4], init_num2[5])


checker = False
for i in range(3):
    for j in range(3):
        orders = "N" * (i + 1) + "E" * (j + 1)
        
        
        for order in orders:
            dice2.roll(order)
        if dice1.num == dice2.num:
            checker = True
        
for i in range(3):
    for j in range(3):
        orders = "E" * (i + 1) + "N" * (j + 1)
        
        
        for order in orders:
            dice2.roll(order)
        if dice1.num == dice2.num:
            checker = True

for i in range(3):
    for j in range(3):
        for k in range(3):
            orders = "E" * (i + 1) + "N" * (j + 1) + "E" * (k + 1)
            
            
            for order in orders:
                dice2.roll(order)
            if dice1.num == dice2.num:
                checker = True

for i in range(3):
    for j in range(3):
        for k in range(3):
            orders = "N" * (i + 1) + "E" * (j + 1) + "N" * (k + 1)
            
            
            for order in orders:
                dice2.roll(order)
            if dice1.num == dice2.num:
                checker = True



if checker == False:
    num_dice1_top, num_dice1_front = dice1.num[0], dice1.num[1]
    
    index_top = dice2.num.index(num_dice1_top)
    index_front = dice2.num.index(num_dice1_front)
    
    counter = 0
    while (index_top != 0) & (counter < 3):
        counter += 1
        if index_top in [0, 1, 4, 5]:
            dice2.roll("N")
            index_top = dice2.num.index(num_dice1_top)
            index_front = dice2.num.index(num_dice1_front)
        else:
            dice2.roll("E")
            index_top = dice2.num.index(num_dice1_top)
            index_front = dice2.num.index(num_dice1_front)
    
    counter = 0
    while (index_front != 1) & (counter < 3):
            dice2.roll("rot_Clock")
            index_top = dice2.num.index(num_dice1_top)
            index_front = dice2.num.index(num_dice1_front)
    
    
    
    
    if dice1.num == dice2.num:
        checker = True

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

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001




class Dice():

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

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

    def equals(self, another):

        ret = False

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret


diceA = Dice()
diceB = Dice()

table = list(map(int, input().split()))
diceA.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

table = list(map(int, input().split()))
diceB.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
   
label = list(map(int,input().split()))
d0 = dice(label)
d1 = list(map(int,input().split()))
for op in 'EEENEEENEEESEEESEEENEEEN':
    if d0.get_label() == d1:
        print('Yes')
        break
    d0.roll(op)
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)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

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

    def equals(self, another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret


diceA = Dice()
diceB = Dice()

table = list(map(int, input().split()))
diceA.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

table = list(map(int, input().split()))
diceB.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")

Solution (Python):









class Dice:
    def __init__(self, l1, l2, l3, l4, l5, l6):
        self.l1 = l1
        self.l2 = l2
        self.l3 = l3
        self.l4 = l4
        self.l5 = l5
        self.l6 = l6
        self.tmp = 0
    def move_n(self):
        self.tmp = self.l5
        self.l5 = self.l1
        self.l1 = self.l2
        self.l2 = self.l6
        self.l6 = self.tmp
    def move_s(self):
        self.tmp = self.l2
        self.l2 = self.l1
        self.l1 = self.l5
        self.l5 = self.l6
        self.l6 = self.tmp
    def move_e(self):
        self.tmp = self.l3
        self.l3 = self.l1
        self.l1 = self.l4
        self.l4 = self.l6
        self.l6 = self.tmp
    def move_w(self):
        self.tmp = self.l4
        self.l4 = self.l1
        self.l1 = self.l3
        self.l3 = self.l6
        self.l6 = self.tmp
    def show(self):
        return self.l1, self.l2, self.l3, self.l4, self.l5, self.l6

yn_f = False
d1 = Dice(*map(int, input().split()))
d2 = Dice(*map(int, input().split()))

if set(d1.show()) == set(d2.show()):
    ne_switch = 0
    while d1.l2 != d2.l2:
        if ne_switch < 3:
            d1.move_n()
            ne_switch+=1
        elif 3 <= ne_switch :
            d1.move_e()
            ne_switch+=1
        if ne_switch == 6: ne_switch = 0
    e_cnt = 0
    while d1.l1 != d2.l1 and e_cnt <= 3:
        d1.move_e()
        e_cnt+=1

if d1.l3 == d2.l3 and d1.l4 == d2.l4 and d1.l5 == d2.l5 and d1.l6 == d2.l6:
    yn_f = True

print('Yes' if yn_f else 'No')

Solution (Python):

from sys import stdin

class Dice:

    def __init__(self,dicelist):
        self.dice_list = dicelist
        self.all_pattern = 'NNNNWNNNWNNNENNNENNNWNNN'

    def roll(self, direction):
        work = list(self.dice_list)
        if (direction == 'N'):
            self.dice_list[0] = work[1]
            self.dice_list[1] = work[5]
            self.dice_list[2] = work[2]
            self.dice_list[3] = work[3]
            self.dice_list[4] = work[0]
            self.dice_list[5] = work[4]
        elif (direction == 'E'):
            self.dice_list[0] = work[3]
            self.dice_list[1] = work[1]
            self.dice_list[2] = work[0]
            self.dice_list[3] = work[5]
            self.dice_list[4] = work[4]
            self.dice_list[5] = work[2]
        elif (direction == 'S'):
            self.dice_list[0] = work[4]
            self.dice_list[1] = work[0]
            self.dice_list[2] = work[2]
            self.dice_list[3] = work[3]
            self.dice_list[4] = work[5]
            self.dice_list[5] = work[1]
        elif (direction == 'W'):
            self.dice_list[0] = work[2]
            self.dice_list[1] = work[1]
            self.dice_list[2] = work[5]
            self.dice_list[3] = work[0]
            self.dice_list[4] = work[4]
            self.dice_list[5] = work[3]

    def equals(self, another):
        for p in self.all_pattern:
            another.roll(p)
            if self.dice_list == another.dice_list:
                return True
        else:
            return False


dice_list1 = list(map(int, stdin.readline().rstrip().split()))
dice_list2 = list(map(int, stdin.readline().rstrip().split()))

dice1 = Dice(dice_list1)
dice2 = Dice(dice_list2)

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

Solution (Python):
import copy
from enum import IntEnum

class Face(IntEnum):
    One=1
    Two=2
    Three=3
    Four=4
    Five=5
    Six=6


class Dice:
    def __init__(self):
        self.top=Face.One
        self.bottom=Face.Six
        self.back=Face.Two
        self.front=Face.Five
        self.left=Face.Four
        self.right=Face.Three
        
    def set_face(self,face_ls):
        self.top=Face(face_ls[0])
        self.back=Face(face_ls[1])
        self.right=Face(face_ls[2])
        self.left=Face(face_ls[3])
        self.front=Face(face_ls[4])
        self.bottom=Face(face_ls[5])
        
    def __str__(self):
        return f"top: {self.top}, back: {self.back}, right: {self.right}, bottom: {self.bottom}, front: {self.front}, left: {self.left}"
        
    def __eq__(self,other):
        equal=self.top == other.top and self.bottom == other.bottom and self.back == other.back and self.front == other.front and self.left == other.left and self.right == other.right
            
        return equal
        
    def get_one_face(self):
        return self.get_n_face(Face.One)
        
    def get_n_face(self,n):
        
        if self.top ==n:
            return self.top
        elif self.bottom==n:
            return self.bottom
        elif self.back==n:
            return self.back
        elif self.front==n:
            return self.front
        elif self.left==n:
            return self.left
        elif self.right==n:
            return self.right
        else:
            assert False
            
    
    def roll(self,command):
        if command=="E":
            
            temp=self.top
            self.top=self.left
            self.left=self.bottom
            self.bottom=self.right
            self.right=temp
            
        elif command=="N":
            
            temp=self.top
            self.top=self.back
            self.back=self.bottom
            self.bottom=self.front
            self.front=temp
            
        elif command=="S":
            
            temp=self.top
            self.top=self.front
            self.front=self.bottom
            self.bottom=self.back
            self.back=temp
            
        elif command=="W":
            
            temp=self.top
            self.top=self.right
            self.right=self.bottom
            self.bottom=self.left
            self.left=temp
    
    def roll_clockwise_fix_top(self):
        
        temp=self.front
        self.front=self.left
        self.left=self.back
        self.back=self.right
        self.right=temp
      
def num_pattern_match(num_list,pattern):
    for i,x in enumerate(num_list):
        is_match=True
        for j,y in enumerate(pattern):
            if num_list[(i+j) % len(num_list)] == pattern[j]:
                pass
            else:
                is_match=False
        if is_match:
            return True
            
    return False      

def build_dice(top,back):
    
    dice=Dice()
    dice.top=top
    dice.back=back
    
    dice.bottom=Face(7-int(dice.top))
    dice.front=Face(7-int(dice.back))

    
    
    exist_dice_list=[int(dice.top),
    int(dice.bottom),
    int(dice.front),
    int(dice.back)]
    
    left_face_num=set([i+1 for i in range(6)]) - set(exist_dice_list)
    
    
    
    face_list=[int(dice.top),int(dice.front),int(dice.bottom),int(dice.back)]

    
    if 1 in left_face_num:
        
        pattern=[2,3,5,4]
        if num_pattern_match(face_list,pattern):
            
            
            dice.right=Face.Six
            dice.left=Face.One
        else:
            dice.right=Face.One
            dice.left=Face.Six
            
    elif 2 in left_face_num:
        pattern=[1,4,6,3]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Five
            dice.left=Face.Two
        else:
            dice.right=Face.Two
            dice.left=Face.Five
            
    elif 3 in left_face_num:
        pattern=[2,6,5,1]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Four
            dice.left=Face.Three
        else:
            dice.right=Face.Three
            dice.left=Face.Four           
        
    return dice


def move_one_face_to_top(dice):
    
    if dice.get_one_face() ==dice.top:
        return
    elif dice.get_one_face()==dice.left:
        
        dice.roll("E")
        return
    elif dice.get_one_face()==dice.back:
        dice.roll("N")
    elif dice.get_one_face()==dice.right:
        dice.roll("W")
    elif dice.get_one_face()==dice.front:
        dice.roll("S")
    elif dice.get_one_face()==dice.bottom:
        dice.roll("N")
        dice.roll("N")
        

def create_all_equal_dice(dice):
    
    same_dice_ls=[]
    for face in list(Face):
        
        created_dice=copy.deepcopy(dice)
        move_n_face_to_top(created_dice,face)
        same_dice_ls.append(copy.deepcopy(created_dice))
        
        
        for i in range(3):
            created_dice.roll_clockwise_fix_top()
            same_dice_ls.append(copy.deepcopy(created_dice))
            
    return same_dice_ls
        
def move_n_face_to_top(dice,face):
    
    spec_face=dice.get_n_face(face)
    if spec_face==dice.top:
        return
    elif spec_face==dice.left:
        dice.roll("E")
        return
    elif spec_face==dice.back:
        dice.roll("N")
        return
    elif spec_face==dice.right:
        dice.roll("W")
        return
    elif spec_face==dice.front:
        dice.roll("S")
        return
    elif spec_face==dice.bottom:
        dice.roll("N")
        dice.roll("N")
        return

def move_two_face_to_back(dice):
    
    assert dice.top == Face.One
    assert dice.bottom != Face.Two
    
    if dice.get_n_face(Face.Two)==dice.left:
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
    elif dice.get_n_face(Face.Two)==dice.front:
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
    elif dice.get_n_face(Face.Two)==dice.right:
        dice.roll_clockwise_fix_top()


def check_if_equal_dice(dice_x,dice_y):
    
    
    
    
    
    
    move_one_face_to_top(dice_x)
    move_one_face_to_top(dice_y)
    
    move_two_face_to_back(dice_x)
    move_two_face_to_back(dice_y)
    
    return dice_x==dice_y

def _run():
    dice_score_ls=list(map(int,input().split()))
    
    dice_score_dict={i+1:score for i,score in enumerate(dice_score_ls)}
    d_inv={v:k for k,v in dice_score_dict.items()}
    
    query_num=int(input())

    for i in range(query_num):
        top,back=tuple(map(int,input().split()))
        top=d_inv[top]
        back=d_inv[back]
        
        dice=build_dice(top,back)
        
        
        print(dice_score_dict[int(dice.right)])
        
    

def compare_dice_with_dict(dice_x,d_x,dice_y_face_list):
    
    is_top_same=d_x[dice_x.top]==dice_y_face_list[0]
    is_bottom_same=d_x[dice_x.bottom]==dice_y_face_list[5]
    is_right_same=d_x[dice_x.right]==dice_y_face_list[2]
    is_left_same=d_x[dice_x.left]==dice_y_face_list[3]
    is_front_same=d_x[dice_x.front]==dice_y_face_list[4]
    is_back_same=d_x[dice_x.back]==dice_y_face_list[1]
    
    return is_top_same and is_bottom_same and is_right_same and is_left_same and is_front_same and is_back_same
    

def run():
    dice_x_face_list=list(map(int,input().split()))
    
    dice_y_face_list=list(map(int,input().split()))
    
    
    face_dict={Face(i+1):x for i,x in enumerate(dice_x_face_list)}
    
    

    
    
    dice_x=Dice()
    
    
    

    ls=create_all_equal_dice(dice_x)


    is_same_dice=False
    for d in ls:
        if compare_dice_with_dict(d,face_dict,dice_y_face_list):
            is_same_dice=True


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

    
    
    
    
    
    
    

run()

Solution (Python):
import copy
import random

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

for x in range(1000):
    r = random.randint(0,3)
    if r == 0:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[4]
        Dt[4] = Dt[5]
        Dt[5] = Dt[1]
        Dt[1] = temp
    elif r== 1:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[2]
        Dt[2] = Dt[5]
        Dt[5] = Dt[3]
        Dt[3] = temp
    elif r== 2:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[3]
        Dt[3] = Dt[5]
        Dt[5] = Dt[2]
        Dt[2] = temp
    elif r == 3:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[1]
        Dt[1] = Dt[5]
        Dt[5] = Dt[4]
        Dt[4] = temp

    D2 = copy.copy(Dt)
        
    flag = 0
    for y in range(6):
        if D1[y] == D2[y]:
            flag += 1
    if flag == 6:
        break

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

Solution (Python):
class Dice:
    def __init__(self, numbers):
        self.dice = {"上" :numbers[0],
                     "下":numbers[5], 
                     "前":numbers[1],
                     "後":numbers[4],
                     "左":numbers[3],
                     "右":numbers[2]
                    }
    
    def order(self, order_seq):
        for _, order in enumerate(order_seq):
            if order == "N":
                self.north()
            elif order == "E":
                self.east()
            elif order == "W":
                self.west()
            elif order == "S":
                self.south()
        
        return self.dice["上"]

    def north(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = F
        self.dice["前"] = D
        self.dice["下"] = B
        self.dice["後"] = U

    def east(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = L
        self.dice["下"] = R
        self.dice["左"] = D
        self.dice["右"] = U

    def west(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = R
        self.dice["下"] = L
        self.dice["左"] = U
        self.dice["右"] = D

    def south(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = B
        self.dice["前"] = U
        self.dice["下"] = F
        self.dice["後"] = D   

    def set_position(self, n, position_seq):
        self.ans = []
        for i in range(n):
            self.up = position_seq[i][0]
            self.front = position_seq[i][1]

            self.search()
            self.west()
            self.search()
            self.west()
            self.search()
            self.north()
            self.search()
            self.west()
            self.search()
            self.west()
            self.search()
        
        return self.ans
    
    def search(self):
        
        if self.dice["上"] == self.up:
            for _ in range(4):
                
                
                if self.dice["前"] == self.front:
                    self.ans = [self.dice["右"], self.dice["後"], self.dice["左"], self.dice["下"]]
                    break
                self.rotate()
            

    def rotate(self):
        F, R, B, L = [self.dice["前"], self.dice["右"], self.dice["後"], self.dice["左"]]
        self.dice["前"] = R
        self.dice["右"] = B
        self.dice["後"] = L
        self.dice["左"] = F
        
numbers = list(map(int, input().split()))
dice1 = Dice(numbers)
numbers = list(map(int, input().split()))
dice2 = Dice(numbers)

position_seq = [[dice2.dice["上"], dice2.dice["前"]]]
answer = [dice2.dice["右"], dice2.dice["後"], dice2.dice["左"], dice2.dice["下"]]

ans = dice1.set_position(1, position_seq)

for i in range(4):
    if ans == None or ans[i] != answer[i]:
        print('No')
        break
if i == 3:
    print('Yes')

Solution (Python):
class Dice:
    def __init__(self, num):
        self.state = {}
        for i in range(1,6+1):
            self.state[i] = num[i-1]

        self.reversed_state = {}
        for key,val in zip(self.state.keys(), self.state.values()):
            self.reversed_state[val] = key
        
    def search_side(self, x,y):
        a = self.reversed_state[x]
        b = self.reversed_state[y]
        if str(a)+str(b) in '12651':
            side = self.state[3]
        elif str(b)+str(a) in '12651':
            side = self.state[4]
        elif str(a)+str(b) in '13641':
            side = self.state[5]
        elif str(b)+str(a) in '13641':
            side = self.state[2]
        elif str(a)+str(b) in '23542':
            side = self.state[1]
        elif str(b)+str(a) in '23542':
            side = self.state[6]
        else:
            side = None
        return side
        
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))

dice1 = Dice(num1)
dice2 = Dice(num2)


pairs = [(1,2), (2,6),(6,5),(5,1), (1,3),(3,6),(6,4),(4,1), (2,3),(3,5),(5,4),(4,2)]
pairs = [(dice1.state[a], dice1.state[b]) for (a,b) in pairs]

ans = 'Yes'
for x,y in pairs:
    side1 = dice1.search_side(x,y)
    side2 = dice2.search_side(x,y)
    if side1!=side2:
        ans = 'No'
        break
print(ans)

Solution (Python):
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

class Dice:
    def __init__(self,a):
        self.dice = [0 for i in range(len(a))]
        for i in range(len(a)):
            self.dice[i] = a[i]

    def N(self):
        self.dice[0],self.dice[1],self.dice[4],self.dice[5] = self.dice[1],self.dice[5],self.dice[0],self.dice[4]

    def S(self):
        self.dice[0],self.dice[1],self.dice[4],self.dice[5] = self.dice[4],self.dice[0],self.dice[5],self.dice[1]

    def E(self):
        self.dice[0],self.dice[2],self.dice[3],self.dice[5] = self.dice[3],self.dice[0],self.dice[5],self.dice[2]

    def W(self):
        self.dice[0],self.dice[2],self.dice[3],self.dice[5] = self.dice[2],self.dice[5],self.dice[0],self.dice[3]

    def R(self):
        self.dice[1],self.dice[2],self.dice[3],self.dice[4] = self.dice[3],self.dice[1],self.dice[4],self.dice[2]

    def L(self):
        self.dice[1],self.dice[2],self.dice[3],self.dice[4] = self.dice[2],self.dice[4],self.dice[1],self.dice[3]

    
    def output(self):
        print(self.dice)


dice1 = Dice(a)
dice2 = Dice(b)
dir = 'RRRRNRRRRSWRRRREERRRRWSRRRRNNNRRRR'
for c in dir:
    if c == "R":
        dice1.R()
    elif c == "N":
        dice1.N()
    elif c == "S":
        dice1.S()
    elif c == "W":
        dice1.W()
    elif c == "E":
        dice1.E()
    elif c == "L":
        dice1.L()
    if dice1.dice == dice2.dice:
        break

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

Solution (Python):
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def rotate_right(self):
        tmp = self.ns
        tmp.reverse()
        self.ns = self.we
        self.we = tmp

    def fit_top_s(self, top, s):
        while self.get_top() != top:
            if top in self.ns:
                self.n()
            elif top in self.we:
                self.w()
            else:
                self.n()
                self.n()
        while self.get_s() != s:
            self.rotate_right()

    def get_top(self):
        return self.ns[1]

    def get_s(self):
        return self.ns[2]

    def get_e(self):
        return self.we[2]


def resolve():
    nums = [int(i) for i in input().split()]
    dc1 = Dice(nums)
    nums = [int(i) for i in input().split()]
    dc2 = Dice(nums)
    dc2.fit_top_s(dc1.get_top(), dc1.get_s())
    if dc1.get_e() == dc2.get_e():
        print("Yes")
    else:
        print("No")


resolve()

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, rear, bottom):
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.rear = rear
        self.bottom = bottom
    def print(self):
        '''print top of dice'''
        print(self.top)
    def north(self):
        self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
    def south(self):
        self.top, self.front, self.bottom, self.rear = \
            self.rear, self.top, self.front, self.bottom
    def east(self):
        self.top, self.right, self.bottom, self.left = \
            self.left, self.top, self.right, self.bottom
    def west(self):
        self.top, self.right, self.bottom, self.left = \
            self.right, self.bottom, self.left, self.top
    def clockwise(self):
        self.front, self.right, self.rear, self.left = \
            self.right, self.rear, self.left, self.front
    def ccw(self):
        self.front, self.right, self.rear, self.left = \
            self.left, self.front, self.right, self.rear
    def __eq__(self, other):
        
        pattern = ['', 'N', 'N', 'N', 'E', 'EE']
        tmp = Dice(other.top, other.front, other.right, other.left, other.rear, other.bottom)
        for i in pattern:
            if i == 'N':
                tmp.north()
            elif i == 'E':
                tmp.east()
            elif i == 'EE':
                tmp.east()
                tmp.east()
            else:
                pass
            if self.top != tmp.top or self.bottom != tmp.bottom:
                continue
            for j in range(4):
                if self.front == tmp.front and self.right == tmp.right and \
                   self.rear == tmp.rear and self.left == tmp.left:
                    return True
                tmp.clockwise()
        return False

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