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, a1, a2, a3, a4, a5, a6):
        
        self.face = [a1, a2, a3, a4, a5, a6]
        self.v = [a5, a1, a2, a6] 
        self.h = [a4, a1, a3, a6] 
        self.det = 1
        

    
    def top(self):
        return self.v[1]

    
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    def searchFace(self, a):
        b = 0
        for i in range(6):
            if a == self.face[i]:
                
                b = i + 1
        return b

    def detJudge(self, x): 
        y = int(7 / 2 - abs(x - 7 / 2))
        if x != y:
            self.det *= -1
        
        return y

    def rightSide(self, top, front):
        r = 0
        if top == 1 and front == 2:
            r = 3
        elif top == 2 and front == 3:
            r = 1
        elif top == 3 and front == 1:
            r = 2
        elif top == 1 and front == 3:
            r = 5
        elif top == 3 and front == 2:
            r = 6
        elif top == 2 and front == 1:
            r = 4
        if self.det == -1:
            r = 7 - r
        return r

d = [[int(i) for i in input().rstrip().split()] for j in range(2)]
dice1 = Dice(d[0][0], d[0][1], d[0][2], d[0][3], d[0][4], d[0][5])
dice2 = Dice(d[1][0], d[1][1], d[1][2], d[1][3], d[1][4], d[1][5])


















    
    
    
    
    
    
    
    
    
    
    
    


import random


yesCount = 0
i = 0
while yesCount == 0 and i < 1000:
    j = random.randint(0, 3)
    if j == 0:
        dice2.north()
    elif j == 1:
        dice2.south()
    elif j == 2:
        dice2.east()
    elif j == 3:
        dice2.west()
    if (dice1.v == dice2.v and dice1.h == dice2.h) or ([dice1.v[2], dice1.v[1], dice1.v[0], dice1.v[3]] == [dice2.v[2], dice2.v[1], dice2.v[0], dice2.v[3]] and [dice1.h[2], dice1.h[1], dice1.h[0], dice1.h[3]] == [dice2.h[2], dice2.h[1], dice2.h[0], dice2.h[3]]):
        yesCount += 1
        
    i += 1
if yesCount >= 1:
    print('Yes')
else:
    print('No')

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

    def inspection(self,other):
        string=''
        a=self.surface[0]
        b=self.surface[1]
        c=self.surface[2]
        d=self.surface[3]
        e=self.surface[4]
        f=self.surface[5]
        match1=a+b+c+d+e+f
        match2=b+f+c+d+a+e
        match3=c+b+f+a+e+d
        match4=d+b+a+f+e+c
        match5=e+a+c+d+f+b
        match6=f+e+c+d+b+a
        match7=f+b+d+c+e+a
        match8=a+d+b+e+c+f
        match9=d+f+b+e+a+c
        match10=b+d+f+a+c+e
        match11=e+d+a+f+c+b
        match12=c+a+b+e+f+d
        match13=f+c+b+e+d+a
        match14=f+d+e+b+c+a
        match15=a+e+d+c+b+f
        match16=e+f+d+c+a+b
        match17=d+e+f+a+b+c
        match18=c+e+a+f+b+d
        match19=b+a+d+c+f+e
        match20=a+c+e+b+d+f
        match21=c+f+e+b+a+d
        match22=e+c+f+a+d+b
        match23=b+c+a+f+d+e
        match24=d+a+e+b+f+c
        for i in other.surface:
            string+=i
        if string==match1 or string==match2 or string==match3 or string==match4 or string==match5 or string==match6 or string==match7 or string==match8 or string==match9 or string==match10 or string==match11 or string==match12 or string==match13 or string==match14 or string==match15 or string==match16 or string==match17 or string==match18 or string==match19 or string==match20 or string==match21 or string==match22 or string==match23 or string==match24:
            return 'Yes'
        return 'No'

dice1=Dice(input().split())
dice2=Dice(input().split())
result=dice1.inspection(dice2)
print(result)

