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):
import random

dice_a = list(map(int, input().split()))
dice_b = list(map(int, input().split()))


class Dice():
    def __init__(self, dice, directions):
        self.dice = dice
        self.directions = directions

    def roll(self):
        for direction in self.directions:
            NS = [0, 1, 5, 4]
            WE = [0, 2, 5, 3]
            copy_dice = self.dice[:]

            if direction == 'N':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-3]]
            elif direction == 'S':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-1]]
            elif direction == 'W':
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-3]]
            else:
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-1]]

        return self.dice


def check_equal(dice_1, dice_2):
    for i in range(777):
        dice_A = Dice(dice_1, random.choice(['N', 'S', 'W', 'E']))

        if dice_A.roll() == dice_2:
            print('Yes')
            break

    else:
        print('No')

check_equal(dice_a, dice_b)

Solution (Python):


dirc = ((0,), (4, 0, 2, 3, 5, 1), (3, 1, 0, 5, 4, 2),
(2, 1, 5, 0, 4, 3), (1, 5, 2, 3, 0, 4), (5, 4, 2, 3, 1, 0))
sideNum = (1, 2, 4, 3)

labelA = list(map(int, input().split()))
labelB = list(map(int, input().split()))

for i in labelB:
    if labelA.count(i) != labelB.count(i):
        print('No')
        exit()

for i in range(6):
    labelC = [0 for k in range(6)]
    if i == 0:
        labelC = labelA[:]
    else:
        for j in range(6):
            labelC[dirc[i][j]] = labelA[j]
    if labelB[0] == labelC[0] and labelB[5] == labelC[5]:
        sideB = ''
        sideC = ''
        for j in sideNum:
            sideB += str(labelB[j])
            sideC += str(labelC[j])
        sideC += sideC
        if sideB in sideC:
            print('Yes')
            exit()
print('No')

Solution (Python):
class Dice:
    def __init__(self, default = [1, 2, 3, 4, 5, 6]):
        self.d = default

    def e(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]

    def w(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]

    def n(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]

    def s(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]

    def r(self):
        self.d[1], self.d[2], self.d[3], self.d[4] = self.d[3], self.d[1], self.d[4], self.d[2]

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

    def forward(self):
        return self.d[1]

    def right(self):
        return self.d[2]

    def bottom(self):
        return self.d[5]

    def forTop(self, num):  
        for i in range(4):
            if self.top() == num:
                break
            self.e()
        else:
            for j in range(3):
                if self.top() == num:
                    break
                self.s()
    def same(self, dice):
        if self.d == dice.d:
            return True


def main():
    a_ = [int(i) for i in input().split()]
    b_ = [int(i) for i in input().split()]
    if not sorted(a_) == sorted(b_):
        print('No')
        return
    a = Dice(a_)
    b = Dice(b_)
    for i in range(4):
        for j in range(4):
            if b.same(a):
                print('Yes')
                return
            else:
                b.e()
        b.s()
    for i in range(4):
        for j in range(4):
            if b.same(a):
                print('Yes')
                return
            else:
                b.e()
        b.r()
    for i in range(4):
        for j in range(4):
            if b.same(a):
                print('Yes')
                return
            else:
                b.s()
        b.r()


    print('No')
    return




if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    
    def __init__(self,l):
        self.f=l
        
    def __str__(self):
        l=self.f
        s=f'[U:{l[0]},S:{l[1]},E:{l[2]},W:{l[3]},N:{l[4]},D:{l[5]}]'
        return(s)
       
    def roll(self,c):
        if c=='N':
            ni=[1,5,2,3,0,4]
        elif c=='S':
            ni=[4,0,2,3,5,1]
        elif c=='E':
            ni=[3,1,0,5,4,2]
        elif c=='W':
            ni=[2,1,5,0,4,3]
        self.f=[self.f[j] for j in ni]
    
    def rotate(self,r):
        if r==+1: 
            ni=[0,3,1,4,2,5]
        elif r==-1: 
            ni=[0,2,4,1,3,5]
        self.f=[self.f[j] for j in ni]

    def patterns(self):
        fs=[]
        for i in range(6):
            if i%2==0:
                self.roll('N')
            else:
                self.roll('E')
            for j in range(4):
                self.rotate(+1)
                fs.append(self.f)
        return fs
        
    def lookEast(self,l):
        for f in self.patterns():
            if f[0]==l[0] and f[1]==l[1]:
                return f[2]
    
    def equals(self,d):
        for f in self.patterns():
            if f==d.f:
                return True
        return False

