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:
    index_list_map = [[[-1],[2,3,4,5],[4,1,3,5],[1,4,2,5],[3,2,1,5],[-1]],
                      [[3,2,5,4],[-1],[0,5,3,4],[5,0,2,4],[-1],[2,3,0,4]],
                      [[1,4,5,3],[5,0,4,3],[-1],[-1],[0,5,1,3],[4,1,0,3]],
                      [[4,1,5,2],[0,5,4,2],[-1],[-1],[5,0,1,2],[1,4,0,2]],
                      [[2,3,5,1],[-1],[5,0,3,1],[0,5,2,1],[-1],[3,2,0,1]],
                      [[-1],[3,2,4,0],[1,4,3,0],[4,1,2,0],[2,3,1,0],[-1]]]

    def __init__(self,list):
        self.num = list

    def lookup_east_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][0]]


    def lookup_west_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][1]]

    def lookup_north_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][2]]

    def lookup_down_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][3]]

spots1 = map(int,raw_input().split())
spots2 = map(int,raw_input().split())

s2_index_u = [ i for i,x in enumerate(spots2) if x == spots1[0]]
s2_index_s = [ i for i,x in enumerate(spots2) if x == spots1[1]]

combinations_u_s = [ [x,y] for x in s2_index_u for y in s2_index_s if x != y and (abs(x-2.5) != abs(y-2.5))]

dice2 = Dice(spots2)

for comb in  combinations_u_s :
    e = dice2.lookup_east_side(comb[0],comb[1])
    w = dice2.lookup_west_side(comb[0],comb[1])
    n = dice2.lookup_north_side(comb[0],comb[1])
    d = dice2.lookup_down_side(comb[0],comb[1])

    if e == spots1[2] and w == spots1[3] and n == spots1[4] and d == spots1[5]:
        print "Yes"
        quit()
print "No"

Solution (Python):
class Dice:
    index_list_map = [[[-1],[2,3,4,5],[4,1,3,5],[1,4,2,5],[3,2,1,5],[-1]],
                      [[3,2,5,4],[-1],[0,5,3,4],[5,0,2,4],[-1],[2,3,0,4]],
                      [[1,4,5,3],[5,0,4,3],[-1],[-1],[0,5,1,3],[4,1,0,3]],
                      [[4,1,5,2],[0,5,4,2],[-1],[-1],[5,0,1,2],[1,4,0,2]],
                      [[2,3,5,1],[-1],[5,0,3,1],[0,5,2,1],[-1],[3,2,0,1]],
                      [[-1],[3,2,4,0],[1,4,3,0],[4,1,2,0],[2,3,1,0],[-1]]]

    def __init__(self,list):
        self.num = list

    def lookup_east_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][0]]


    def lookup_west_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][1]]

    def lookup_north_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][2]]

    def lookup_down_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][3]]

    def is_same(self,dice):
        index_u = [ i for i,x in enumerate(dice.num) if x == self.num[0]]
        index_s = [ i for i,x in enumerate(dice.num) if x == self.num[1]]

        combinations_u_s = [ [x,y] for x in index_u for y in index_s if x != y and (abs(x-2.5) != abs(y-2.5))]
        for comb in  combinations_u_s :
            e = dice.lookup_east_side(comb[0],comb[1])
            w = dice.lookup_west_side(comb[0],comb[1])
            n = dice.lookup_north_side(comb[0],comb[1])
            d = dice.lookup_down_side(comb[0],comb[1])
            if e == self.num[2] and w == self.num[3] and n == self.num[4] and d == self.num[5]:
                return True
        return False

spots1 = map(int,raw_input().split())
spots2 = map(int,raw_input().split())

dice1 = Dice(spots1)
dice2 = Dice(spots2)

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

Solution (Python):
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]
        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    def judge(self,dice_2):
        T={0:'N',1:'E',2:'S',3:'W'}
        m=[dice_2.s,dice_2.w,dice_2.n,dice_2.e,dice_2.f,dice_2.b]
        for i in range(6):
            if m[i]==self.f:
                if i==4:temp=dice_2
                elif i==5:temp=Dice(Dice(dice_2.create('N')).create('N'))
                else:temp=Dice(dice_2.create(T[i]))

                if self.b==temp.b:
                        side_1=''.join(list(map(str,[self.s,self.w,self.n,self.e])))*2
                        side_2=''.join(list(map(str,[temp.s,temp.w,temp.n,temp.e])))
                        if side_2 in side_1:return 'Yes'
        return 'No'