Solution (Python):
face = list(map(int,input().split()))
anface = list(map(int,input().split()))
def Nroll(list):
	a = [list[1],list[5],list[2],list[3],list[0],list[4]]
	return a
def Wroll(list):
	a = [list[2],list[1],list[5],list[0],list[4],list[3]]
	return a
ql = []
ans = "No"
for ii in range(2):
	face = Wroll(face)
	for k in range(4):
		face = Nroll(face)
		for kk in range(4):
			face = Wroll(face)
			if face == anface:
				ans = "Yes"
				break
		else:
			continue
		break
	else:
		continue
	break
print(ans)

Solution (Python):
def N(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[1]
  t1[1]=d1[5]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[0]
  t1[5]=d1[4]
  return t1
def S(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[4]
  t1[1]=d1[0]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[5]
  t1[5]=d1[1]
  return t1
def E(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[3]
  t1[1]=d1[1]
  t1[2]=d1[0]
  t1[3]=d1[5]
  t1[4]=d1[4]
  t1[5]=d1[2]
  return t1
def W(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[2]
  t1[1]=d1[1]
  t1[2]=d1[5]
  t1[3]=d1[0]
  t1[4]=d1[4]
  t1[5]=d1[3]
  return t1
d1=[0 for i in range(6)]
d2=[0 for i in range(6)]
d1[:]=(int(x) for x in input().split())
d2[:]=(int(x) for x in input().split())

if d1[2]==d2[0]:
  d2=E(d2)
elif d1[2]==d2[1]:
  d2=N(d2)
  d2=E(d2)
elif d1[2]==d2[3]:
  d2=E(d2)
  d2=E(d2)
elif d1[2]==d2[4]:
  d2=S(d2)
  d2=E(d2)
elif d1[2]==d2[5]:
  d2=W(d2)
elif d1[2]!=d2[2]:
  print("No")
  exit()

if d1==d2:
  print("Yes")
  exit()

for i in range(3):
  d2=N(d2)
  if d1==d2:
    print("Yes")
    exit()

print("No")

Solution (Python):

import random
class Dice:
    def __init__(self, numbers):
        self.dice=[i for i in numbers]
        self.workspace=[i for i in numbers]
        
        self.top=self.dice[0]
        
        
    def rotate(self,command):
        if command == "W":
            self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
            self.dice=self.workspace
        elif command == "E":
            self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
            self.dice = self.workspace
        
        if command == "S":
            self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
            self.dice=self.workspace
        elif command == "N":
            self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
            self.dice=self.workspace
            
    def get_top(self):
        self.top=self.dice[0]
        print(self.top)
        
    def predict(self, num):
        for i in range(num):
            top, front = map(int, input().split())
            while(True):
                if top == self.dice[0] and front == self.dice[1]:
                    break
                command_num=random.randint(1,4)
                if command_num == 1:
                    self.rotate("W")
                elif command_num == 2:
                    self.rotate("E")
                elif command_num == 3:
                    self.rotate("S")
                elif command_num == 4:
                    self.rotate("N")
            print(self.dice[2])
            
    def getter(self):
        return self.dice[0], self.dice[1], self.dice[2], self.dice[3], self.dice[4], self.dice[5]
    
    def predict_same(self, top, front, right, left, back, bottom):
        for n in range(300):
            if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
                break
            command_num=random.randint(1,4)
            if command_num == 1:
                    self.rotate("W")
            elif command_num == 2:
                    self.rotate("E")
            elif command_num == 3:
                    self.rotate("S")
            elif command_num == 4:
                    self.rotate("N")
        
        if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
            if self.dice[3] == left and self.dice[4] == back and self.dice[5] == bottom:
                return "Yes"
                
            else:
                return "No"
                
        else:
            return "No"
            
        
            
                
    
        

numbers1=list(map(int,input().split()))
numbers2=list(map(int,input().split()))
dice1=Dice(numbers1)
dice2=Dice(numbers2)
top, front, right, left, back, bottom=dice1.getter()

print(dice2.predict_same(top, front, right, left, back, bottom))

Solution (Python):
import collections


class Dice():
    def __init__(self, labels):
        self.__pip = labels
    
    def roll_e(self): 
        self.__pip[0], self.__pip[3], self.__pip[5], self.__pip[2] = \
            self.__pip[3], self.__pip[5], self.__pip[2], self.__pip[0]

    def roll_n(self): 
        self.__pip[0], self.__pip[1], self.__pip[5], self.__pip[4] = \
            self.__pip[1], self.__pip[5], self.__pip[4], self.__pip[0]

    def roll_s(self): 
        self.__pip[0], self.__pip[4], self.__pip[5], self.__pip[1] = \
            self.__pip[4], self.__pip[5], self.__pip[1], self.__pip[0]

    def roll_w(self): 
        self.__pip[0], self.__pip[2], self.__pip[5], self.__pip[3] = \
            self.__pip[2], self.__pip[5], self.__pip[3], self.__pip[0]

    def roll_nn(self): 
        self.roll_n()
        self.roll_n()

    def turn_dice(self): 
        self.__pip[1], self.__pip[2], self.__pip[4], self.__pip[3] = \
            self.__pip[2], self.__pip[4], self.__pip[3], self.__pip[1]

    def roll_dice(self, c):
        if c != self.__pip[0]:
            if c == self.__pip[1]:
                self.roll_n()
            elif c == self.__pip[2]:
                self.roll_w()
            elif c == self.__pip[3]:
                self.roll_e()
            elif c == self.__pip[4]:
                self.roll_s()
            else:
                self.roll_nn()
    
    def get_top(self):
        return self.__pip[0]

    def get_front(self):
        return self.__pip[1]

    def get_right(self):
        return self.__pip[2]
        
    def get_left(self):
        return self.__pip[3]
        
    def get_behind(self):
        return self.__pip[4]
        
    def get_bottom(self):
        return self.__pip[5]
    
    def judge(self, dice_2):
        top = dice_2.get_top()
        self.roll_dice(top)
        for i in range(4):
            if dice_2.get_front() == self.__pip[1]:
                break
            if i == 3:
                return False
            self.turn_dice()
        if dice_2.get_right() != self.__pip[2] or \
            dice_2.get_left() != self.__pip[3] or \
            dice_2.get_behind() != self.__pip[4] or \
            dice_2.get_bottom() != self.__pip[5]:
            return False
        return True
       
        
def main():
    lst1 = list(input().split())
    lst2 = list(input().split())
    if len(set(lst1) ^ set(lst2)) != 0:
        print('No')
        return
    c = collections.Counter(lst2)
    dice1 = Dice(lst1)
    dice2 = Dice(lst2)
    dice2.roll_dice(c.most_common()[-1][0]) 
    if dice1.judge(dice2):
        print('Yes')
    else:
        print('No')
        

if __name__ == "__main__":
    main()

Solution (Python):
import random
A = list(map(int,input().split()))
N = list(map(int,input().split()))
C = ["E","W","S","N"]
for _ in range(10**5):
    i = random.choice(C)
    if i == "E":
        N[0],N[2],N[3],N[5] = N[3],N[0],N[5],N[2]
    elif i == "W":
        N[3],N[0],N[5],N[2] = N[0],N[2],N[3],N[5]
    elif i == "S":
        N[0],N[1],N[4],N[5] = N[4],N[0],N[5],N[1]
    else:
        N[4],N[0],N[5],N[1] = N[0],N[1],N[4],N[5]
    
    if A == N:
        print("Yes")
        exit()
print("No")

Solution (Python):
class Dice:
    def __init__(self,dim=list(range(1,7))):
        self.dim = dim

    def roll(self,direction):
        if direction == "N":
            buff = self.dim[0]
            self.dim[0] = self.dim[1]
            self.dim[1] = self.dim[5]
            self.dim[5] = self.dim[4]
            self.dim[4] = buff

        if direction == "E":
            buff = self.dim[3]
            self.dim[3] = self.dim[5]
            self.dim[5] = self.dim[2]
            self.dim[2] = self.dim[0]
            self.dim[0] = buff

        if direction == "W":
            buff = self.dim[0]
            self.dim[0] = self.dim[2]
            self.dim[2] = self.dim[5]
            self.dim[5] = self.dim[3]
            self.dim[3] = buff

        if direction == "S":
            buff = self.dim[0]
            self.dim[0] = self.dim[4]
            self.dim[4] = self.dim[5]
            self.dim[5] = self.dim[1]
            self.dim[1] = buff

lst = list(map(int,input().split()))
D = Dice(lst)
D2_lst = list(map(int,input().split()))

count = 0
for op in 'EEENEEENEEESEEESEEENEEEN':
    if D.dim == D2_lst:
        print("Yes")
        break
    D.roll(op)
    count += 1
if count == 24:
    print("No")

Solution (Python):

class Dice:
    def __init__(self, input_dice):
        self.flow = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
        self.dice = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
  
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.dice[0] = n0
        self.dice[1] = n1
        self.dice[2] = n2
        self.dice[3] = n3
        self.dice[4] = n4
        self.dice[5] = n5
        return self.dice
    
    def roll(self, dir):
        if dir == 'S':
            self.setNumber(self.flow[0], self.flow[2], self.flow[5], self.flow[1], self.flow[4], self.flow[3])
            self.flow = self.dice
            return self.dice
        if dir == 'N':
            self.setNumber(self.flow[0], self.flow[3], self.flow[1], self.flow[5], self.flow[4], self.flow[2])
            self.flow = self.dice
            return self.dice
        if dir == 'W':
            self.setNumber(self.flow[2], self.flow[1], self.flow[4], self.flow[0], self.flow[3], self.flow[5])
            self.flow = self.dice
            return self.dice
        if dir == 'E':
            self.setNumber(self.flow[3], self.flow[1], self.flow[0], self.flow[4], self.flow[2], self.flow[5])
            self.flow = self.dice
            return self.dice

    def identify(self, dice_x):
        for i in range(6):
            if self.dice[i] != dice_x[i]:
                return False
                break
            elif i == 5:
                return True

    def check(self, dice_x):
        import sys
        dice_x = [dice_x[3], dice_x[1], dice_x[0], dice_x[5], dice_x[2], dice_x[4]]
        
        
        
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == True: 
                print('Yes')
                sys.exit()
        
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == True: 
                print('Yes')
                sys.exit()
        
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == True: 
                print('Yes')
                sys.exit()
        
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == True: 
                print('Yes')
                sys.exit()
        
        self.roll('E')
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == True: 
                print('Yes')
                sys.exit()
        
        self.roll('N')
        self.roll('N')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == True: 
                print('Yes')
                sys.exit()
        print('No')

dice = list(map(int, input().split()))
dice_x = list(map(int, input().split()))

d = Dice(dice)
d.check(dice_x)

Solution (Python):
class dice:
    def __init__(self, X):
        self.x = [0] * 6
        self.x[0] = X[0]
        self.x[1] = X[1]
        self.x[2] = X[2]
        self.x[3] = X[3]
        self.x[4] = X[4]
        self.x[5] = X[5]

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

X1 = list(map(int, input().split()))
X2 = list(map(int, input().split()))
d1 = dice(X1)
d2 = dice(X2)
distances = list('NNNNWNNNWNNNENNNENNNWNNN')
b = False
for d in distances:
    d2.roll(d)
    if d1.x[0] == d2.x[0] and d1.x[1] == d2.x[1] and d1.x[2] == d2.x[2] and \
       d1.x[3] == d2.x[3] and d1.x[4] == d2.x[4] and d1.x[5] == d2.x[5]:
        b = True
        break
if b == False:
    print('No')
else:
    print('Yes')

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

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

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

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

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

    def rotate_r(self):
        self.list = [self.list[0], self.list[2], self.list[4], self.list[1], self.list[3], self.list[5]]


dice_1 = Dice(list(map(int, input().split())))
dice_2 = Dice(list(map(int, input().split())))
c = 0
for i in range(4):
    dice_1.rotate_r()
    for j in range(4):
        dice_1.roll_n()
        if dice_1.list == dice_2.list:
            c = 1

for i in range(4):
    dice_1.rotate_r()
    for j in range(4):
        dice_1.roll_e()
        if dice_1.list == dice_2.list:
            c = 1
if c == 1:
    print('Yes')
else:
    print('No')

Solution (Python):
import random

class Dice():
    def __init__(self, numbers):
        self.numbers = numbers
        S = [1, 5, 2, 3, 0, 4]
        N = [4, 0, 2, 3, 5, 1]
        W = [3, 1, 0, 5, 4, 2]
        E = [2, 1, 5, 0, 4, 3]
        self.tumble = {0: S, 1: N, 2: W, 3: E}
        
    def rol(self, command):
        prev = self.numbers.copy()
        for i, t in enumerate(self.tumble[command]):
            self.numbers[t] = prev[i]

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

max_len= 24
dice_table = []
dice = Dice(d1)


for _ in range(1000):
    dice.rol(random.randint(0, 3))
    numbers = dice.numbers.copy()
    if numbers not in dice_table:
        dice_table.append(numbers)
        
if d2 in dice_table:
    print('Yes')
else:
    print('No')

Solution (Python):

def dice():
    import random as ran

    dnum = list(map(int,input().split()))
    dcnum = list(map(int,input().split()))


    up = dnum[0]
    un = dnum[5]
    ri = dnum[2]
    le = dnum[3]
    fr = dnum[1]
    ba = dnum[4]
    tmp = int(0)
    tmp2 = int(0)
    order = ["S","N","E","W"]
    count = int(0)

    while count <= 1000  :
        x = ran.choice(order)
        if (x == "S"):
            tmp = fr
            tmp2 = un
            fr = up
            up = ba
            un = tmp
            ba = tmp2

        elif (x == "N"):
            tmp = un
            tmp2 = up
            up = fr
            un = ba
            fr = tmp
            ba = tmp2

        elif (x == "E"):
            tmp = up
            tmp2 = un
            up = le
            un = ri
            ri = tmp
            le = tmp2

        elif (x == "W"):
            tmp = un
            tmp2 = up
            up = ri
            un = le
            ri = tmp
            le = tmp2

        if (up == dcnum[0] and un == dcnum[5] and ri == dcnum[2] and le == dcnum[3] and fr == dcnum[1] and ba == dcnum[4]):
            print("Yes")
            break

        if (count == 1000):
            print("No")

        count += 1
dice()

Solution (Python):
























































































class Dice:
    def __init__(self, label: list):
        self.top, self.front, self.right, self.left, self.back, self.bottom = label

    def roll(self, direction: str):
        if direction == "N":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.front,
                self.bottom,
                self.right,
                self.left,
                self.top,
                self.back,
            )
        elif direction == "W":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.right,
                self.front,
                self.bottom,
                self.top,
                self.back,
                self.left,
            )
        elif direction == "S":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.back,
                self.top,
                self.right,
                self.left,
                self.bottom,
                self.front,
            )
        elif direction == "E":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.left,
                self.front,
                self.top,
                self.bottom,
                self.back,
                self.right,
            )

    def output_top(self):
        print(self.top)

    def get_top_front(self):
        return f"{self.top} {self.front}"

    def print_right(self):
        print(self.right)

    def get_label(self):
        return [self.top, self.front, self.left, self.back, self.bottom]






















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