print('Yes' if Dice(list(map(int,input().split()))).equals(Dice(list(map(int,input().split())))) else 'No')

Solution (Python):
import copy
import sys
class Dice():
    def __init__(self, t, s, e, w, n, b):
        self.a = [t, s, e, w, n, b]
        self.a_org = copy.deepcopy(self.a)

    def reset(self):
        self.a = copy.deepcopy(self.a_org)
    
    def shake(self, me):
        if me == 'S':
            self.b = [self.a[int(i)] for i in '402351']
            self.a = self.b
        elif me == 'N':
            self.b = [self.a[int(i)] for i in '152304']
            self.a = self.b
        if me == 'W':
            self.b = [self.a[int(i)] for i in '215043']
            self.a = self.b
        if me == 'E':
            self.b = [self.a[int(i)] for i in '310542']
            self.a = self.b  
    def get(self, dir):
        if dir == 't': return self.a[0]
        elif dir == 's': return self.a[1]
        elif dir == 'e': return self.a[2]
        elif dir == 'w': return self.a[3]
        else: print('input err', dir)
    def front(self, f):
        self.reset()
        if f == 0:self.shake('S')
        elif f == 4:self.shake('S');self.shake('S')
        elif f == 3:self.shake('E');self.shake('S')
        elif f == 2:self.shake('W');self.shake('S')
        elif f == 5:self.shake('N')

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

d1 = Dice(*n1)
d2 = Dice(*n2)

for i in range(6):
    if d1.a == d2.a:
        print('Yes')
        sys.exit()
    else:
        d2.front(i)
        if d1.a == d2.a:
            print('Yes')
            sys.exit()
    for _ in range(3):
        d2.shake('W')
        if d1.a == d2.a:
            print('Yes')
            sys.exit()
        
print('No')

Solution (Python):
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        elif dir == "H":
            self.list[1], self.list[2], self.list[4], self.list[3] = self.list[2], self.list[4], self.list[3], self.list[1]
        elif dir =="V":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        print("D:{}".format(repr(self.list)))

    def isface(self,f):
        if f in self.list:
            return True
        else:
            return False

    def isSameface(self,b):
        for i in range(len(self.list)):
            if self.list[i] != b.list[i]:
                return False
        return True

    def isSame(self,b):
        
        for c in "ZHHHWHHHEHHHEHHHWHHHWHHH":
            b.rotate(c)
            if self.isSameface(b):
                return True
        return False


def main():
    l = [int(x) for x in input().split()]
    k = [int(x) for x in input().split()]
    a = Dice(l)
    b = Dice(k)

    if a.isSame(b):
        print("Yes")
    else:
        print("No")


if __name__  == '__main__':
    main()

Solution (Python):
pattern_list =[[0,1,2,3,4,5],[0,2,4,1,3,5],[0,4,3,2,1,5],[0,3,1,4,2,5],[1,2,0,5,3,4],[1,5,2,3,0,4],[1,3,5,0,2,4],[1,0,3,2,5,4],[2,0,1,4,5,3],[2,4,0,5,1,3],[2,5,4,1,0,3],[2,1,5,0,4,3],[3,0,4,1,5,2],[3,1,0,5,4,2],[3,5,1,4,0,2],[3,4,5,0,1,2],[4,2,5,0,3,1],[4,0,2,3,5,1],[4,3,0,5,2,1],[4,5,3,2,0,1],[5,1,3,2,4,0],[5,2,1,4,3,0],[5,4,2,3,1,0],[5,3,4,1,2,0]]

dice_a_list = list(map(int,input().split()))
dice_b_list = list(map(int,input().split()))

dice_c_list =[0,0,0,0,0,0]
cnt = 0
for i in range(24):
	for j in range(6):
		dice_c_list[j]=  dice_a_list[pattern_list[i][j]]
	if dice_c_list == dice_b_list:
		cnt =1