num_1=list(map(int,input().split()))
num_2=list(map(int,input().split()))
dice_1=Dice(num_1)
dice_2=Dice(num_2)
print(dice_1.judge(dice_2))

Solution (Python):
class Dice:
    def __init__(self, init_values = ['1','2','3','4','5','6']):
        self.value = dict(zip(["top", "front","right","left","back","bottom"]\
                             , init_values))

    
    def roll(self, direction):
        if direction == 'N':
            self.value["top"], self.value["front"], self.value["bottom"], self.value["back"] = \
            self.value["front"], self.value["bottom"], self.value["back"], self.value["top"]
        elif direction == 'S':
            self.value["top"], self.value["back"], self.value["bottom"], self.value["front"] = \
            self.value["back"], self.value["bottom"], self.value["front"], self.value["top"]
        elif direction == 'E':
            self.value["top"], self.value["left"], self.value["bottom"], self.value["right"] = \
            self.value["left"], self.value["bottom"], self.value["right"], self.value["top"]
        elif direction == 'W':
            self.value["top"], self.value["right"], self.value["bottom"], self.value["left"] = \
            self.value["right"], self.value["bottom"], self.value["left"], self.value["top"]
        else:
            print("Error: illegal format.")

    
    def spin(self, direction):
        if direction == "CW":
            self.value["front"], self.value["right"], self.value["back"], self.value["left"] = \
            self.value["right"], self.value["back"], self.value["left"], self.value["front"]
        elif direction == "CCW":
            self.value["front"], self.value["left"], self.value["back"], self.value["right"] = \
            self.value["left"], self.value["back"], self.value["right"], self.value["front"]
        else:
            print("Error: illegal format.")
            
dice1 = Dice(input().split())
dice2 = Dice(input().split())

result = "No"
for direction in 'SESESE':
    dice2.roll(direction)
    if dice1.value["top"] == dice2.value["top"]:
        for j in range(4):
            dice2.spin("CW")
            if dice1.value == dice2.value:
                result = "Yes"
                break

print(result)

Solution (Python):

class Dice:
    def __init__(self, label):
        self.d = label

    def roll(self, direction):
        if direction == "N":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[1], self.d[5], self.d[4], self.d[0]
        elif direction == "S":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[4], self.d[0], self.d[1], self.d[5]
        elif direction == "E":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[3], self.d[0], self.d[2], self.d[5]
        elif direction == "W":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[2], self.d[5], self.d[3], self.d[0]
        else:
            pass

label = [int(i) for i in input().split()]
label2 = [int(i) for i in input().split()]

dice1 = Dice(label)
dice2 = Dice(label2)


cmd = "N" * 4 + ("W" + "N" * 4) * 3 + "NE" + "N" * 4 + "EE" + "N" * 4 

for i in cmd:
    dice2.roll(i)

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

Solution (Python):
class Dice:
    def __init__(self, men):
        self.men = men

    def throw(self, direction):
        if direction == "E":
            pmen = men[:]
            men[0] = pmen[3]
            men[1] = pmen[1]
            men[2] = pmen[0]
            men[3] = pmen[5]
            men[4] = pmen[4]
            men[5] = pmen[2]
        elif direction == "W":
            pmen = men[:]
            men[0] = pmen[2]
            men[1] = pmen[1]
            men[2] = pmen[5]
            men[3] = pmen[0]
            men[4] = pmen[4]
            men[5] = pmen[3]
        elif direction == "S":
            pmen = men[:]
            men[0] = pmen[4]
            men[1] = pmen[0]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[5]
            men[5] = pmen[1]
        elif direction == "N":
            pmen = men[:]
            men[0] = pmen[1]
            men[1] = pmen[5]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[0]
            men[5] = pmen[4]
        elif direction == "C":
            pmen = men[:]
            men[0] = pmen[0]
            men[1] = pmen[2]
            men[2] = pmen[4]
            men[3] = pmen[1]
            men[4] = pmen[3]
            men[5] = pmen[5]
        elif direction == "U":
            pmen = men[:]
            men[0] = pmen[0]
            men[1] = pmen[3]
            men[2] = pmen[1]
            men[3] = pmen[4]
            men[4] = pmen[2]
            men[5] = pmen[5]

