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):
buff = "NNNNWNNNWNNNENNNENNNWNNN"

class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                
                return self.num[m]
        
        def return_lst(self):
                return self.num

def isSameDice(D1, D2):
        for d in buff:
                D1.roll(d)
                if D1.return_lst() == D2.return_lst():
                        return True
        return False

lst = [ int(i) for i in input().split() ]
D1 = Dice(lst)

lst = [ int(i) for i in input().split() ]
D2 = Dice(lst)

if isSameDice(D1, D2):
        print("Yes")
else:
        print("No")

Solution (Python):
d1=input().split()
d2=input().split()
m=[[1,2,4,3,1],[5,2,0,3,5],[5,4,0,1,5],[5,1,0,4,5],[5,3,0,2,5],[4,2,1,3,4]]
ans='No'

if sorted(d1)==sorted(d2):
    if len(set(d1))>=4:
        for i in range(3):
            if d1[5-i]==d2[5-d2.index(d1[i])]:
                mae,migi=[d1[m[i][s]] for s in range(2)]
                for j in range(4):
                    if mae==d2[m[d2.index(d1[i])][j]] and migi==d2[m[d2.index(d1[i])][j+1]]:
                        ans='Yes'
                        break
            else:
                ans='No'
                break
    else:
        ans='Yes'

print(ans)

Solution (Python):
class Dice:
    def __init__(self, labels):
        self.labels = labels
        
    def __str__(self):
        return str(self.labels[0])
    
    def roll_south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]
            
    def roll_east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    
    def roll_west(self):
        self.labels[0], self.labels[3], self.labels[5], self.labels[2] = self.labels[2], self.labels[0], self.labels[3], self.labels[5]
    
    def roll_north(self):
        self.labels[0], self.labels[4], self.labels[5], self.labels[1] = self.labels[1], self.labels[0], self.labels[4], self.labels[5]
        
    def get_faces(self):
        return self.labels
        
def main():
    labels0 = list(map(int, input().split()))
    labels = list(map(int, input().split()))
    d = Dice(labels)
    
    d0 = Dice(labels0)
    f = labels0[0]
    for i in labels0:
        if labels0.count(i) < labels0.count(f):
            f = i
    ind = labels0.count(f)
    if ind == 1:
        d0.roll_north()
    elif ind == 4:
        d0.roll_south()
    else:
        while d0.get_faces()[0] != f:
            d.roll_east()
    labels0 = d0.get_faces()
    

    ind0 = labels.index(labels0[0])
    ind1 = labels.index(labels0[1])
    if ind0 == 1:
        d.roll_north()
    elif ind0 == 4:
        d.roll_south()
    else:
        while d.get_faces()[0] != labels0[0]:
            d.roll_east()
    while d.get_faces()[1] != labels0[1]:
        d.roll_east()
        d.roll_south()
        d.roll_west()
    for i in range(2,6):
        if d.get_faces()[i] != labels0[i]:
            print('No')
            return
    print('Yes')
    return
            
