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, faces):
        self.top = faces[0]
        self.front = faces[1]
        self.right = faces[2]
        self.left = faces[3]
        self.back = faces[4]
        self.bottom = faces[5]

    def rotate(self, command):
        pre_top = self.top
        if command == "N":
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.back
            self.back = pre_top
        elif command == "E":
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = pre_top
        elif command == "W":
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = pre_top
        elif command == "S":
            self.top = self.back
            self.back = self.bottom
            self.bottom = self.front
            self.front = pre_top
        elif command == "R":
            pre_front = self.front
            self.front = self.left
            self.left = self.back
            self.back = self.right
            self.right = pre_front


def main() -> None:
    dice_x = Dice(list(map(int, input().split())))
    dice_y = Dice(list(map(int, input().split())))

    for i in range(4):
        dice_x.rotate("N")
        for j in range(4):
            dice_x.rotate("E")
            for k in range(4):
                dice_x.rotate("R")

                if dice_x.top != dice_y.top:
                    pass
                elif dice_x.bottom != dice_y.bottom:
                    pass
                elif dice_x.left != dice_y.left:
                    pass
                elif dice_x.right != dice_y.right:
                    pass
                elif dice_x.front != dice_y.front:
                    pass
                elif dice_x.back != dice_y.back:
                    pass
                else:
                    print("Yes")
                    return

    print("No")


if __name__ == "__main__":
    main()

Solution (Python):


from collections import Counter
 
class Dice:
    def __init__(self, *num):
        if len(num) != 6:
            raise ValueError("6!")
        self.numbers = num
 
    def east(self):
        index = (3, 1, 0, 5, 4, 2)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def west(self):
        index = (2, 1, 5, 0, 4, 3)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def south(self):
        index = (4, 0, 2, 3, 5, 1)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def north(self):
        index = (1, 5, 2, 3, 0, 4)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def rot_top(self):
        """topを変えないように時計周りにくるくる回す"""
        index = (0, 2, 4, 1, 3, 5)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    @property
    def top(self):
        return self.numbers[0]
 
    @property
    def front(self):
        return self.numbers[1]
 
    @property
    def right(self):
        return self.numbers[2]
 
    def __repr__(self):
        return "Dice(" + ", ".join([str(i) for i in self.numbers]) + ")"
 
 
    def align_top_and_front(self, tmp_dice):
        
        rarest = Counter(self.numbers).most_common()[-1][0]
        for i in range(4):
            if self.top == rarest:
                break
            self.east()
        for i in range(4):
            if self.top == rarest:
                break
            self.north()
 
        
        for i in range(4):
            if self.top == tmp_dice.top:
                break
            tmp_dice.east()
 
        for i in range(4):
            if self.top == tmp_dice.top:
                break
            tmp_dice.north()
 
        
        for i in range(4):
            if self.front == tmp_dice.front:
                break
            tmp_dice.rot_top()
        return tmp_dice
 
 
    def align(self, other_dice):
        tmp = Dice(*other_dice.numbers)
        tmp = self.align_top_and_front(tmp)
        
        
        if self.numbers == tmp.numbers:
            print("Yes")
        else:
            print("No")
 
 
def main():
    num = [int(i) for i in input().split()]
    dice = Dice(*num)
 
    num = [int(i) for i in input().split()]
    other_dice = Dice(*num)
 
    Dice.align(dice, other_dice)
 
if __name__ == "__main__":
    main()

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

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

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

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

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

    def IsEqual(self, dice2):
        if (self.top, self.south, self.east, self.west, self.north, self.bottom) == (dice2.top, dice2.south, dice2.east, dice2.west, dice2.north, dice2.bottom):
            return True
        else:
            return False


n1 = list(map(int, input().split()))
n2 = list(map(int, input().split()))

dice_1 = Dice(n1)
dice_2 = Dice(n2)

flag = False

for i in range(4):
    dice_1.roll_n()
    for j in range(4):
        dice_1.roll_e()
        if dice_1.IsEqual(dice_2):
            flag = True

dice_1.roll_e()

for i in range(4):
    dice_1.roll_n()
    for i in range(4):
        dice_1.roll_e()
        if dice_1.IsEqual(dice_2):
            flag = True



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