men = map(int, (raw_input()).split(" "))
d1 = Dice(men)
men = map(int, (raw_input()).split(" "))
d2 = Dice(men)

flag = False

for i in range(4):
    d1.throw("W")
    for j in range(4):
        d1.throw("S")
        if d1.men == d2.men:
            flag = True

for i in range(4):
    d1.throw("C")
    for j in range(4):
        d1.throw("S")
        if d1.men == d2.men:
            flag = True

if flag:
    print "Yes"
else:
    print "No"

Solution (Python):
n1 = [int(i) for i in input().split()]
n2 = [int(i) for i in input().split()]


class Dice(object):
    def __init__(self,num):
        self.n = num[4]
        self.e = num[2]
        self.w = num[3]
        self.s = num[1]
        self.center = num[0]
        self.back = num[5]

    def number(self):
        number = [self.center, self.s, self.e, self.w, self.n, self.back]
        return number

    def move(self,str):
        if str == 'N':
            x = self.n
            self.n = self.center
            self.center = self.s
            self.s = self.back
            self.back = x
            return self.center
        elif str == 'S':
            x = self.s
            self.s = self.center
            self.center = self.n
            self.n = self.back
            self.back = x
            return self.center
        elif str== 'E':
            x = self.e
            self.e = self.center
            self.center = self.w
            self.w = self.back
            self.back = x
            return self.center
        elif str == 'W':
            x = self.w
            self.w = self.center
            self.center = self.e
            self.e = self.back
            self.back = x
            return self.center

dice1 = Dice(n1)
dice2 = Dice(n2)
bool = False
status = dice1.center


for i in range(4):
    for j in range(4):
        for k in range(4):
            
            if dice1.number() == dice2.number():
                bool = True
            else:
                dice1.move('N')
                dice1.move('E')
                dice1.move('S')
        dice1.move('E')
    dice1.move('N')




print('Yes') if bool == True else print('No')

Solution (Python):
class Dice:

    __top = 0
    __front = 1
    __right = 2
    __left = 3
    __back = 4
    __bottom = 5

    def __init__(self, a, b, c, d, e, f):
        self.__dice = [a,b,c,d,e,f]

    def S(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__back]
        self.__dice[Dice.__front]  = dice_before[Dice.__top]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__bottom] = dice_before[Dice.__front]

    def E(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__left]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__top]
        self.__dice[Dice.__left]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__right]

    def W(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__right]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__left]   = dice_before[Dice.__top]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__left]

    def N(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__front]
        self.__dice[Dice.__front]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__top]
        self.__dice[Dice.__bottom] = dice_before[Dice.__back]

    def turn(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__top]
        self.__dice[Dice.__front]  = dice_before[Dice.__right]
        self.__dice[Dice.__right]  = dice_before[Dice.__back]
        self.__dice[Dice.__left]   = dice_before[Dice.__front]
        self.__dice[Dice.__back]   = dice_before[Dice.__left]
        self.__dice[Dice.__bottom] = dice_before[Dice.__bottom]

    def top(self):
        return(self.__dice[Dice.__top])

    def front(self):
        return(self.__dice[Dice.__front])

    def right(self):
        return(self.__dice[Dice.__right])

    def left(self):
        return(self.__dice[Dice.__left])

    def back(self):
        return(self.__dice[Dice.__back])

    def bottom(self):
        return(self.__dice[Dice.__bottom])

    def compare(self, dice):
        if (self.__dice[Dice.__top]    == dice.__dice[Dice.__top] and
            self.__dice[Dice.__front]  == dice.__dice[Dice.__front] and
            self.__dice[Dice.__right]  == dice.__dice[Dice.__right] and
            self.__dice[Dice.__left]   == dice.__dice[Dice.__left] and
            self.__dice[Dice.__back]   == dice.__dice[Dice.__back] and
            self.__dice[Dice.__bottom] == dice.__dice[Dice.__bottom]):
            print("Yes")
        else:
            print("No")

    def print(self):
        print('[top   ] :', self.__dice[Dice.__top])
        print('[front ] :', self.__dice[Dice.__front])
        print('[right ] :', self.__dice[Dice.__right])
        print('[left  ] :', self.__dice[Dice.__left])
        print('[back  ] :', self.__dice[Dice.__back])
        print('[bottom] :', self.__dice[Dice.__bottom])


