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):
nums = list(map(int, input().split()))
nums2 = list(map(int, input().split()))

import random

class dice:
    def __init__(self):
        self.top = 0
        self.right = 0
        self.front = 0
        self.left = 0
        self.back = 0
        self.bottom = 0
    
    def set_num(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums
        return self
    
    def get_right(self, f_top, f_front):
        while f_top!=self.top or f_front!=self.front:
            self.roll(random.randint(0,3))
        return self.right
    
    def check(self, dice2):
        cnt=0
        while cnt<10000:
            if self.is_same(dice2):
                return True
            cnt+=1
            self.roll(random.randint(0,3))
        
        return False
        
        
    def is_same(self, dice2):
        if (self.top, self.right, self.left, self.front, self.back, self.bottom)==(d2.top, d2.right, d2.left, d2.front, d2.back, d2.bottom):
            return True
        else:
            return
        
    def roll(self, command):
        if command==0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.left, self.front, self.top, self.bottom, self.back, self.right
        elif command==1:
            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 command==2:
            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 command==3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.back, self.top, self.right, self.left, self.bottom, self.front
            

d = dice()
d.set_num(nums)
d2 = dice()
d2.set_num(nums2)

if d.check(d2):
    print('Yes')
else:
    print('No')

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

  def vertical(self, direction):
    s = self.state
    state = [s[1], s[5], s[0], s[4]]
    if direction < 0:
      s[0], s[1], s[4], s[5] = state
    elif 0 < direction:
      s[0], s[1], s[4], s[5] = reversed(state)
    return self
  
  def lateral(self, direction):
    s = self.state
    state = [s[2], s[5], s[0], s[3]]
    if direction < 0:
      s[0], s[2], s[3], s[5] = state
    elif 0 < direction:
      s[0], s[2], s[3], s[5] = reversed(state)
    return self

  def north(self):
    self.vertical(-1)
    return self

  def south(self):
    self.vertical(1)
    return self
  
  def east(self):
    self.lateral(1)
    return self

  def west(self):
    self.lateral(-1)
    return self

dice1 = Dice(input().split())
dice2 = Dice(input().split())

if dice1.state == dice2.state:
  print('Yes')
else:
  is_eql = False
  for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
    if c == 'N':
      dice1.north()
    elif c == 'S':
      dice1.south()
    elif c == 'W':
      dice1.west()
    elif c == 'E':
      dice1.east()
    if dice1.state == dice2.state:
      is_eql = True
      break
  print('Yes' if is_eql else '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):
import random

class  Dise:
    def __init__(self,top,flont,right,left,back,bottom):
        self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom
        
    def rot(self,d):
        if d=='N':
            self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top
        elif d=='E':
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        elif d=='S':
                self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom
        elif d=='W':
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
    
    def gettop(self):
        return self.top
    def getfront(self):
        return self.flont
    def getright(self):
        return self.right
    def getleft(self):
        return self.left
    def getback(self):
        return self.back
    def getbottom(self):
        return self.bottom
    
n1=list(map(int,input().split()))
n2=list(map(int,input().split()))

dise1=Dise(n1[0],n1[1],n1[2],n1[3],n1[4],n1[5])
dise2=Dise(n2[0],n2[1],n2[2],n2[3],n2[4],n2[5])
for j in range(1000):
    dise1.rot(random.choice('NESW'))
    if dise1.gettop()==dise2.gettop() and dise1.getfront()==dise2.getfront() and dise1.getright()==dise2.getright() and dise1.getleft()==dise2.getleft() and dise1.getback()==dise2.getback() and dise1.getbottom()==dise2.getbottom():
        print("Yes")
        break
if j==999:
    print("No")

Solution (Python):

class Dice():
 East = [ [0,3,5,2,4,0]
		 ,[4,0,1,6,0,3]
		 ,[2,6,0,0,1,5]
		 ,[5,1,0,0,6,2]
		 ,[3,0,6,1,0,4]
		 ,[0,4,2,5,3,0]
		 ]
 def __init__(self,N):
  self.label = N
  self.top = 1
  self.north = 5
 def move(self,ori):
  
  if ori=='S':
   t = self.top
   self.top = self.north
   self.north = 7-t
  elif ori=='N':
   t = self.top
   self.top = 7-self.north
   self.north = t
  elif ori=='E':
   east = self.East[self.north-1][self.top-1]
   self.top = 7-east
  elif ori=='W':
   east = self.East[self.north-1][self.top-1]
   self.top = east

  elif ori=='C': 
   east = self.East[self.north-1][self.top-1]
   self.north = east
 def gettop(self):
  return( self.label[self.top-1] )
 def getbottom(self):
  return( self.label[6-self.top] )
 def getnorth(self):
  return( self.label[self.north-1] )
 def getsouth(self):
  return( self.label[6-self.north] )
 def geteast(self):
  east = self.East[self.north-1][self.top-1]
  return( self.label[east-1] )
 def getwest(self):
  east = self.East[self.north-1][self.top-1]
  return( self.label[6-east] )

label = list(map(int, input().split() ))
D = Dice(label)
label = list(map(int, input().split() ))
E = Dice(label)


sMove = 'NNNEEE'
for mi in range(len(sMove)+1):
 if D.gettop() == E.gettop() and D.getbottom() == E.getbottom():
  sRot = 'CCCC'
  for ri in range(len(sRot)):
   if D.getnorth() == E.getnorth() and D.geteast() == E.geteast() and D.getsouth() == E.getsouth() and D.getwest() == E.getwest():
    print('Yes')
    exit()
   if ri<len(sRot):
    E.move(sRot[ri])
 if mi<len(sMove):
  E.move(sMove[mi])
print('No')

Solution (Python):

def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1


def dice_find(list1, int1, int2):
    position_numnber = list1.index(int2)
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    position_numnber = list1.index(int1)
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1


input_number = list(map(int, input().split()))
check_number = list(map(int, input().split()))


check_number = dice_find(check_number, input_number[0], input_number[1])


if input_number == check_number:
    print("Yes")
else:
    print("No")

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

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

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

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

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

    def up_front_to_right(self, top, front):
        if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]:
            return self.right
        elif (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]:
            return self.left
        elif (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]:
            return self.top
        elif (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]:
            return self.bottom
        elif (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]:
            return self.front
        elif (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]:
            return self.back
        else:
            return -1
            
    def inverse(self,a):
        if a==self.top:
            return self.bottom
        elif a==self.front:
            return self.back
        elif a==self.right:
            return self.left
        elif a==self.left:
            return self.right
        elif a==self.back:
            return self.front
        elif a==self.front:
            return self.back
        else:
            return -1
            
*x,=map(int,input().split())
*y,=map(int,input().split())
dice0=Dice(x)
dice1=Dice(y)
for i in x:
    for j in x:
        if i!=j and i!=dice0.inverse(j):
            a=dice0.up_front_to_right(i,j)
            b=dice1.up_front_to_right(i,j)
            if a!=b:
                print('No')
                exit()
print('Yes')

Solution (Python):
import random
def dice(a,b,c,d,e,f,l):
    if l == "N":
        return [b,f,c,d,a,e]
    if l == "S":
        return [e,a,c,d,f,b]
    if l == "E":
        return [d,b,a,f,e,c]
    if l == "W":
        return [c,b,f,a,e,d]
d = list(map(int, input().split()))
s = ["W","N","E","S"]
a,b,c,g,e,f = map(int ,input().split())
j = 0
while j <= 10000:
    k = random.randrange(4)
    d = dice(d[0],d[1],d[2],d[3],d[4],d[5],s[k])
    if d[0] == a and d[1] == b and d[2] == c and d[3] == g and d[4] == e and d[5] == f:
        print("Yes")
        break
    if j == 10000:
        print("No")
    j += 1

Solution (Python):
import math

class Dice():
    top   = 0 
    left  = 0 
    right = 0 
    front = 0 
    back  = 0 
    below = 0 

    DEBUG_MODE = False
    def __init__(self,lst,dbg = False):
        if len(lst) == 6:
            self.top   = lst[0]
            self.front = lst[1]
            self.right = lst[2]
            self.left  = lst[3]
            self.back  = lst[4]
            self.below = lst[5]

        if dbg == True:
            self.DEBUG_MODE = True
        else:
            self.DEBUG_MODE = False
    
    def rotate(self,string):
        
        for ch in string:
            if   ch == 'W':
                self.left,self.top,self.right,self.below = self.top,self.right,self.below,self.left

            elif ch == 'E':
                self.left,self.top,self.right,self.below = self.below,self.left,self.top,self.right

            elif ch == 'S':
                self.top,self.back,self.below,self.front = self.back,self.below,self.front,self.top

            elif ch == 'N':
                self.top,self.back,self.below,self.front = self.front,self.top,self.back,self.below
            
            
            if self.DEBUG_MODE:
                self.dbg_PRINT_ALL_VALUE()

    def front_and_top_to_right(self,top,front):

        for i in range(4):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") 
        
        for i in range(2):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("SS")
        
        return None

    def equals(self,dice):
        if not isinstance(dice,Dice):
            return False

        for i in range(4):
            for j in range(4):
                if self.__non_rotate_equals(dice):
                    return True
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") 
        
        for i in range(2):
            for j in range(4):
                if self.__non_rotate_equals(dice):
                    return True
                self.rotate("W")
            self.rotate("SS")
        
        return False

    def __non_rotate_equals(self,dice):
        if (self.top   == dice.top   and
            self.left  == dice.left  and
            self.right == dice.right and
            self.front == dice.front and
            self.back  == dice.back  and
            self.below == dice.below ) :
            return True
        
        return False


        
    def get_topvalue(self):
        return self.top
    
    def dbg_PRINT_ALL_VALUE(self):
        print(f"        bk:{self.back:04} ")
        print(f"le:{self.left:04} tp:{self.top:04} ri:{self.right:04} be:{self.below:04}")
        print(f"        fr:{self.front:04} ")


lst  = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
dice = Dice(lst)
dice2 = Dice(lst2)

if dice.equals(dice2):
    print("Yes")
else:
    print("No")

Solution (Python):
import random
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
    def output(self):
        return self.dice
    def move(self, direction):
        for _ in direction: self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

dice_1 = Dice([int(x) for x in input().split()])
dice_2 = Dice([int(x) for x in input().split()])

Dir = 'NSEW'

for _ in range(10000):
    dice_2.move(Dir[random.randint(0,3)])
    if dice_1.output() == dice_2.output(): break

print('No') if _ == 9999 else print('Yes')

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

def dicing(lis, inst):
    if inst == 'N':
        ans_lis = [lis[1],lis[5],lis[2],lis[3],lis[0],lis[4]]
    if inst == 'W':
        ans_lis = [lis[2],lis[1],lis[5],lis[0],lis[4],lis[3]]
    if inst == 'S':
        ans_lis = [lis[4],lis[0],lis[2],lis[3],lis[5],lis[1]]
    if inst == 'E':
        ans_lis = [lis[3],lis[1],lis[0],lis[5],lis[4],lis[2]]
    
    return(ans_lis)

def turn_right(lis):
    inst = list('ENW')
    for i in range(len(inst)):
        lis = dicing(lis, inst[i])
    return(lis)

def find_above(lis, num1, num2):
    inst1 = list('NNNEWW')
    for i in range(len(inst1)):
        if lis[0] == num1 and lis[5] == num2:
            break
        
        lis = dicing(lis, inst1[i])
        if lis[0] == num1 and lis[5] == num2:
            break
    return(lis)

YN = 'No'

lis = [1,2,3,4,5,6]
lis = find_above(dice1, dice2[0], dice2[5])
for j in range(4):
    lis = turn_right(lis)
    if lis == dice2:
        YN = 'Yes'
        break

print(YN)

Solution (Python):
from collections import deque

class Dice():
    def __init__(self, seq):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

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

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input().split(" ")

    seq = [int(a) for a in param]
    d1 = Dice(seq)

    param = input().split(" ")

    seq = [int(a) for a in param]
    d2 = Dice(seq)

    top1 = d1.disp_top_face()
    front1 = d1.disp_front_face()

    flag = 1

    while(flag):

        for _ in range(4):

            d2.lotate("S")

            if d2.disp_top_face() == top1:
                flag = 0
                break

        if flag :
            d2.lotate("E")

    for _ in range(4):

        if d1.disp_front_face() == d2.disp_front_face():
            break

        d2.lotate("E")
        d2.lotate("S")
        d2.lotate("W")

    
    
    
    
    
    

    if d2.disp_bottom_face() == d1.disp_bottom_face() and \
       d2.disp_front_face() == d1.disp_front_face() and \
       d2.disp_left_face() == d1.disp_left_face() and \
       d2.disp_right_face() == d1.disp_right_face() and \
       d2.disp_back_face() == d1.disp_back_face():
       print("Yes")
    else:
       print("No")

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

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['west'], self.label['top'], self.label['bottom'], self.label['east'])

    def __roll_to_west(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['east'], self.label['bottom'], self.label['top'], self.label['west'])

    def __roll_to_south(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['north'], self.label['top'], self.label['bottom'], self.label['south'])

    def __roll_to_north(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['south'], self.label['bottom'], self.label['top'], self.label['north'])

    def __turn_right(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['east'], self.label['north'], self.label['south'], self.label['west'])

    def __turn_left(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['west'], self.label['south'], self.label['north'], self.label['east'])

