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,dice):
        self.dice = dice

    def roll_n(self):
        d = self.dice
        self.dice = [d[1],d[5],d[2],d[3],d[0],d[4]]

    def roll_e(self):
        d = self.dice
        self.dice = [d[3],d[1],d[0],d[5],d[4],d[2]]

    def roll_s(self):
        d = self.dice
        self.dice = [d[4],d[0],d[2],d[3],d[5],d[1]]
    
    def roll_w(self):
        d = self.dice
        self.dice = [d[2],d[1],d[5],d[0],d[4],d[3]]

    def top(self):
        return self.dice[0]

    def roll(self,command):
        if command=='N':self.roll_n()
        if command=='E':self.roll_e()
        if command=='S':self.roll_s()
        if command=='W':self.roll_w()

    def same(self,b):
        com1 = 'SSSWSSSE'
        com2 = 'WWWW'
        for c in com1:
            if self.dice[1]==b.dice[1]:break
            if c=='E':return False
            b.roll(c)
        for c in com2:
            if self.dice==b.dice:return True
            b.roll(c)
        return False

def main():
    a = dice(list(map(int,input().split())))
    b = dice(list(map(int,input().split())))
    if a.same(b):print('Yes')
    else        :print('No')

if __name__ == '__main__':
    main()

Solution (Python):
import random 

def dice (a, b, c, d, e, f, l) :  

  if(l == "N") : 

    return [b, f, c, d, a, e] 

  elif (l == "S") : 

    return [e, a, c, d, f, b] 

  elif (l == "W") : 

    return [d, b, a, f, e, c] 

  else : 

    return [c, b, f, a, e, d] 

  

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

a, b, c, d, e, f = map(int, input().split()) 

L = ["N", "S", "W", "E"] 

  

cnt = 0 

  

while (cnt <= 10000) : 

  x = random.randrange(4)  

  d1 = dice(d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], L[x]) 

  

  if (d1[0] == a and d1[1] == b and d1[2] == c and d1[3] == d 

     and d1[4] == e and d1[5] == f) : 

    print("Yes") 

    break 

  elif (cnt == 10000) : 

    print ("No") 

    break 

  else : 

    cnt += 1

Solution (Python):
def dice(d, n):
    if n == 1:
        return d[1] + d[2] + d[4] + d[3]
    if n == 2:
        return d[0] + d[3] + d[5] + d[2]
    if n == 3:
        return d[0] + d[1] + d[5] + d[4]
    if n == 4:
        return d[0] + d[4] + d[5] + d[1]
    if n == 5:
        return d[0] + d[2] + d[5] + d[3]
    if n == 6:
        return d[1] + d[3] + d[4] + d[2]

d1 = input().split()
d2 = input().split()

for i in range(6):
    if d1[0] == d2[i] and d1[5] == d2[5-i] and dice(d2, i+1) in dice(d1, 1)*2:
        print('Yes')
        break
    if i == 5:
        print('No')

Solution (Python):
class Dice():
    
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.d1=d1
        self.d2=d2
        self.d3=d3
        self.d4=d4
        self.d5=d5
        self.d6=d6
    
    def roll(self,c):
        if c=='N':
            self.d1,self.d5,self.d6,self.d2=self.d2,self.d1,self.d5,self.d6
        elif c=='S':
            self.d1,self.d5,self.d6,self.d2=self.d5,self.d6,self.d2,self.d1
        elif c=='E':
            self.d1,self.d3,self.d6,self.d4=self.d4,self.d1,self.d3,self.d6
        elif c=='W':
            self.d1,self.d3,self.d6,self.d4=self.d3,self.d6,self.d4,self.d1
        elif c=='R':
            self.d2,self.d3,self.d5,self.d4=self.d4,self.d2,self.d3,self.d5
        elif c=='L':
            self.d2,self.d3,self.d5,self.d4=self.d3,self.d5,self.d4,self.d2
    
    def minnum(self):
        return min(self.d1,self.d2,self.d3,self.d4,self.d5,self.d6)
        
    def min2num(self):
        return min(self.d2,self.d3,self.d4,self.d5,self.d6)
        
    def rolling(self):
        m=self.minnum()
        if m==self.d3:
            self.roll('W')
        elif m==self.d6:
            self.roll('E')
            self.roll('E')
        elif m==self.d4:
            self.roll('E')
        elif m==self.d2:
            self.roll('N')
        elif m==self.d5:
            self.roll('S')
        m=self.min2num()
        if m==self.d3:
            self.roll('L')
        elif m==self.d5:
            self.roll('L')
            self.roll('L')
        elif m==self.d4:
            self.roll('R')
            
    def returnlist(self):
        l=[self.d1,self.d2,self.d3,self.d4,self.d5,self.d6]
        return l
    