Solution (Python):
class Dice:
    __TOP = 0
    __FRONT = 1
    __RIGHT = 2
    __LEFT = 3
    __BACK = 4
    __BOTTOM = 5

    def __init__(self, face_val=None):
        self.f_keys = [self.__TOP,  
                       self.__FRONT,  
                       self.__RIGHT,  
                       self.__LEFT,  
                       self.__BACK,  
                       self.__BOTTOM  
                       ]

        if face_val is None or len(face_val) != 6:
            face_val = ['1', '2', '3', '4', '5', '6']

        self.f_key_to_val = {}
        self.f_val_to_key = {}
        for f_key, val in zip(self.f_keys, face_val):
            self.f_key_to_val[f_key] = val
            self.f_val_to_key[val] = f_key

    MOVE_SWAP_FACES = {
        'S': [(__BACK, __TOP), (__TOP, __FRONT), (__FRONT, __BOTTOM), (__BOTTOM, __BACK)],
        'W': [(__RIGHT, __TOP), (__TOP, __LEFT), (__LEFT, __BOTTOM), (__BOTTOM, __RIGHT)],
        'E': [(__LEFT, __TOP), (__TOP, __RIGHT), (__RIGHT, __BOTTOM), (__BOTTOM, __LEFT)],
        'N': [(__FRONT, __TOP), (__TOP, __BACK), (__BACK, __BOTTOM), (__BOTTOM, __FRONT)],
        'RCW' : [(__LEFT, __FRONT), (__FRONT, __RIGHT), (__RIGHT, __BACK), (__BACK, __LEFT)],   
        'RCCW': [(__RIGHT, __FRONT), (__FRONT, __LEFT), (__LEFT, __BACK), (__BACK, __RIGHT)],   
    }

    def dice_move(self, direction_list):
        for direction in direction_list:
            prev_faces = self.f_keys[:]
            for prev_f, next_f in self.MOVE_SWAP_FACES[direction]:
                self.f_keys[next_f] = prev_faces[prev_f]
            

    MOVE_TO_TOP = {__TOP:[], __FRONT:['N'], __RIGHT:['W'], __LEFT:['E'], __BACK:['S'], __BOTTOM:['N','N']}

    def dice_fix(self, top, front):
        if type(top) == str:
            top = self.f_val_to_key[top]
            front = self.f_val_to_key[front]

        
        if top != self.f_keys[self.__TOP]:
            now_top = self.f_keys.index(top)
            move = self.MOVE_TO_TOP[now_top]
            self.dice_move(move)

        if top != self.f_keys[self.__TOP]:
            raise AssertionError 

        
        if front != self.f_keys[self.__FRONT]:
            for i in range(3):
                self.dice_move(['RCW'])
                if front == self.f_keys[self.__FRONT]:
                    break
            else:
                return False    
        return True

    def get_value(self, face):
        return self.f_key_to_val[self.f_keys[face]]

    def is_identical(self, other) -> bool:
        
        self_values = [self.get_value(x) for x in self.f_keys]
        other_values = [other.get_value(x) for x in other.f_keys]
        if set(self_values) != set(other_values):
            return False

        
        other_top = other.get_value(self.__TOP)
        other_front = other.get_value(self.__FRONT)
        ret = self.dice_fix(other_top, other_front)
        if not ret:
            return False

        
        for i in range(6):
            a1 = self.get_value(i)
            a2 = other.get_value(i)

            if self.get_value(i) != other.get_value(i):
                return False

        return True


    def __repr__(self):
        return f'({",".join(map(str, self.f_keys))})'


def main():
    d1_faces = input().split()
    dice1 = Dice(d1_faces)
    d2_faces = input().split()
    dice2 = Dice(d2_faces)
    print(['No','Yes'][dice1.is_identical(dice2)])

main()

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.diceNum: List[int] = [] 

    def setNum(self,i):
        self.pos = i[0]
        self.diceNum.append(i[0])
        self.diceNum.append(i[1])
        self.diceNum.append(i[2])
        self.diceNum.append(i[3])
        self.diceNum.append(i[4])
        self.diceNum.append(i[5])
    def getTopPos(self):
        return self.diceNum[0]    
    def moveToTopnum(self,n):
        i = 0
        for i in range(0,4):
            if (self.getTopPos() == n ):
                return True
            self.move("S")
        else:
            for j in range(0,4):
                if (self.getTopPos() == n ):
                    return True
                self.move("E")
        return False
    def getFrontPos(self):
        return self.diceNum[1]
    def getRightPos(self):
        return self.diceNum[2]
    def yokoRotate(self):
            i0=self.diceNum[0]
            i1=self.diceNum[2] 
            i2=self.diceNum[4] 
            i3=self.diceNum[1]
            i4=self.diceNum[3]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
    def move(self,d):
        if (d == "E"):
            i0=self.diceNum[3]
            i1=self.diceNum[1] 
            i2=self.diceNum[0] 
            i3=self.diceNum[5]
            i4=self.diceNum[4]
            i5=self.diceNum[2]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "W"):
            i0=self.diceNum[2]
            i1=self.diceNum[1] 
            i2=self.diceNum[5] 
            i3=self.diceNum[0]
            i4=self.diceNum[4]
            i5=self.diceNum[3]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "S"):
            i0=self.diceNum[4]
            i1=self.diceNum[0] 
            i2=self.diceNum[2] 
            i3=self.diceNum[3]
            i4=self.diceNum[5]
            i5=self.diceNum[1]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "N"):
            i0=self.diceNum[1]
            i1=self.diceNum[5] 
            i2=self.diceNum[2] 
            i3=self.diceNum[3]
            i4=self.diceNum[0]
            i5=self.diceNum[4]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
    def rotateToFrontnum(self,n):
        for i in range(0,4):
            self.yokoRotate()
            if ( self.getFrontPos() == n):
                return True
        return False
    def isEqual(self,d):
        for i in range(0,6):
            if (self.diceNum[i] != d.diceNum[i]):
                return False
        return True

 