def check_same_dice(dice1, dice2):
    for direction in ['top', 'bottom', 'east', 'west', 'south', 'north']:
        if dice1.label[direction] != dice2.label[direction]:
            return False
    return True

dice_labels1 = input().split(' ')
dice_labels2 = input().split(' ')
dice1 = Dice(dice_labels1)
dice2 = Dice(dice_labels2)
same_pattern_list = []

for i in range(0, 4):
    for j in range(0, 4):
        for k in range(0, 4):
            dice2.roll('E')
            same_pattern_list.append(check_same_dice(dice1, dice2))
        dice2.roll('N')
        same_pattern_list.append(check_same_dice(dice1, dice2))
    dice2.turn('R')
    same_pattern_list.append(check_same_dice(dice1, dice2))

if True in same_pattern_list:
    print('Yes')
else:
    print('No')

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

*L1, = map(int, input().split())
*L2, = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)*3
ok = 0
for k in p:
    if L1 == L2:
        ok = 1
    L2[:] = [L2[e] for e in D[k]]

print("Yes" if ok else "No")

Solution (Python):
def lotate(dic, dire):
    if dire == 'N':
        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
    elif dire == 'S':
        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
    elif dire == 'W':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
    elif dire == 'E':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
    return dic


a1,b1,c1,d1,e1,f1 = map(int, input().split())
a2,b2,c2,d2,e2,f2 = map(int, input().split())
dic1 = {'up': a1, 'front': b1, 'right': c1, 'left': d1, 'back': e1, 'bottom': f1}
dic2 = {'up': a2, 'front': b2, 'right': c2, 'left': d2, 'back': e2, 'bottom': f2}
ans = 'No'
if dic1 == dic2:
    ans = 'Yes'