if cnt==0:
	print("No")
else:
	print("Yes")

Solution (Python):
class Dice:
    
    def __init__(self, lst):
        self.val=[]
        self.val.append(lst[0])
        self.val.append(lst[1])
        self.val.append(lst[2])
        self.val.append(lst[3])
        self.val.append(lst[4])
        self.val.append(lst[5])

    def rotate(self,dir):
        if dir=="N":
            tmp=self.val[0]
            self.val[0]=self.val[1]
            self.val[1]=self.val[5]
            self.val[5]=self.val[4]
            self.val[4]=tmp
        if dir=="E":
            tmp=self.val[0]
            self.val[0]=self.val[3]
            self.val[3]=self.val[5]
            self.val[5]=self.val[2]
            self.val[2]=tmp
        if dir=="S":
            tmp=self.val[0]
            self.val[0]=self.val[4]
            self.val[4]=self.val[5]
            self.val[5]=self.val[1]
            self.val[1]=tmp
        if dir=="W":
            tmp=self.val[0]
            self.val[0]=self.val[2]
            self.val[2]=self.val[5]
            self.val[5]=self.val[3]
            self.val[3]=tmp

def int_to_dir(n):
    if n==0:
        return "N"
    if n==1:
        return "E"
    if n==2:
        return "S"
    if n==3:
        return "W"
    

x = list(map(int,input().split()))
y = list(map(int,input().split()))




D1 = Dice(x) 

D2 = Dice(y)



import random 

Determin=False
for i in range(1000):

    D2.rotate(int_to_dir(random.randint(0,4)))
    
    
    if D1.val==D2.val:
        
        
        Determin=True
        
    
if Determin:
    print("Yes")
else:
    print("No")

Solution (Python):
def dice_rotation(dice, command):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	
	if command == 'S':
		dice[0] = tmp_dice[4]
		dice[4] = tmp_dice[5]
		dice[5] = tmp_dice[1]
		dice[1] = tmp_dice[0]
	
	elif command == 'N':
		dice[0] = tmp_dice[1]
		dice[1] = tmp_dice[5]
		dice[5] = tmp_dice[4]
		dice[4] = tmp_dice[0]
	
	elif command == 'W':
		dice[0] = tmp_dice[2]
		dice[2] = tmp_dice[5]
		dice[5] = tmp_dice[3]
		dice[3] = tmp_dice[0]
	
	elif command == 'E':
		dice[0] = tmp_dice[3]
		dice[3] = tmp_dice[5]
		dice[5] = tmp_dice[2]
		dice[2] = tmp_dice[0]

def dice_spinning(dice):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	dice[1] = tmp_dice[2]
	dice[2] = tmp_dice[4]
	dice[4] = tmp_dice[3]
	dice[3] = tmp_dice[1]

def comparison_dices(Dice1,Dice2):

	yes_counter = 0
	for j in range(6):
		if Dice1[j] == Dice2[j]:
			yes_counter += 1
	if yes_counter == 6:
		return True

	return False

def test():

	Dice1 = list(map(int,input().split()))
	Dice2 = list(map(int,input().split()))

	judgement_result = False

	
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'S')

	
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'W')

	if judgement_result == True:
		print("Yes")
	else:
		print("No")

if __name__ == "__main__":
	test()

Solution (Python):
import copy


class Dice:
    def __init__(self, a, b, c, d, e, f):
        self.top = a
        self.front = b
        self.right = c
        self.left = d
        self.behind = e
        self.bottom = f

    def S(self):
        self.top, self.front, self.behind, self.bottom = self.behind, self.top, self.bottom, self.front

    def N(self):
        self.behind, self.top, self.bottom, self.front = self.top, self.front, self.behind, self.bottom

    def E(self):
        self.top, self.bottom, self.left, self.right = self.left, self.right, self.bottom, self.top

    def W(self):
        self.left, self.right, self.bottom, self.top = self.top, self.bottom, self.left, self.right

    def spin(self):
        self.left, self.behind, self.right, self.front = self.front, self.left, self.behind, self.right

    def __eq__(self, _dice2):
        dice2 = copy.deepcopy(_dice2)
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.N()
        dice2.N()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.N()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.E()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.W()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.S()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        return False



    def _eqaul(self, dice2):
        return self.front == dice2.front and self.behind == dice2.behind and self.left == dice2.left and self.right == dice2.right and self.top == dice2.top and self.bottom == dice2.bottom

    def __repr__(self):
        return ",".join([str(object=i) for i in (self.top,self.front,self.right,self.left,self.behind,self.bottom)])