main()

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 set(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 kaiten(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.set(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.set(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.set(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.set(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def tansaku(self,top_num,front_num):
 
        self.save = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save[i] = self.number[i]
 
        ret = -1;
 
        for i in range(len(self.order)):
            self.kaiten(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[i]
 
        return ret;
 
    def hyouka(self,b):
        for i in range(len(self.order)):
            self.kaiten(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != b.number[k]: 
                    FLG = False
                    break
            if FLG == True:
                return True
        
        return False
        
 
 
A = Dice()
B = Dice()

table = list(map(int,input().split()))
A.set(table[0], table[1], table[2], table[3], table[4], table[5])

table = list(map(int,input().split()))
B.set(table[0], table[1], table[2], table[3], table[4], table[5])

if A.hyouka(B):
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice():

    patterns = {"N":[1,5,2,3,0,4],"S":[4,0,2,3,5,1],"W":[2,1,5,0,4,3],"E":[3,1,0,5,4,2]}

    def __init__(self):
        self.number = [i for i in range(6)]

    
    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,command,int):
        for i in command:
            self.number = [self.number[j] for j in self.patterns[i]]
        return self.number[int]


dice = Dice()


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

dice.setNumber(d2[0],d2[1],d2[2],d2[3],d2[4],d2[5])

command1 = ["S","S","S","S","E","E","E"] 
command2 = ["S","E","N","S","E","N","S","E","N","S","E","N"] 

chk = False
for i in command1:
    if d1[0] == dice.roll(i,0):
        for j in command2:
            if d1[1] == dice.roll(j,1):
                if d1[2] == dice.number[2] and d1[3] == dice.number[3] and d1[4] == dice.number[4] and d1[5] == dice.number[5]:
                    chk = True
                else:chk = False
            else:continue
    else:continue

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

Solution (Python):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = ['402351', '152304', '310542', '215043']   
t = []
t.append(a)
i = 0; j = 0
while True:
    if t[i][0] == b[0] and t[i][1] == b[1]:
        ans = "Yes" if t[i][2] == b[2] and t[i][3] == b[3] else "No"
        print(ans)
        break
    if i == len(t)-1: 
        for h in range(len(s)):
            t.append([ t[j][int(k)] for k in list(s[h]) ])
        j+=1
    i+=1

Solution (Python):
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

surfaceNum1 = [int(i) for i in input().split()]
surfaceNum2 = [int(i) for i in input().split()]
rollCommandList = ["E", "W", "S", "N"]
dice1 = Dice(surfaceNum1)
dice2 = Dice(surfaceNum2)
counter = 0
    
while True:
    counter += 1
    rollCommand = random.choice(rollCommandList)
    if rollCommand == "E":
        dice2.east()
    if rollCommand == "W":
        dice2.west()
    if rollCommand == "S":
        dice2.south()
    if rollCommand == "N":
        dice2.north()
    if counter == 10000:
        print('No')
        break
        
    if dice1.surface == dice2.surface:
        print('Yes')
        break

Solution (Python):
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]

    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True



p1 = [ int(n) for n in input().split()]
p2 = [ int(n) for n in input().split()]

dice1 = Dice(p1)
dice2 = Dice(p2)


print('Yes' if dice1.same(dice2) else 'No')

Solution (Python):
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True

p1 = [ int(n) for n in input().split()]
p2 = [ int(n) for n in input().split()]

dice1 = Dice(p1)
dice2 = Dice(p2)

print('Yes' if dice1.same(dice2) else 'No')

Solution (Python):
n1 = list(map(int,input().split()))
n2 = list(map(int,input().split()))
a = "No"
for i in range(6):
    for j in range(4):
        n1 = [n1[0],n1[3],n1[1],n1[4],n1[2],n1[5]]
        if n1 == n2:
            a = "Yes"
    if i % 2 == 0:
        n1 = [n1[4],n1[0],n1[2],n1[3],n1[5],n1[1]]
    else:
        n1 = [n1[2],n1[1],n1[5],n1[0],n1[4],n1[3]]
print(a)

Solution (Python):

class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N(self):
        ls = self.S().S().S().ls
        return Dice(ls)
        
    def E(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W(self):
        ls = self.E().E().E().ls
        return Dice(ls)
        
        
        
    def R_rot(self):
        return self.E().S().W()
        
    def rot(self, num):
        for _ in range(num):
            self = self.R_rot()
        return self
    
        
ls = list(map(int, input().split()))
LS = list(map(int, input().split()))

a = Dice(ls)
b = Dice(LS)



me = [a, a.N(), a.W(), a.E(), a.S(), a.S().S()]

judge = False
for i in me:
    for j in range(4):
        
        if i.rot(j).ls == b.ls:
            judge = True

if judge == True:
    print('Yes')
else:
    print('No')

Solution (Python):

import copy
class Dice:
    
    def __init__(self, d):
        self.data = {"bottom":d[5], "north":d[4], "west": d[3],
                    "east":d[2],"south":d[1],"top":d[0]}

    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self, directions):
        for direction in directions:
            self.moveOne(direction)
            
    def setDiceII(self, a, b):
        if self.data["east"] == a:
            self.moveOne("W")
        elif self.data["north"] == a:
            self.moveOne("S")
        elif self.data["west"] == a:
            self.moveOne("E")
        elif self.data["south"] == a:
            self.moveOne("N")
        elif self.data["bottom"] == a:
            self.movePart("WW")

        if self.data["north"] == b:
            self.rotateRight()
            self.rotateRight()
        elif self.data["east"] == b:
            self.rotateRight()
        elif self.data["west"] == b:
            self.rotateLeft()
            
        
    
    def rotateRight(self):
        temp = self.data["east"]
        self.data["east"] = self.data["north"]
        self.data["north"] = self.data["west"]
        self.data["west"] = self.data["south"]
        self.data["south"] = temp
    
    def rotateLeft(self):
        temp = self.data["west"]
        self.data["west"] = self.data["north"]
        self.data["north"] = self.data["east"]
        self.data["east"] = self.data["south"]
        self.data["south"] = temp
      
    def getSurface(self):
        return self.data["top"]
    
    def getEast(self):
        return self.data["east"]
    
    def getData(self):
        return self.data
    
    def getPatterns(self):
        patterns = []
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.rotateRight()
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        return patterns
                

    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])

num1 = list(map(int,input().rstrip().split()))
num2 = list(map(int,input().rstrip().split()))
dice1 = Dice(num1)
dice2 = Dice(num2)
flag = False
for i in dice2.getPatterns():
    if dice1.getData()==i:
        print("Yes")
        flag = True
        break;
if not flag:
    print("No")

Solution (Python):
dice1_ = [int(i) for i in input().split()]
dice1 = {
	(0,0,0):100000,
    (0,0,1):dice1_[0],
    (0,-1,0):dice1_[1],
    (1,0,0):dice1_[2],
    (-1,0,0):dice1_[3],
    (0,1,0):dice1_[4],
    (0,0,-1):dice1_[5]
}
rdice1 = {
    dice1_[0]:(0,0,1),
    dice1_[1]:(0,-1,0),
    dice1_[2]:(1,0,0),
    dice1_[3]:(-1,0,0),
    dice1_[4]:(0,1,0),
    dice1_[5]:(0,0,-1)
}

dice2_ = [int(i) for i in input().split()]
dice2 = {
	(0,0,0):100000,
    (0,0,1):dice2_[0],
    (0,-1,0):dice2_[1],
    (1,0,0):dice2_[2],
    (-1,0,0):dice2_[3],
    (0,1,0):dice2_[4],
    (0,0,-1):dice2_[5]
}
rdice2 = {
    dice2_[0]:(0,0,1),
    dice2_[1]:(0,-1,0),
    dice2_[2]:(1,0,0),
    dice2_[3]:(-1,0,0),
    dice2_[4]:(0,1,0),
    dice2_[5]:(0,0,-1)
}

c = [[dice1_[0],i] for i in dice1_[1:]] + [[dice1_[1],i] for i in dice1_[2:]] + [[dice1_[2],i] for i in dice1_[3:]] + [[dice1_[3],i] for i in dice1_[4:]] +[[dice1_[4],i] for i in dice1_[5:]] + [[dice1_[5],i] for i in dice1_[6:]]
def cross(a,b):
	return(a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0])
istrue = sum([1 - int(i) for i in [dice1[cross(rdice1[a],rdice1[b])] == dice2[cross(rdice2[a],rdice2[b])] for a,b in c]])
if istrue == 0:
	print("Yes")
else:
	print("No")

Solution (Python):
id1 = list(map(int, input().split()))
id2 = list(map(int, input().split()))


class die:
    face = [0, 0, 0, 0, 0, 0]

    def __init__(self, nums):
        self.face = [nums[f] for f in [0, 3, 1, 2, 4, 5]]

    def roll(self, dirs):

        for di in dirs:
            c_face = list(self.face)
            if di == 'S':
                self.face = [c_face[f] for f in [4, 1, 0, 3, 5, 2]]
            elif di == 'N':
                self.face = [c_face[f] for f in [2, 1, 5, 3, 0, 4]]
            elif di == 'W':
                self.face = [c_face[f] for f in [3, 0, 2, 5, 4, 1]]
            elif di == 'E':
                self.face = [c_face[f] for f in [1, 5, 2, 0, 4, 3]]
            

        return list(self.face)


def four_roll(d, d2):
    for r in 'SSSS':
        d.roll(r)
        if d.face == d2.face:
            print('Yes')
            return True


d2 = die(id2)
for md in (' ', 'W', 'E', 'NW', 'NE', 'WW'):
    d1 = die(id1)
    d1.roll(md)
    if four_roll(d1, d2):
        break
else:
    print('No')

Solution (Python):
import math


class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def roll_east(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def roll_north(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def roll_south(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def roll_west(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def spin_left(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp

    def check(self, dice2):
        ans = False
        for x in range(4):
            if dice2.south == self.south:
                if dice2.east == self.east and dice2.west == self.west and \
                        dice2.north == self.north and dice2.bottom == self.bottom:
                    ans = True
            self.spin_left()
        return ans

    def top_check(self, dice2):
        ans = False
        if dice2.top == self.top:
            ans |= self.check(dice2)
        if dice2.top == self.south:
            self.roll_north()
            ans |= self.check(dice2)
        if dice2.top == self.east:
            self.roll_west()
            ans |= self.check(dice2)
        if dice2.top == self.west:
            self.roll_east()
            ans |= self.check(dice2)
        if dice2.top == self.north:
            self.roll_south()
            ans |= self.check(dice2)
        if dice2.top == self.bottom:
            self.roll_south()
            self.roll_south()
            ans |= self.check(dice2)
        if ans:
            print("Yes")
        else:
            print("No")


a, b, c, d, e, f = map(int, input().split())
dice = Dice(a, b, c, d, e, f)
a, b, c, d, e, f = map(int, input().split())
dice2 = Dice(a, b, c, d, e, f)
dice.top_check(dice2)

Solution (Python):
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] 
        self.nowkey = 0
        self.c_key = 5
        self.nowval = li[0]
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 
    def operate(self, s):
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = self.c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = self.c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = self.c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = self.c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]
        self.c_key = abs(5 - self.nowkey)
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 

a = list(map(int, input().split()))
b = list(map(int, input().split()))
diceA = DICE(li = a)
diceB = DICE(li = b)
s = 'NNNNWNNNNWNNNNWNNNN'+'NEEEENEEEENEEEENEEEE'+'ENWWWWNWWWWNWWWWNWWWWW'
flag = False
for i in s:
    diceA.operate(i)
    if diceA.distvals == diceB.distvals:
        print('Yes')
        flag = True
        break
if flag == False:
    print('No')

Solution (Python):
class Dice:
        def __init__(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def reset(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def rollE(self):
                temp = self.label[3]
                self.label[3] = self.label[5]
                self.label[5] = self.label[2]
                self.label[2] = self.label[0]
                self.label[0] = temp
        def rollN(self):
                temp = self.label[0]
                self.label[0] = self.label[1]
                self.label[1] = self.label[5]
                self.label[5] = self.label[4]
                self.label[4] = temp
        def rollA(self):
                temp = self.label[3]
                self.label[3] = self.label[4]
                self.label[4] = self.label[2]
                self.label[2] = self.label[1]
                self.label[1] = temp
        def printDice(self):
                print(self.label)

def check(d1, d2):
        for i in range(6):
                if d1.label[i] != d2.label[i]:
                        return False
        return True

strDice = input()
diceList = strDice.split()
dice1 = Dice(diceList)

strDice = input()
diceList = strDice.split()
dice2 = Dice(diceList)
isEqual = False

for j in range(6):
        for k in range(4):
                dice1.rollA()
                if check(dice1, dice2):
                        isEqual = True
        if j % 2 == 0:
                dice1.rollE()
        else:
                dice1.rollN()

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

Solution (Python):
dice1 = input().split()
dice2 = input().split()


d1 = {dice2[0]: "123456", dice2[1]: "263415", dice2[2]: "326154", dice2[3]: "421653", dice2[4]: "513462",
      dice2[5]: "653421"}
dice2 = [dice2[int(i) - 1] for i in d1[dice1[0]]]

d2 = {dice2[1]: "123456", dice2[2]: "135246", dice2[3]: "142536", dice2[4]: "154326"}
dice2 = [dice2[int(i) - 1] for i in d2[dice1[1]]]

dice1 = sorted([[dice1[0], dice1[3]], [dice1[1], dice1[4]], [dice1[2], dice1[5]]])
dice2 = sorted([[dice2[0], dice2[3]], [dice2[1], dice2[4]], [dice2[2], dice2[5]]])
if dice1 == dice2:
    print("Yes")
else:
    print("No")

Solution (Python):
def rotateDice(direction: str, dice: list) -> list:
    s = {'N': "152304", 'W': "215043", 'E': "310542", 'S': "402351", 'R': "031425", 'L': "024135"}
    dice = [dice[int(i)] for i in s[direction]]
    return dice


dice1 = input().split()
dice2 = input().split()
all_dice_list = []
for i in range(4):
    dice1 = rotateDice('E', dice1)
    for j in range(4):
        dice1 = rotateDice('N', dice1)
        for k in range(4):
            dice1 = rotateDice('R', dice1)
            all_dice_list.append(dice1)

counter = 0
for _list in all_dice_list:
    if _list == dice2:
        print('Yes')
        counter += 1
        break

if counter == 0:
    print('No')

Solution (Python):
f = list(map(int, input().split()))
a = list(map(int, input().split()))
b = 0
for i in range(4):
	t = a[0]
	a[0] = a[2]
	a[2] = a[5]
	a[5] = a[3]
	a[3] = t
	for j in range(4):
		t = a[1]
		a[1] = a[2]
		a[2] = a[4]
		a[4] = a[3]
		a[3] = t
		if a == f:
			b = 1
for i in range(4):
	t = a[0]
	a[0] = a[1]
	a[1] = a[5]
	a[5] = a[4]
	a[4] = t
	for j in range(4):
		t = a[1]
		a[1] = a[2]
		a[2] = a[4]
		a[4] = a[3]
		a[3] = t
		if a == f:
			b = 1
if b:
	print("Yes")
else:
	print("No")

Solution (Python):
D = [[1, 3, 4, 2], [5, 3, 0, 2], [5, 1, 0, 4], [5, 4, 0, 1], [2, 0, 3, 5], [1, 2, 4, 3]]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
count = 0
for i, j in enumerate(a):
    if a.count(j) > 1:
        count += 1
        continue
    A = [a[k] for k in D[i]]
    B = [b[k] for k in D[b.index(j)]]
    if A != B:
        B = B[B.index(A[0]):] + B[:B.index(A[0])]
    if A == B:
        count += 1
if count == 6:
    print("Yes")
else:
    print("No")