a,b,c,d,e,f=map(int,input().split())
D=Dice(a,b,c,d,e,f)
a,b,c,d,e,f=map(int,input().split())
D2=Dice(a,b,c,d,e,f)
D.rolling()
D2.rolling()
if D.returnlist()==D2.returnlist():
    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):
        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 query(self,top_num,front_num):
        self.save_data =[i for i in range(6)]

        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
        
        return ret
    def get_Top(self):
        return self.number[0]
    
    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 :
                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):
import itertools
def get_dice():
    input_data = input().split(" ")
    items = [int(cont) for cont in input_data]
    keys = ['T', 'S', 'E', 'W', 'N', 'B']
    return dict(zip(keys, items))

def rot_dice(rot, dice):
    if rot == "N":
        keys = ['T', 'S', 'B', 'N']
        items = dice['S'], dice['B'], dice['N'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "S":
        keys = ['T', 'S', 'B', 'N']
        items = dice['N'], dice['T'], dice['S'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "E":
        keys = ['T', 'E', 'B', 'W']
        items = dice['W'], dice['T'], dice['E'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "W":
        keys = ['T', 'E', 'B', 'W']
        items = dice['E'], dice['B'], dice['W'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "R":
        keys = ['N', 'W', 'S', 'E']
        items = dice['E'], dice['N'], dice['W'], dice['S']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

def search_right_surf(conds, dice):
    a, b = conds
    a_key = [k for k, v in dice.items() if v == a]
    b_key = [k for k, v in dice.items() if v == b]
    key_list = a_key + b_key

    part_st = ''.join(key_list)

    def search(part_st):
        if part_st in "TNBST":
            return "W"

        if part_st in "TSBNT":
            return "E"

        if part_st in "TEBWT":
            return "N"

        if part_st in "TWBET":
            return "S"

        if part_st in "NESWN":
            return "B"

        if part_st in "NWSEN":
            return "T"

    target_key = search(part_st)
    print(dice[target_key])

def search_top_surf(top_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == top_surf]

    if dice2_surf == 'N':
        rot_dice("S", dice)

    if dice2_surf == 'B':
        controls = list("SS")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'S':
        controls = list("N")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'W':
        controls = list("E")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'E':
        controls = list("W")
        for i in controls:
            rot_dice(i, dice)

def search_flont_surf(flont_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == flont_surf]

    if dice2_surf == 'E':
        controls = list("R")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'S':
        controls = list("RR")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'W':
        controls = list("RRR")
        for i in controls:
            rot_dice(i, dice)

def perfect_rot_compare(dice1, dice2):

        def compare_dice():
            if dice1 == dice2:
                return True
        if compare_dice():
            return True
        Rs = ["", "R", "RR", "RRR", "RRRR"]
        Ns = ["", "N", "NN", "NNN", "NNNN"]
        Es = ["", "E", "EE", "EEE", "EEEE"]
        for i, j, k in itertools.product(Rs, Ns, Es):
            controls = list(i+j+k)
            for t in controls:
                rot_dice(t, dice2)
            if compare_dice():
                return True
        return False


def q1():

    dice=get_dice()
    controls = list(input())
    for i in controls:
        rot_dice(i, dice)
    print(dice["T"])

def q2():

    dice=get_dice()
    a = input()
    repeater = int(a)

    for neee in range(repeater):
        control_input = input().split(" ")
        conds = [int(i) for i in control_input]
        search_right_surf(conds, dice)

def q3():
    dice1 = get_dice()
    dice2 = get_dice()

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

def q4():
    inp = input()
    dice_num = int(inp)
    dice_list = list()
    for i in range(dice_num):
        dice_list.append(get_dice())

    def compare_many_dices():
        dice1 = dice_list[0]
        for dice in dice_list:
            if not perfect_rot_compare(dice1, dice):
                return False
        return True

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

q3()

Solution (Python):
def create_dice(nums):
    a, b, c, d, e, f = nums
    vertical = [a, b, f, e]
    horizontal = [b, c, e, d]
    return Dice(vertical, horizontal)


class Dice:
    def __init__(self, v, h):
        self.vertical = v
        self.horizontal = h

    def v2h(self):
        self.horizontal[0] = self.vertical[1]
        self.horizontal[2] = self.vertical[3]

    def h2v(self):
        self.vertical[1] = self.horizontal[0]
        self.vertical[3] = self.horizontal[2]

    def roll(self, direction):
        if direction == 'N':
            tmp1 = self.vertical[0]
            tmp2 = self.vertical[1:]
            self.vertical = tmp2 + [tmp1]
            self.v2h()
        elif direction == 'S':
            tmp1 = self.vertical[-1]
            tmp2 = self.vertical[:-1]
            self.vertical = [tmp1] + tmp2
            self.v2h()
        elif direction == 'E':
            tmp1 = self.horizontal[0]
            tmp2 = self.horizontal[1:]
            self.horizontal = tmp2 + [tmp1]
            self.h2v()
        elif direction == 'W':
            tmp1 = self.horizontal[-1]
            tmp2 = self.horizontal[:-1]
            self.horizontal = [tmp1] + tmp2
            self.h2v()


s1 = map(int, input().split(" "))
d1 = create_dice(s1)

s2 = map(int, input().split(" "))
d2 = create_dice(s2)


def match(l1, l2):
    lenlist = len(l1)
    lenset = len(set(l1))
    if lenlist == lenset:
        return l1[0] == l2[0]
    else:
        diff = 4 - (lenlist - lenset) + 1
        for i in range(diff):
            if l1[i] != l2[i]:
                return False
        return True

r = 0
while d1.vertical != d2.vertical and d1.horizontal != d2.horizontal and r < 4:
    
    d2.roll("E")

    v = 0
    while not match(d1.vertical, d2.vertical) and v < 4:
        d2.roll("N")
        v += 1

    h = 0
    while not match(d1.horizontal, d2.horizontal) and v < 4:
        d2.roll("E")
        h += 1

    r += 1

if d1.vertical == d2.vertical and d1.horizontal == d2.horizontal:
    print("Yes")
else:
    print("No")

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

    def setNum(self, n0, n1, n2, n3, n4, n5):
        self.d[0], self.d[1], self.d[2], self.d[3], self.d[4], self.d[5] = (
            n0,
            n1,
            n2,
            n3,
            n4,
            n5,
        )

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

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

flag = False
for i in list("NNNNWNNNWNNNENNNENNNWNNN"):
    d2.roll(i)
    if d1.d[0] == d2.d[0]:
        if d1.d == d2.d:
            flag = True

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

Solution (Python):
import random
class Dice:
    def __init__(self,top,front,right,left,back,bottom):
        self.top, self.bottom=top,bottom
        self.right, self.left=right,left
        self.front, self.back=front,back
    def turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
d1=map(int,raw_input().split())
d2=map(int,raw_input().split())
dice1=Dice(d1[0],d1[1],d1[2],d1[3],d1[4],d1[5])
dice2=Dice(d2[0],d2[1],d2[2],d2[3],d2[4],d2[5])
flg=0
for i in range(1000):
    d="NSWE"[random.randint(0,3)]
    dice1.turn(d)
    if dice1.top==dice2.top and dice1.front==dice2.front and dice1.right==dice2.right and dice1.left==dice2.left and dice1.back==dice2.back and dice1.bottom==dice2.bottom:
        print "Yes"
        flg=1
        break
if flg==0:
    print "No"

Solution (Python):
import copy


def move(lon, lat, com):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if com == "E" or com == "W":
        target, other = lat, lon
    if com == "S" or com == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    com = "N" if upper in lon else "E"
    for _i in range(4):
        move(lon, lat, com)
        if lon[0] == upper:
            break


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


longitude = [0, 1, 5, 4]
latitude = [0, 3, 5, 2]

values = list(input().split())
u, f = values[longitude[0] - 1], values[longitude[1] - 1]
values2 = list(input().split())
longitude2, latitude2 = copy.copy(longitude), copy.copy(latitude)
result = "No"
for i in range(6):
    set_upper(longitude2, latitude2, i)
    for j in range(4):
        rotate(longitude2, latitude2, "R")
        if values[0] != values2[longitude2[0]]:
            continue
        elif values[1] != values2[longitude2[1]]:
            continue
        elif values[2] != values2[latitude2[3]]:
            continue
        elif values[3] != values2[latitude2[1]]:
            continue
        elif values[4] != values2[longitude2[3]]:
            continue
        elif values[5] != values2[longitude2[2]]:
            continue
        else:
            result = "Yes"
            break
    if result == "Yes":
        break
print(result)

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 get_Top(self):
        return self.number[0]
        
    def query(self, top_num, front_num):
        self.save_data = [i for i in range(6)]
        for i in range(6):
            self.save_data[i] = self.number[i]
            
        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
            
        for i in range(6):
            self.number[i] = self.save_data[i]
            
        return ret
        
    def equals(self, another):
        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 False

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):
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.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 query(self,top_num,front_num):

        self.save_data = [i for i in range(6)]
        
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

        return ret

    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):
dice1 = input().split()
dice2 = input().split()

def rotate(faces, move):
    for i in range(len(move)):
        m = move[i]
        
        if m == "N":
            
            tmp = faces[4]
            faces[4] = faces[0]
            faces[0] = faces[1]
            faces[1] = faces[5]
            faces[5] = tmp
            
        elif m == "S":
            
            tmp = faces[1]
            faces[1] = faces[0]
            faces[0] = faces[4]
            faces[4] = faces[5]
            faces[5] = tmp
            
        elif m == "E":
            
            tmp = faces[2]
            faces[2] = faces[0]
            faces[0] = faces[3]
            faces[3] = faces[5]
            faces[5] = tmp
            
        elif m == "W":
            
            tmp = faces[3]
            faces[3] = faces[0]
            faces[0] = faces[2]
            faces[2] = faces[5]
            faces[5] = tmp





















        
def equals(a, b):
    for (a, b) in zip(dice1, dice2):
        if a != b:
            return False
            
    return True

isMatch = equals(dice1, dice2)

copy_list = dice1.copy()

looping = True
for j in range(4):
    
    if isMatch:
        break
    for i in range(4):
        
        rotate(dice1, "N")
        if equals(dice1, dice2):
            isMatch = True
            break
    
    
    rotate(dice1, "W")
    





rotate(dice1, "NW")

for j in range(4):
    
    if isMatch:
        break
    for i in range(4):
        
        rotate(dice1, "N")
        if equals(dice1, dice2):
            isMatch = True
            break
    
    
    rotate(dice1, "W")
    


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

Solution (Python):
class dice:
    def __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
    
    def W(s):
        tmp = s.d1
        s.d1 = s.d3
        s.d3 = s.d6
        s.d6 = s.d4
        s.d4 = tmp
        
    def E(s):
        tmp = s.d1
        s.d1 = s.d4
        s.d4 = s.d6
        s.d6 = s.d3
        s.d3 = tmp
        
    def N(s):
        tmp = s.d1
        s.d1 = s.d2
        s.d2 = s.d6
        s.d6 = s.d5
        s.d5 = tmp
        
    def S(s):
        tmp = s.d1
        s.d1 = s.d5
        s.d5 = s.d6
        s.d6 = s.d2
        s.d2 = tmp
        
    def L(s):
        tmp = s.d2
        s.d2 = s.d3
        s.d3 = s.d5
        s.d5 = s.d4
        s.d4 = tmp
        
    def isSame(s, d):
        flg = False
        
        
        for i in range(6):
            
            for j in range(6):
                if s.d1 == d.d1 and s.d6 == d.d6:
                    
                    for j in range(3):
                        if s.d2 == d.d2 and s.d3 == d.d3 and s.d4 == d.d4 and s.d5 == d.d5:
                            
                            return True
                        else:
                            
                            d.L()
                    
                
                if j <= 3:
                    d.N()
                elif j == 4:
                    d.E()
                else:
                    d.E()
                    d.E()
            
            
            if i <= 3:
                s.N()
            elif i == 4:
                s.E()
            else:
                s.E()
                s.E()
        
        
        return False
        
dice1 = dice(input().split())
dice2 = dice(input().split())
if dice1.isSame(dice2):
    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):
import sys

class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.NEWS = {"N": [0,4,5,1],
                     "E": [0,2,5,3],
                     "W": [0,3,5,2],
                     "S": [0,1,5,4],
                     "R": [1,2,4,3]}
       
    def move(self,aNEWS):
        idx = self.NEWS[aNEWS]
        tmp = self.LabelList[idx[0]]
        self.LabelList[idx[0]] = self.LabelList[idx[3]]
        self.LabelList[idx[3]] = self.LabelList[idx[2]]
        self.LabelList[idx[2]] = self.LabelList[idx[1]]
        self.LabelList[idx[1]] = tmp

def step2():
    for i in range(4):
        if Dise1.LabelList[1] == Dise2.LabelList[1] and \
           Dise1.LabelList[2] == Dise2.LabelList[2] and \
           Dise1.LabelList[3] == Dise2.LabelList[3] and \
           Dise1.LabelList[4] == Dise2.LabelList[4]:
            print("Yes")
            sys.exit()
        else:
            Dise2.move("R")
    print("No")
    sys.exit()

Dise1 = Dise(input().split())
Dise2 = Dise(input().split())

for i in range(4):
    if Dise1.LabelList[0] == Dise2.LabelList[0] and \
       Dise1.LabelList[5] == Dise2.LabelList[5]:
        step2()
    else:
        Dise2.move("E")

Dise2.move("N")
if Dise1.LabelList[0] == Dise2.LabelList[0] and \
   Dise1.LabelList[5] == Dise2.LabelList[5]:
    step2()

Dise2.move("S")
Dise2.move("S")
if Dise1.LabelList[0] == Dise2.LabelList[0] and \
   Dise1.LabelList[5] == Dise2.LabelList[5]:
    step2()

print("No")