for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
    if dice1.get_label() == dice2.get_label():
        print("Yes")
        break
    dice1.roll(i)
else:
    print("No")

Solution (Python):
import sys


def rollDice(dice, direction):
    buf = [x for x in dice]
    if direction == "S":
        buf[0] = dice[4]
        buf[1] = dice[0]
        buf[4] = dice[5]
        buf[5] = dice[1]
    elif direction == "E":
        buf[0] = dice[3]
        buf[2] = dice[0]
        buf[3] = dice[5]
        buf[5] = dice[2]
    elif direction == "W":
        buf[0] = dice[2]
        buf[2] = dice[5]
        buf[3] = dice[0]
        buf[5] = dice[3]
    elif direction == "N":
        buf[0] = dice[1]
        buf[1] = dice[5]
        buf[4] = dice[0]
        buf[5] = dice[4]

    for i in range(6):
        dice[i] = buf[i]


def rollDiceSide(dice):
    buf = [x for x in dice]
    buf[1] = dice[2]
    buf[2] = dice[4]
    buf[3] = dice[1]
    buf[4] = dice[3]

    for i in range(6):
        dice[i] = buf[i]


def rollCheckSide(d):
    if d1 == d2:
        print("Yes")
        sys.exit()
    rollDiceSide(d2)