dice1 = Dice(*[int(i) for i in input().split(" ")])
dice2 = Dice(*[int(i) for i in input().split(" ")])

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

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,odr):
        if   odr=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif odr=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif odr=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif odr=='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()))
d1 = dice(label)
d2 = list(map(int, input().split()))
for odr in 'EEENEEENEEESEEESEEENEEEN':
    if d1.get_label() == d2:
        print('Yes')
        break
    d1.roll(odr)
else:
    print('No')

Solution (Python):

import sys
import copy
line = sys.stdin.readline() 
line = line.rstrip('\r\n')
face = line.split()

line = sys.stdin.readline() 
line = line.rstrip('\r\n')
face2 = line.split()


for i in range(5):
    if face[1] == face2[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[1]
    face[1] = face_old[5]
    face[2] = face_old[2]
    face[3] = face_old[3]
    face[4] = face_old[0]
    face[5] = face_old[4]
else:
    face_old = copy.deepcopy(face)
    face[0] = face_old[3]
    face[1] = face_old[1]
    face[2] = face_old[0]
    face[3] = face_old[5]
    face[4] = face_old[4]
    face[5] = face_old[2]
for i in range(5):
    if face[1] == face2[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[1]
    face[1] = face_old[5]
    face[2] = face_old[2]
    face[3] = face_old[3]
    face[4] = face_old[0]
    face[5] = face_old[4]
for i in range(5):
    if face[0] == face2[0]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[3]
    face[1] = face_old[1]
    face[2] = face_old[0]
    face[3] = face_old[5]
    face[4] = face_old[4]
    face[5] = face_old[2]

if face == face2:
    print("Yes")
else:
    print("No")

Solution (Python):


def west(d):
	tmp=d[4]
	d[4]=d[1]
	d[1]=d[3]
	d[3]=d[6]
	d[6]=tmp

def east(d):
	tmp=d[4]
	d[4]=d[6]
	d[6]=d[3]
	d[3]=d[1]
	d[1]=tmp

def north(d):
	tmp=d[1]
	d[1]=d[2]
	d[2]=d[6]
	d[6]=d[5]
	d[5]=tmp

def south(d):
	tmp=d[1]
	d[1]=d[5]
	d[5]=d[6]
	d[6]=d[2]
	d[2]=tmp

def spin(d):
	tmp=d[2]
	d[2]=d[3]
	d[3]=d[5]
	d[5]=d[4]
	d[4]=tmp

def kaiten(d, op):
	if   op == "W": west(d)
	elif op == "E": east(d)
	elif op == "N": north(d)
	elif op == "S": south(d)

def inputDice():
	return list(map(int,("-1 "+input()).split()))

def equal(da, db):
	for op in list("NWWWN-"):
		for i in range(4):
			if(da[1]==db[1] and da[2]==db[2] and da[3]==db[3] and da[4]==db[4] and da[5]==db[5] and da[6]==db[6]):
				return True
			spin(db)
		kaiten(db,op)
	return False

da=inputDice()
db=inputDice()
if equal(da,db):
	print("Yes")
else:
	print("No")

Solution (Python):
class dice:
  def __init__(self,dice_number_list):
    self.top,self.front,self.right,self.left,self.rear,self.bottom = dice_number_list
    self.dice_number_list = dice_number_list
    
  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])
    
  
  def get_all_number_list(self):
    
    
    
    
    
    
    
    all_dice_number_list = []
    for op in "NNNNWNNNWNNNENNNENNNWNNN":
      self.roll(op)
      if self.get_label() not in all_dice_number_list:
        all_dice_number_list.append(self.get_label())
    return(all_dice_number_list)
  
  
  def judge_equal(self,another):
    if(sorted(self.get_all_number_list()) == sorted(another.get_all_number_list())):
       return True
    else:
       return False

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