else:
    s = 'EEENEEENEEESEEESEEENEEEN'
    for i in s:
        dic2 = lotate(dic2, i)
        if dic1 == dic2:
            ans = 'Yes'
            break
print(ans)

Solution (Python):
import random


class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]
        self.back = self.faces[6]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down, self.back = self.down, self.top, self.back, self.up
        elif direction == "S":
            self.top, self.up, self.down, self.back = self.up, self.back, self.top, self.down
        elif direction == "W":
            self.top, self.left, self.right, self.back = self.right, self.top, self.back, self.left
        elif direction == "E":
            self.top, self.left, self.right, self.back = self.left, self.back, self.top, self.right
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def __eq__(self, other):
        return (
           self.top, self.up, self.left, self.down, self.right, self.back
        ) == (
            other.top, other.up, other.left, other.down, other.right, other.back
        )


f1 = [int(i) for i in input().split()]
f2 = [int(i) for i in input().split()]
dice1 = Dice(*f1)
dice2 = Dice(*f2)
ans = "No"
i = 0
while i < 10000:
    if dice1 == dice2:
        ans = "Yes"
        break
    dice2.roll(random.choice(["N", "S", "W", "E"]))
    i += 1
print(ans)

Solution (Python):
change=list( map(int,input().split()))
change_after=list( map(int,input().split()))

def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]
def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]
def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]
def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]
def Rot(a,b,c,d,e,f):
    return [a,d,b,e,c,f]



flag=0
for idx in range(0, 5):
    change=South(*change)
    if change==change_after:
        flag=flag+1
    for idx2 in range(0,4):
        change=Rot(*change)
        if change==change_after:
           flag=1+flag
           
for idx in range(0, 5):
    change=West(*change)
    if change==change_after:
        flag=flag+1
    for idx2 in range(0,4):
        change=Rot(*change)
        if change==change_after:
           flag=1+flag
if flag==0:
    print("No")
else:
    print("Yes")