def rollCheck(d):
    if d1 == d2:
        print("Yes")
        sys.exit()
    rollDice(d2, "S")
    for _ in range(4):
        rollCheckSide(d2)


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


for _ in range(4):
    for _ in range(4):
        rollCheck(d2)
    rollDice(d2, "W")

print("No")

Solution (Python):
class dice:
    def __init__(self, f0, f1, f2, f3, f4, f5):
        self.dice_num = [f0, f1, f2, f3, f4, f5]

    def roll_dice(self, command):
        for i in command:
            if i == 'N':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[1]
                self.dice_num[1] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[4]
                self.dice_num[4] = tmp

            if i == 'S':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[4]
                self.dice_num[4] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[1]
                self.dice_num[1] = tmp

            if i == 'E':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[3]
                self.dice_num[3] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[2]
                self.dice_num[2] = tmp

            if i == 'W':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[2]
                self.dice_num[2] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[3]
                self.dice_num[3] = tmp

    def print_topface(self):
        print(self.dice_num[0])

    def turn_clockwise(self):
        tmp = self.dice_num[1]
        self.dice_num[1] = self.dice_num[2]
        self.dice_num[2] = self.dice_num[4]
        self.dice_num[4] = self.dice_num[3]
        self.dice_num[3] = tmp

    def check_same_dice(self, dice2):
        for i in range(4):
            self.roll_dice('W')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        for i in range(4):
            self.roll_dice('N')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        return False