if d1.judge_equal(d2):
  print("Yes")
else:
  print("No")

Solution (Python):

d,e=[input().split()for _ in'12'];e[3:5]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3:5]=f[4:2:-1]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

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):
d,e=[input().split()for _ in'12'];e[3:5]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3:5]=f[4:2:-1]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

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
import os
import math
 
 
dice0 = list(map(int, input().split()))
dice1 = list(map(int, input().split()))
 
def dice_roll(dice, c):
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
    
    elif c == 'R':
        dice[2] = copy[1]
        dice[4] = copy[2]
        dice[3] = copy[4]
        dice[1] = copy[3]
    return dice
 
 
def check():
    global dice0
    global dice1
 
    
    num = 0
    while dice0[0] != dice1[0]:
        if num % 2 == 0:
            dice0 = dice_roll(dice0, 'E')
        else:
            dice0 = dice_roll(dice0, 'N')
        num += 1
        if num > 10:
            return False
 
    
    num = 0
    while dice0[1] != dice1[1]:
        dice0 = dice_roll(dice0, 'R')
        num += 1
        if num > 10:
            return False
 
    if dice0[2] == dice1[2] and dice0[3] == dice1[3] and dice0[4] == dice1[4] and dice0[5] == dice1[5]:
        return True
    else:
        return False
 
result = check()
if result:
    print('Yes')
else:
    
    dice0 = dice_roll(dice0, 'N')
    result = check()
    if result:
        print('Yes')
    else:
        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):
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.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
     
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}
 
    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]
 
        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
 
import random
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
u,s,e,w,n,d=map(int,input().split())
dice_b=Dice(u,w,s,e,n,d)
ok=False
for i in range (1000):
    dice.rot(random.randint(0,3))
    if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
        ok=True
if ok:
    print('Yes')
else :
    print('No')

Solution (Python):



import sys

def getKeyFromValue(dice, value):
    keys = [k for k, v in dice.items() if v == value]
    if keys:
        return keys[0]
    return None


def initDice(numbers):  
        
    dice = {'top': numbers[0], 'bottom': numbers[5], 'front': numbers[1],
            'back': numbers[4], 'right': numbers[2], 'left': numbers[3]}
    return dice


def rollDice(dice, direction):  
    if direction == 'N':
        top = dice['front']
        bottom = dice['back']
        front = dice['bottom']
        back = dice['top']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['front'] = front
        dice['back'] = back
    elif direction == 'S':
        top = dice['back']
        bottom = dice['front']
        front = dice['top']
        back = dice['bottom']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['front'] = front
        dice['back'] = back
    elif direction == 'E':
        top = dice['left']
        bottom = dice['right']
        right = dice['top']
        left = dice['bottom']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['right'] = right
        dice['left'] = left
    elif direction == 'W':
        top = dice['right']
        bottom = dice['left']
        right = dice['bottom']
        left = dice['top']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['right'] = right
        dice['left'] = left
    return dice


def spinDice(dice):
    front = dice['right']
    right = dice['back']
    back = dice['left']
    left = dice['front']
    dice['front'] = front
    dice['right'] = right
    dice['back'] = back
    dice['left'] = left
    return dice

def assertDice(dice_1, dice_2):
    if dice_1 == dice_2:
        print('Yes')
        sys.exit()


def checkDice(dice_1,dice_2):
    assertDice(dice_1, dice_2)
    
    for i in range(3):
        dice_1 = spinDice(dice_1)
        
        assertDice(dice_1, dice_2)

numbers_1 = [int(i) for i in input().split()]
dice_1 = initDice(numbers_1)
numbers_2 = [int(i) for i in input().split()]
dice_2 = initDice(numbers_2)


checkDice(dice_1,dice_2)





roll_directions = [['N'], ['S'], ['W'],['E'],['N','N']]







dice_1 = initDice(numbers_1)

for direction in roll_directions:
    for d in direction:
        dice_1 = rollDice(dice_1, d)
    checkDice(dice_1,dice_2)
    dice_1 = initDice(numbers_1)
































print('No')