def S(dice, top):
    for t in range(4):
        if dice.top() == top:
            return dice
        dice.S()
    return dice

def turn(dice, front):
    for t in range(4):
        if dice.front() == front:
            return dice
        dice.turn()
    return dice

a, b, c, d, e, f = input().split()
dice1 = Dice(a, b, c, d, e, f)

top = max(a,b,c,d,e,f)
dice1 = S(dice1, top)
a,b,c,d,e,f = input().split()
dice2 = Dice(a,b,c,d,e,f)

top = dice1.top()
front = dice1.front()

for to in range(2):
    dice2 = S(dice2, top)
    if dice2.top() == top:
        break
    else:
        dice2.turn()

for fr in range(4):
    dice2 = turn(dice2, front)
    if dice2.front() == front:
        break

dice1.compare(dice2)

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.top = 1
        self.front = 2
        self.right = 3

    def get_top(self):
        return eval("self." + 'l' + str(self.top))

    def get_right(self):
        return eval("self." + 'l' + str(self.right))

    def get_front(self):
        return eval("self." + 'l' + str(self.front))

    def get_bottom(self):
        return eval("self." + 'l' + str(7-self.top))

    def get_left(self):
        return eval("self." + 'l' + str(7-self.right))

    def get_back(self):
        return eval("self." + 'l' + str(7-self.front))

    def rot(self):
        self.front,self.right = self.right,7-self.front

    def move(self, order):
        if order == 'S':
            pretop = self.top
            self.top = 7 - self.front
            self.front = pretop
        elif order == 'E':
            pretop = self.top
            self.top = 7 - self.right
            self.right = pretop


def match_top(dice,target):
    for i in range(4):
        dice.move('S')
        if dice.get_top() == target:
            return dice
    return False


l = list(map(int,input().split()))
d1 = Dice(l[0],l[1],l[2],l[3],l[4],l[5])

l = list(map(int,input().split()))
d2 = Dice(l[0],l[1],l[2],l[3],l[4],l[5])

d1_top = d1.get_top()
d1_front = d1.get_front()
d1_right = d1.get_right()
d1_bottom = d1.get_bottom()
d1_back = d1.get_back()
d1_left = d1.get_left()
ret = match_top(d2,d1_top)

if ret == False:
    d2.move('E')
    ret = match_top(d2,d1_top)
if ret == False:
    print('No')
else:
    matched = False
    for i in range(4):
        d2.rot()
        if d2.get_front() == d1_front and \
        d2.get_right() == d1_right and \
        d2.get_bottom() == d1_bottom and \
        d2.get_left() == d1_left and \
        d2.get_back() == d1_back:
            matched = True
            print ('Yes')
            break
    if not matched:
        print('No')

Solution (Python):
def move(d, r):
    if r == 'N':
        return (d[1], d[5], d[2], d[3], d[0], d[4])
    if r == 'E':
        return (d[3], d[1], d[0], d[5], d[4], d[2])
    if r == 'W':
        return (d[2], d[1], d[5], d[0], d[4], d[3])
    if r == 'S':
        return (d[4], d[0], d[2], d[3], d[5], d[1])
    return d
     
dice_1 = tuple(map(str,input().split()))
dice_2 = tuple(map(str,input().split()))

def gen_all(dice_1):
    dice = {dice_1}
    while True:
        dice2 = {move(d,r) for d in dice for r in list("NEWS")}.union(dice)
        if dice == dice2: break
        dice = dice2
    return dice    

print("Yes" if dice_2 in gen_all(dice_1) else "No")

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

def rot(dice,rotation):
    if rotation == "E":
        dice = (dice[3],dice[1],dice[0],dice[5],dice[4],dice[2])
    elif rotation == "W":
        dice = (dice[2],dice[1],dice[5],dice[0],dice[4],dice[3])
    elif rotation == "N":
        dice = (dice[1],dice[5],dice[2],dice[3],dice[0],dice[4])
    elif rotation == "S":
        dice = (dice[4],dice[0],dice[2],dice[3],dice[5],dice[1])
    return dice

def make_all_pattern(dice):
    pattern = {dice}
    pattern2 = pattern
    while True:
        pattern2 = pattern.union({rot(d,r) for d in pattern for r in list("NEWS")})
        if pattern2 == pattern:
            break
        pattern = pattern2
    return pattern