l = list(map(int,input().split()))
dice = Dice()
dice.setNum(l)

min = 10000
r_num = 0
for i in set(l):
    if (min > l.count(i)):
       min = l.count(i)
       r_num = i
dice.moveToTopnum(r_num)


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

t = dice.getTopPos()
f = dice.getFrontPos()
r = dice.getRightPos()

if (dice2.moveToTopnum(t) != True):
    print ("No")

elif (dice2.rotateToFrontnum(f) != True):
    print ("No")


elif (dice.isEqual(dice2) == False ):
    print ("No")

else:
    print ("Yes")

Solution (Python):
d1=input().split()
d2=input().split()

def roll(Dice,Vector):
    if Vector == "N":
        c=Dice[0]
        Dice[0]=Dice[1]
        Dice[1]=Dice[5]
        Dice[5]=Dice[4]
        Dice[4]=c
    elif Vector == "W":
        c=Dice[0]
        Dice[0]=Dice[2]
        Dice[2]=Dice[5]
        Dice[5]=Dice[3]
        Dice[3]=c
    elif Vector == "E":
        c=Dice[0]
        Dice[0]=Dice[3]
        Dice[3]=Dice[5]
        Dice[5]=Dice[2]
        Dice[2]=c
    elif Vector == "S":
        c=Dice[0]
        Dice[0]=Dice[4]
        Dice[4]=Dice[5]
        Dice[5]=Dice[1]
        Dice[1]=c

v=list("NNNNWNNNWNNNENNNENNNWNNN")
f=0
for item in v:
    roll(d2,item)
    if d1==d2:
        print("Yes")
        f+=1
        break
if f==0:
    print("No")

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

slist = "NNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNN"

for s in slist:
    if s == "N":
        next = list("263415")
    elif s == "E":
        next = list("421653")
    elif s == "S":
        next = list("513462")
    else:
        next = list("326154")

    tmp = [0] * 6
    for i, n in enumerate(next):
        tmp[i] = dice[int(n)-1]

    dice = tmp

    if dice == dice2:
        print("Yes")
        exit()

print("No")

Solution (Python):
d=list(map(int,input().split()))
o=list(map(int,input().split()))
if o[0]==d[1]:
	d[0],d[1],d[4],d[5]=d[1],d[5],d[0],d[4]		
elif o[0]==d[2]:
	d[0],d[2],d[3],d[5]=d[2],d[5],d[0],d[3]
elif o[0]==d[3]:
	d[0],d[2],d[3],d[5]=d[3],d[0],d[5],d[2]	
elif o[0]==d[4]:
	d[0],d[1],d[4],d[5]=d[4],d[0],d[5],d[1]		
elif o[0]==d[5]:
	d[0],d[1],d[4],d[5]=d[5],d[4],d[1],d[0]
while o[1]!=d[1]:
	d[1],d[2],d[4],d[3]=d[3],d[1],d[2],d[4]
if d==o:
	print('Yes')
else:
	print('No')

Solution (Python):
d, d2 = [list(map(int, input().split())) for i in range(2)]  
from collections import OrderedDict
def make_p(d):
    p = OrderedDict()
    for k, v in zip(["T", "N", "S", "E", "W", "B"], [d[0], d[4], d[1], d[2], d[3], d[5]]):
        p[k] = v
    return p

p, p2 = make_p(d), make_p(d2)