if __name__ == "__main__":
    num_list1 = list(map(int, input().split()))
    num_list2 = list(map(int, input().split()))
    mydice1 = dice(*num_list1)
    mydice2 = dice(*num_list2)
    same_dice = mydice1.check_same_dice(mydice2)
    if same_dice:
        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,lst):
        self.face=lst
        self.order="NNNNWNNNWNNNENNNENNNWNNN"
    
    def roll(self,x):
        tmp=self.face
        if x=="E":
            self.face=[tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        if x=="W":
            self.face=[tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        if x=="N":
            self.face=[tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
        if x=="S":
            self.face=[tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
    
    def showDown(self):
        return self.face[0]
    
    def query(self,lst):
        tmp=self.face
        ans=-1
        for i in self.order:
            self.roll(i)
            if self.face[0]==lst[0] and self.face[1]==lst[1]:
                ans=self.face[2]
                break
        self.face=tmp
        return ans
    
    def isEqual(self,another):
        tmp=self.face
        ans=False
        for i in self.order:
            self.roll(i)
            flg=True
            for j in range(6):
                if self.face[j]!=another.face[j]:
                    flg=False
                    break
            if flg:
                return True

            
    
diceA=Dice(list(map(int,input().split(" "))))
diceB=Dice(list(map(int,input().split(" "))))
if diceA.isEqual(diceB):
    print("Yes")
else:
    print("No")