dice2 = tuple(map(int,input().split()))

if dice2 in make_all_pattern(dice):
    print("Yes")
else:
    print("No")

Solution (Python):


import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def main():
    die1 = init_die()
    die2 = init_die()

    if sorted(die1.pips) != sorted(die2.pips):
        print('No')
    else:
        for idx, pip in enumerate(die2.pips):
            for spin in range(4):
                if die1.pips == die2.pips:
                    print('Yes')
                    sys.exit(0)
                else:
                    die1.spin_die_clockwise()
            if idx in {0, 1, 2}:
                die1.move_die('N')
            if idx in {3}:
                die1.move_die('N')
                die1.move_die('E')
            if idx in {4}:
                die1.move_die('E')
                die1.move_die('E')

        print('No')


if __name__ == '__main__':
    main()

Solution (Python):


import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def are_identical(die1, die2):
    if sorted(die1.pips) != sorted(die2.pips):
        return 'No'
    else:
        for idx, pip in enumerate(die2.pips):
            for spin in range(4):
                if die1.pips == die2.pips:
                    return 'Yes'
                else:
                    die1.spin_die_clockwise()
            if idx in {0, 1, 2}:
                die1.move_die('N')
            if idx in {3}:
                die1.move_die('N')
                die1.move_die('E')
            if idx in {4}:
                die1.move_die('E')
                die1.move_die('E')

        return 'No'


def main():
    die1 = init_die()
    die2 = init_die()
    print(are_identical(die1, die2))


if __name__ == '__main__':
    main()

Solution (Python):
class Dice():
	def __init__(self, label):
		self.d = label
		
	def __eq__(self, other):
		return (self.d[1] == other.d[1] and self.d[2] == other.d[2] and self.d[3] == other.d[3] and self.d[4] == other.d[4] and self.d[5] == other.d[5] and self.d[6] == other.d[6])
	
	def __ne__(self, other):
		return (self.d[1] != other.d[1] or self.d[2] != other.d[2] or self.d[3] != other.d[3] or self.d[4] != other.d[4] or self.d[5] != other.d[5] or self.d[6] != other.d[6])
	
	def roll(self, drt):
		if drt == 'N':
			self.d[1], self.d[2], self.d[6], self.d[5] = self.d[2], self.d[6], self.d[5], self.d[1]
		elif drt == 'E':
			self.d[1], self.d[3], self.d[6], self.d[4] = self.d[4], self.d[1], self.d[3], self.d[6]
		elif drt == 'S':
			self.d[2], self.d[6], self.d[5], self.d[1] = self.d[1], self.d[2], self.d[6], self.d[5]
		elif drt == 'W':
			self.d[4], self.d[1], self.d[3], self.d[6] = self.d[1], self.d[3], self.d[6], self.d[4]
		elif drt == 'r':
			self.d[2], self.d[3], self.d[5], self.d[4] = self.d[4], self.d[2], self.d[3], self.d[5]
		elif drt == 'l':
			self.d[4], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[3], self.d[5], self.d[4]
	
	def printl(self, lct):
		print(self.d[lct])
		
label = [0]	
label.extend(list(map(int, input().split())))
dice1 = Dice(label)

label2 = [0]
label2.extend(list(map(int, input().split())))
dice2 = Dice(label2)

S1 = 'NNNNENNNNENNNNENNNNrNNNNllNNNN'
leng = len(S1)

for j in range(leng):
		if dice1 == dice2:
			print("Yes")
			break
		dice2.roll(S1[j])

if dice1 != dice2:
	print("No")

Solution (Python):
A,B,C,D,E,F = map(int, input().split())
u,v,w,x,y,z = map(int, input().split())
s = 0
for _ in range(3):
    for _ in range(4):
        if A == u and B == v and C == w and D == x and E == y and F == z:
            s = 1
            break
        A,B,C,D,E,F = A,C,E,B,D,F 
    A,B,C,D,E,F = D,B,A,F,E,C 
    for _ in range(4):
        if A == u and B == v and C == w and D == x and E == y and F == z:
            s = 1
            break
        A,B,C,D,E,F = A,C,E,B,D,F 
    A,B,C,D,E,F = B,F,C,D,A,E 

if s == 0:
    print("No")
else:
    print("Yes")