for c in "SSSWNNNWNNNESSSWNNNESSSX":       
    t, n, s, e, w, b = p["T"], p["N"], p["S"], p["E"], p["W"], p["B"]
    if p == p2:
        print("Yes")
        break
    if c == "X":
        print("No")
    if c == "N":
        p["N"], p["T"], p["S"], p["B"]= t, s, b, n
    if c == "S":
        p["N"], p["T"], p["S"], p["B"]= b, n, t, s
    if c == "E":
        p["E"], p["T"], p["W"], p["B"]= t, w, b, e
    if c == "W":
        p["E"], p["T"], p["W"], p["B"]= b, e, t, w

Solution (Python):
def swap(dice,i,j,k,l):
    x=dice[l]
    dice[l]=dice[k]
    dice[k]=dice[j]
    dice[j]=dice[i]
    dice[i]=x
    return dice

def Sroll(dice):
    dice=swap(dice,0,1,5,4)
    return dice

def Eroll(dice):
    dice=swap(dice,0,2,5,3)
    return dice

def Wroll(dice):
    dice=swap(dice,0,3,5,2)
    return dice

def Nroll(dice):
    dice=swap(dice,0,4,5,1)
    return dice




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

top=dice1[0]
fro=dice1[1]

for j in range(0,8):
    if(fro==dice2[1]):
        break
    if(j==3):
        dice2=Eroll(dice2)
    dice2=Sroll(dice2)
while(top!=dice2[0]):
    dice2=Eroll(dice2)

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

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



class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.pattern = 'NNNNENNNENNNWNNNWNNNENNN'
        self.ret = 'No'
        
    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 match(self, Std):
        for i in range(6):
            self.work[i] = self.number[i]
        
        for i in range(len(self.pattern)):
            self.roll(self.pattern[i])
            if self.number == Std:
                self.ret = 'Yes'
                break
                
    def get_ret(self):
        return self.ret

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


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

dice.match(tableStd)
print("%s"%(dice.get_ret()))

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

for _ in range(4):
    b[0],b[4],b[5],b[1]=b[1],b[0],b[4],b[5]
    for _ in range(4):
        b[1],b[2],b[4],b[3]=b[3],b[1],b[2],b[4]
        for _ in range(4):
            b[0],b[4],b[5],b[1]=b[1],b[0],b[4],b[5]
            if a==b:
                print('Yes')
                exit()
print('No')

Solution (Python):
class Dice :
    def __init__(self, pane):
        self.pane = pane
    
    def roll_W(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[2]
        self.pane[2] = self.pane[5]
        self.pane[5] = self.pane[3]
        self.pane[3] = temp

    def roll_S(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[4]
        self.pane[4] = self.pane[5]
        self.pane[5] = self.pane[1]
        self.pane[1] = temp
    
dice1 = Dice(input().split())
dice2 = Dice(input().split())

flag = True

while True:
    t = dice1.pane[0]
    f = dice1.pane[1]
    if (dice2.pane[0] == f or dice2.pane[4] == f):
        dice2.roll_S()
    if (dice2.pane[0] == t and dice2.pane[1] == f):
        break
    dice2.roll_W()

for i in range(0, len(dice1.pane)):
    if (dice1.pane[i] != dice2.pane[i]):
        flag = False
        break

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

Solution (Python):



class Dice:
    def __init__(self,dice):
        self.dice = dice
    def n_roll(self):
        self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
    def s_roll(self):
        self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
    def e_roll(self):
        self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]
    def w_roll(self):
        self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
    def r_spin(self):
        self.dice = [self.dice[0],self.dice[2],self.dice[4],self.dice[1],self.dice[3],self.dice[5]]

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))
flag = 0
for i in range(4):
        dice1.n_roll()
        for j in range(4):
            dice1.r_spin()
            if dice2.dice == dice1.dice:
                flag = 1
for i in range(4):
        dice1.w_roll()
        for j in range(4):
            dice1.r_spin()
            if dice2.dice == dice1.dice:
                flag = 1


if flag == 1:
    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, pip):
        self.pip = pip
    
    def move(self, dir):
        if str(dir) == 'E':
            self.pip[0], self.pip[2], self.pip[3], self.pip[5] = \
                self.pip[3], self.pip[0], self.pip[5], self.pip[2]
        elif str(dir) == 'W':
            self.pip[0], self.pip[2], self.pip[3], self.pip[5] = \
                self.pip[2], self.pip[5], self.pip[0], self.pip[3]
        elif str(dir) == 'N':
            self.pip[0], self.pip[1], self.pip[4], self.pip[5] = \
                self.pip[1], self.pip[5], self.pip[0], self.pip[4]
        elif str(dir) == 'S':
            self.pip[0], self.pip[1], self.pip[4], self.pip[5] = \
                self.pip[4], self.pip[0], self.pip[5], self.pip[1]


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

check = "No"
for x in "EEENEEENEEESEEESEEENEEEN":
    if d1.pip == d2.pip:
        check = "Yes"
        break
    d2.move(x)
print(check)

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

    def toN(self):
        tmp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = tmp

    def toS(self):
        tmp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = tmp

    def toE(self):
        tmp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = tmp

    def toW(self):
        tmp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = tmp

    def moveTo(self, ds):
        for d in ds:
            if   d == 'N':
                self.toN()
            if d == 'S':
                self.toS()
            if d == 'E':
                self.toE()
            if d == 'W':
                self.toW()

    def getTop(self):
        return self.top

    def getBottom(self):
        return self.bottom

    def getFront(self):
        return self.front

    def getBack(self):
        return self.back

    def getLeft(self):
        return self.left

    def getRight(self):
        return self.right

    def __eq__(self, other):
        if self.top != other.top:
            return False
        if self.bottom != other.bottom:
            return False
        if self.front != other.front:
            return False
        if self.back != other.back:
            return False
        if self.left != other.left:
            return False
        if self.right != other.right:
            return False

        return True

def moveTo(dice, top, front):
    if dice.getFront() != front:
        if   dice.getTop()    == front:
            dice.moveTo("S")
        elif dice.getBottom() == front:
            dice.moveTo("N")
        elif dice.getBack()   == front:
            dice.moveTo("NN")
        elif dice.getLeft()   == front:
            dice.moveTo("ES")
        elif dice.getRight()  == front:
            dice.moveTo("WS")

    if dice.getTop() != top:
        if   dice.getBottom() == top:
            dice.moveTo("EE")
        elif dice.getLeft()   == top:
            dice.moveTo("E")
        elif dice.getRight()  == top:
            dice.moveTo("W")

    return dice

def equalDice(dice1, dice2):
    dice2 = moveTo(dice2, dice1.getTop(), dice1.getFront())
    return dice1 == dice2

def main():
    dice1 = Dice(input().split())
    dice2 = Dice(input().split())

    if equalDice(dice1, dice2):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP":top, "FRONT":front, "LEFT":left, "RIGHT":right, "BACK":back, "BOTTOM":bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")
  
  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")
  
  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")
  
  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = \
    self.d[b], self.d[c], self.d[d], self.d[a]
  
  def all_rolls(self):
    ret = []
    for i in range(6):
      if i%2:
        self.roll_x()
      else:
        self.roll_y()
      for j in range(4):
        self.roll_z()
        t = self.d.copy()
        ret.append(t)
    return ret

  def equivalent(self, dice):
    for i in range(6):
      if i%2:
        self.roll_x()
      else:
        self.roll_y()
      for j in range(4):
        self.roll_z()
        t = self.d.copy()
        if t==dice.d:
          return True
    return False

d1 = list(map(int, input().split()))
dd1 = Dice(d1[0], d1[1], d1[3], d1[2], d1[4], d1[5])
d2 = list(map(int, input().split()))
dd2 = Dice(d2[0], d2[1], d2[3], d2[2], d2[4], d2[5])
if dd1.equivalent(dd2):
  print("Yes")
else:
  print("No")

Solution (Python):
class Dice:
	
	def __init__(self, nums):
		self.nums = nums
		self.cU = nums[0]
		self.cS = nums[1]
		self.cE = nums[2]
		self.cW = nums[3]
		self.cN = nums[4]
		self.cD = nums[5]
	def goN(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pS,pD,pU,pN
	def goE(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pW,pU,pD,pE
	def goW(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pE,pD,pU,pW
	def goS(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pN,pU,pD,pS
	def toU(self, num):
		if self.cD == num:
			for _ in range(2): self.goN()
		elif self.cN == num: self.goS()
		elif self.cE == num: self.goW()
		elif self.cW == num: self.goE()
		elif self.cS == num: self.goN()
	def right(self, num):
		if self.cN == num: return self.cW
		elif self.cE == num: return self.cN
		elif self.cW == num: return self.cS
		elif self.cS == num: return self.cE
		else: raise 
di1 = Dice([int(i) for i in input().split(' ')])
di2 = Dice([int(i) for i in input().split(' ')])
for i in di1.nums:
	if di2.nums.count(i) == 1:
		di1.toU(i)
		di2.toU(i)
		break
if di1.cU == di2.cU and di1.cD == di2.cD:
	nesw1 = ''.join(list(map(str, [di1.cN,di1.cE,di1.cS,di1.cW])))
	nesw1 += nesw1
	nesw2 = ''.join(list(map(str, [di2.cN,di2.cE,di2.cS,di2.cW])))
	if nesw1.count(nesw2) > 0: print('Yes')
	else: print('No')
else: print('No')