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):
        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])
        else:
            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])
            flag = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    flag = False
                    break
            if flag == True:
                return True
        
        return ret
          

dice1 = Dice()
dice2 = Dice()
table = list(map(int, input().split()))
dice1.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])

table2 = list(map(int, input().split()))
dice2.setNumber(table2[0],table2[1],table2[2],table2[3],table2[4],table2[5])










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

Solution (Python):
import random

class Dice():
    def __init__(self, number):
        self.number = number

    def S(self):
        temp = self.number
        self.number = [temp[4], temp[0], temp[2], temp[3], temp[5], temp[1]]

    def N(self):
        temp = self.number
        self.number = [temp[1], temp[5], temp[2], temp[3], temp[0], temp[4]]

    def E(self):
        temp = self.number
        self.number = [temp[3], temp[1], temp[0], temp[5], temp[4], temp[2]]

    def W(self):
        temp = self.number
        self.number = [temp[2], temp[1], temp[5], temp[0], temp[4], temp[3]]

    def order(self, str):
        for ch in str:
            if ch == "S":
                self.S()
            elif ch == "N":
                self.N()
            elif ch == "E":
                self.E()
            else:
                self.W()

    def query(self, top, front):
        while True:
            drc = random.randint(0, 3)
            self.order("NEWS"[drc])
            if self.number[0] == top and self.number[1] == front:
                break

number1 = list(map(int, input().split()))
number2 = list(map(int, input().split()))

dice1 = Dice(number1)
dice2 = Dice(number2)

dice1.query(dice2.number[0], dice2.number[1])
if dice1.number == dice2.number:
    print("Yes")
else:
    print("No")

Solution (Python):
import enum
class Direction(enum.Enum):
    N = "N"
    E = "E"
    W = "W"
    S = "S"

    @classmethod
    def value_of(cls, value):
        return [v for v in cls if v.value == value][0]


class Dice:
    def __init__(self, *value_list):
        self.__value_list = list(value_list)

    def rotate(self, direction):
        l = self.__value_list
        if  direction == Direction.N:
            l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0]
        elif  direction == Direction.E:
            l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5]
        elif  direction == Direction.W:
            l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0]
        elif  direction == Direction.S:
            l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5]

    def adjust_top_front(self, top_value, front_value):
        for _ in range(2):
            for _ in range(3):
                if self.front_value() == front_value:
                    break
                self.rotate(Direction.N)
            if self.front_value() == front_value:
                break
            self.rotate(Direction.E)
        
        for _ in range(3):
            if self.top_value() == top_value:
                break
            self.rotate(Direction.E)
    
    def is_same_dice(self, othere_dice):
        return (self.top_value() == othere_dice.top_value()
        and self.bottom_value() == othere_dice.bottom_value()
        and self.front_value() == othere_dice.front_value()
        and self.behind_value() == othere_dice.behind_value()
        and self.right_value() == othere_dice.right_value()
        and self.left_value() == othere_dice.left_value())

    def top_value(self):
        return self.__value_list[0]

    def bottom_value(self):
        return self.__value_list[5]

    def front_value(self):
        return self.__value_list[1]

    def behind_value(self):
        return self.__value_list[4]

    def right_value(self):
        return self.__value_list[2]

    def left_value(self):
        return self.__value_list[3]


dice1 = Dice(*input().split())
dice2 = Dice(*input().split())
dice1.adjust_top_front(dice2.top_value(), dice2.front_value())
print("Yes" if dice1.is_same_dice(dice2) else "No")

Solution (Python):
class dice():
    top = 1
    flont = 2
    right = 3
    def do_N(self):
        temp = self.flont
        self.flont = 7-self.top
        self.top = temp

    def do_S(self):
        temp = 7-self.flont
        self.flont = self.top
        self.top = temp

    def do_E(self):
        temp = self.top
        self.top = 7-self.right
        self.right = temp

    def do_W(self):
        temp = 7-self.top
        self.top = self.right
        self.right = temp

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = dice()
dice2 = dice()
flag1 = False
flag2 = False

if num1[dice1.flont-1] == num2[dice2.flont-1] and num1[dice1.top-1] == num2[dice2.top-1]:
    flag1 = True
    if num1[dice1.right-1] == num2[dice2.right-1] and num1[7-dice1.top-1] == num2[7-dice2.top-1] and num1[7-dice1.flont-1] == num2[7-dice2.flont-1] and num1[7-dice1.right-1] == num2[7-dice2.right-1]:
        flag2 = True
for j in range(4):
    for k in range(4):
        dice1.do_E()
        if num1[dice1.flont-1] == num2[dice2.flont-1] and num1[dice1.top-1] == num2[dice2.top-1]:
            flag1 = True
            if num1[dice1.right-1] == num2[dice2.right-1] and num1[7-dice1.top-1] == num2[7-dice2.top-1] and num1[7-dice1.flont-1] == num2[7-dice2.flont-1] and num1[7-dice1.right-1] == num2[7-dice2.right-1]:
                flag2 = True
    dice1.do_N()
    if num1[dice1.flont-1] == num2[dice2.flont-1] and num1[dice1.top-1] == num2[dice2.top-1]:
        flag1 = True
        if num1[dice1.right-1] == num2[dice2.right-1] and num1[7-dice1.top-1] == num2[7-dice2.top-1] and num1[7-dice1.flont-1] == num2[7-dice2.flont-1] and num1[7-dice1.right-1] == num2[7-dice2.right-1]:
            flag2 = True

dice1.do_S()
dice1.do_E()
if num1[dice1.flont-1] == num2[dice2.flont-1] and num1[dice1.top-1] == num2[dice2.top-1]:
    flag1 = True
    if num1[dice1.right-1] == num2[dice2.right-1] and num1[7-dice1.top-1] == num2[7-dice2.top-1] and num1[7-dice1.flont-1] == num2[7-dice2.flont-1] and num1[7-dice1.right-1] == num2[7-dice2.right-1]:
        flag2 = True
for j in range(4):
    for k in range(4):
        dice1.do_E()
        if num1[dice1.flont-1] == num2[dice2.flont-1] and num1[dice1.top-1] == num2[dice2.top-1]:
            flag1 = True
            if num1[dice1.right-1] == num2[dice2.right-1] and num1[7-dice1.top-1] == num2[7-dice2.top-1] and num1[7-dice1.flont-1] == num2[7-dice2.flont-1] and num1[7-dice1.right-1] == num2[7-dice2.right-1]:
                flag2 = True
    dice1.do_N()
    if num1[dice1.flont-1] == num2[dice2.flont-1] and num1[dice1.top-1] == num2[dice2.top-1]:
        flag1 = True
        if num1[dice1.right-1] == num2[dice2.right-1] and num1[7-dice1.top-1] == num2[7-dice2.top-1] and num1[7-dice1.flont-1] == num2[7-dice2.flont-1] and num1[7-dice1.right-1] == num2[7-dice2.right-1]:
            flag2 = True

if flag1 and flag2:
    print("Yes")
else:
    print("No")

Solution (Python):

dice1 = [int(d) for d in input().split()]
dice2 = [int(d) for d in input().split()]

R1 = [
    [0, 1, 2, 3, 4, 5], 
    [3, 1, 0, 5, 4, 2], 
    [2, 1, 5, 0, 4, 3], 
    [4, 0, 2, 3, 5, 1], 
    [1, 5, 2, 3, 0, 4], 
    [5, 4, 2, 3, 1, 0]  
]

R2 = [0, 3, 1, 4, 2, 5] 

ans = 'No'
for r1 in R1:
    dice3 = [dice2[i] for i in r1]
    for _ in range(4):
        dice3 = [dice3[i] for i in R2]
        if dice1 == dice3:
            ans = 'Yes'
            break
    else:
        continue
    break

print(ans)

Solution (Python):
def Roll(c, lst) :
    if c == 'N' :
        lst[0], lst[1], lst[5], lst[4] = lst[1], lst[5], lst[4], lst[0]
    elif c == 'S' :
        lst[0], lst[1], lst[5], lst[4] = lst[4], lst[0], lst[1], lst[5]
    elif c == 'E' :
        lst[0], lst[2], lst[5], lst[3] = lst[3], lst[0], lst[2], lst[5]
    elif c == 'W' :
        lst[0], lst[2], lst[5], lst[3] = lst[2], lst[5], lst[3], lst[0]
    return lst
    
import copy
dice_A = list(map(int, input().split()))
dice_B = list(map(int, input().split()))

for i in range(4) :
    if dice_B[1] == dice_A[1] :
        break
    else :
        Roll('S', dice_B)
if dice_B[1] != dice_A[1] :
    Roll('E', dice_B)
    for i in range(4) :
        if dice_B[1] == dice_A[1] :
            break
        else :
            Roll('S', dice_B)
for i in range(4) :
    if dice_B[0] == dice_A[0] :
        break
    else :
        Roll('E', dice_B)

if dice_B[2] == dice_A[2] and dice_B[3] == dice_A[3] and dice_B[4] == dice_A[4] and dice_B[5] == dice_A[5] :
    print("Yes")
else :
    print("No")

Solution (Python):
class Dice:
    def __init__(self, top: str, front: str, right: str, left: str, back: str, bottom: str) -> None:
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.back = back
        self.bottom = bottom

    def __eq__(self, other) -> bool:
        top, front = self.top, self.front

        
        found = False
        for direction in 'SSSS':
            other.roll(direction)
            if other.top == top:
                found = True
                break
        if not found:
            for direction in 'EEE':
                other.roll(direction)
                if other.top == top:
                    break

        
        for _ in range(4):
            other.rotate_right()
            if other.front == front:
                break

        return (
                self.right == other.right
                and self.left == other.left
                and self.back == other.back
                and self.bottom == other.bottom
        )

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

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

    def roll(self, direction: str) -> None:
        if direction == 'S':
            self.south()
        elif direction == 'N':
            self.north()
        elif direction == 'E':
            self.east()
        elif direction == 'W':
            self.west()

    def north(self):
        [self.top, self.back, self.bottom, self.front] = [self.front, self.top, self.back, self.bottom]

    def south(self):
        [self.top, self.back, self.bottom, self.front] = [self.back, self.bottom, self.front, self.top]

    def east(self):
        [self.top, self.right, self.bottom, self.left] = [self.left, self.top, self.right, self.bottom]

    def west(self):
        [self.top, self.right, self.bottom, self.left] = [self.right, self.bottom, self.left, self.top]

    def rotate_right(self) -> None:
        for direction in 'SWN':
            self.roll(direction)


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

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

Solution (Python):
class Dice():
    def __init__(self, a, b, c, d, e, f):
        """面の数字とindexを一致させるために0を挿入"""
        self.s = [0, a, b, c, d, e, f]

    def rotate(self, dir):
        if dir == "N":
            self.s[0] = self.s[1] 
            self.s[1] = self.s[2] 
            self.s[2] = self.s[6]
            self.s[6] = self.s[5]
            self.s[5] = self.s[0]
            return

        elif dir == "W":
            self.s[0] = self.s[1]
            self.s[1] = self.s[3] 
            self.s[3] = self.s[6]
            self.s[6] = self.s[4]
            self.s[4] = self.s[0]
            return

        elif dir == "S":
            self.s[0] = self.s[1]
            self.s[1] = self.s[5] 
            self.s[5] = self.s[6]
            self.s[6] = self.s[2]
            self.s[2] = self.s[0]
            return

        elif dir == "E":
            self.s[0] = self.s[1]
            self.s[1] = self.s[4] 
            self.s[4] = self.s[6]
            self.s[6] = self.s[3]
            self.s[3] = self.s[0]
            return
        
        elif dir == "R":
            self.s[0] = self.s[2]
            self.s[2] = self.s[3] 
            self.s[3] = self.s[5]
            self.s[5] = self.s[4]
            self.s[4] = self.s[0]
            return

        else:
            return


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

if set(dice1.s[1:]) != set(dice2.s[1:]):
    """片方にない数字がもう片方に含まれる場合"""
    pass 

elif dice1.s[1:] != dice2.s[1:]:
    for i in range(3):
        if dice1.s[1:] != dice2.s[1:]:
            for j in range(4):
                if dice1.s[1:] != dice2.s[1:]:
                    dice2.rotate("R")
                else:
                    FLG = True
                    break
            if FLG:
                break

            dice2.rotate("S")
            for j in range(4):
                if dice1.s[1:] != dice2.s[1:]:
                    dice2.rotate("R")
                else:
                    FLG = True
                    break
            if FLG:
                break
            dice2.rotate("E")
        else:
            FLG = True 
        if FLG:
            break
else:
    FLG = True

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

Solution (Python):
import copy


class Dice:
    def __init__(self, one: int, two: int, three: int, four: int, five: int, six: int) -> None:
        self.__one = one
        self.__two = two
        self.__three = three
        self.__four = four
        self.__five = five
        self.__six = six

    def roll(self, direction) -> None:
        if direction == "N":
            tmp = self.__one
            self.__one = self.__two
            self.__two = self.__six
            self.__six = self.__five
            self.__five = tmp

        if direction == "E":
            tmp = self.__one
            self.__one = self.__four
            self.__four = self.__six
            self.__six = self.__three
            self.__three = tmp

        if direction == "S":
            tmp = self.__one
            self.__one = self.__five
            self.__five = self.__six
            self.__six = self.__two
            self.__two = tmp

        if direction == "W":
            tmp = self.__one
            self.__one = self.__three
            self.__three = self.__six
            self.__six = self.__four
            self.__four = tmp

        if direction == "I":
            tmp = self.__one
            self.__one, self.__six = self.__six, self.__one
            self.__two, self.__five = self.__five, self.__two

    def set_top(self, top: int) -> bool:
        if self.__one != top:
            for i in range(3):
                self.roll("N")
                if (self.__one == top):
                    break
        if self.__one != top:
            for i in range(3):
                self.roll("E")
                if (self.__one == top):
                    break
        return self.__one == top

    def rotate(self) -> None:
        tmp = self.__two
        self.__two = self.__four
        self.__four = self.__five
        self.__five = self.__three
        self.__three = tmp

    def check(self, dice) -> bool:
        flag = True
        if self.__one != dice.__one:
            flag = False
        if self.__two != dice.__two:
            flag = False
        if self.__three != dice.__three:
            flag = False
        if self.__four != dice.__four:
            flag = False
        if self.__five != dice.__five:
            flag = False
        if self.__six != dice.__six:
            flag = False
        return flag

    @property
    def top(self) -> int:
        return self.__one

    @property
    def front(self) -> int:
        return self.__two

    @property
    def right(self) -> int:
        return self.__three

    @property
    def left(self) -> int:
        return self.__four

    @property
    def back(self) -> int:
        return self.__five

    @property
    def bottom(self) -> int:
        return self.__six


if __name__ == "__main__":
    dice1_one, dice1_two, dice1_three, dice1_four, dice1_five, dice1_six = map(
        int, input().split(' '))
    dice2_one, dice2_two, dice2_three, dice2_four, dice2_five, dice2_six = map(
        int, input().split(' '))

    dice1 = Dice(dice1_one, dice1_two, dice1_three,
                 dice1_four, dice1_five, dice1_six)
    dice2 = Dice(dice2_one, dice2_two, dice2_three,
                 dice2_four, dice2_five, dice2_six)

    directions = ["N", "E", "S", "W", "I"]
    for direction in directions:
        dice = copy.deepcopy(dice1)
        if not (dice1.top == dice2.top and dice1.bottom == dice2.bottom):
            dice.roll(direction)
        if dice.top == dice2.top and dice.bottom == dice2.bottom:
            if dice.front != dice2.front:
                for i in range(3):
                    dice.rotate()
                    if dice.check(dice2):
                        print("Yes")
                        exit()
            else:
                if dice.check(dice2):
                    print("Yes")
                    exit()
    print("No")

Solution (Python):

"""
Spyderエディタ

これは一時的なスクリプトファイルです
"""

class Dice():
    
    
    
    

    
    
    
    
    
    def __init__(self, nums):
        self.pos = nums
    
    def rot_E(self):
        e = self.pos
        self.pos = [e[3], e[1], e[0], e[5], e[4], e[2]]

    def rot_W(self):
        e = self.pos
        self.pos = [e[2], e[1], e[5], e[0], e[4], e[3]]

    def rot_S(self):
        e = self.pos
        self.pos = [e[4], e[0], e[2], e[3], e[5], e[1]]

    def rot_N(self):
        e = self.pos
        self.pos = [e[1], e[5], e[2], e[3], e[0], e[4]]
        
    def rot_CW(self):
        e = self.pos
        self.pos = [e[0], e[2], e[4], e[1], e[3], e[5]]

    def rot_CCW(self):
        e = self.pos
        self.pos = [e[0], e[3], e[1], e[4], e[2], e[5]]

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

    def face(self):
        return self.pos[1]

    def right(self, tf=None):
        

        if tf == None:
            print(self.pos[2])
            return

        t = self.pos.index(tf[0])  
        f = self.pos.index(tf[1])  
        
        
        dr = [(1,2,4,3),(0,3,5,2),(0,1,5,4),(0,4,5,1),(0,2,5,3),(1,3,4,2)]
        r = (dr[t].index(f) + 1) % 4
        print(self.pos[dr[t][r]])
        return

    def left(self):
        print(self.pos[3])
        return

    def back(self):
        print(self.pos[4])
        return

    def bottom(self):
        print(self.pos[5])
        return

    def fit_top(x):
        if x == 0:
            d2.rot_S()
            d2.rot_S()
        if x == 1:
            d2.rot_N()
        if x == 3:
            d2.rot_axis()
            d2.rot_axis()
        if x == 4:
            d2.rot_S()
        if x == 5:
            d2.rot_axis()
            d2.rot_axis()
            d2.rot_axis()

    
    def position(self, x):
        return self.pos.index(x)
    


d1 = Dice([int(x) for x in input().split()])
d2 = Dice([int(x) for x in input().split()])

check_f = False


for _ in range(4):
    d2.rot_CW()
    if d1.pos == d2.pos:
        check_f = True

d2.rot_N()
for _ in range(4):
    d2.rot_CW()
    if d1.pos == d2.pos:
        check_f = True
d2.rot_S()

d2.rot_W()
for _ in range(4):
    d2.rot_CW()
    if d1.pos == d2.pos:
        check_f = True
d2.rot_E()

d2.rot_S()
for _ in range(4):
    d2.rot_CW()
    if d1.pos == d2.pos:
        check_f = True
d2.rot_N()

d2.rot_E()
for _ in range(4):
    d2.rot_CW()
    if d1.pos == d2.pos:
        check_f = True
d2.rot_W()

d2.rot_E()
d2.rot_E()
for _ in range(4):
    d2.rot_CW()
    if d1.pos == d2.pos:
        check_f = True
d2.rot_W()
d2.rot_W()

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

Solution (Python):
class Dice:
    def __init__(self, lst):
        self.a = lst[0]
        self.b = lst[1]
        self.c = lst[2]
        self.d = lst[3]
        self.e = lst[4]
        self.f = lst[5]
        
    def roll(self, orders):
        for order in orders:
            if order=='W':
                tmp = self.a
                self.a = self.c
                self.c = self.f
                self.f = self.d
                self.d = tmp
            elif order=='E':
                tmp = self.a
                self.a = self.d
                self.d = self.f
                self.f = self.c
                self.c = tmp
            elif order=='S':
                tmp = self.a
                self.a = self.e
                self.e = self.f
                self.f = self.b
                self.b = tmp
            elif order=='N':
                tmp = self.a
                self.a = self.b
                self.b = self.f
                self.f = self.e
                self.e = tmp


    
    def equal(self, dice_):
        if (self.a==dice_.a and
            self.b==dice_.b and
            self.c==dice_.c and
            self.d==dice_.d and
            self.e==dice_.e and
            self.f==dice_.f
           ):
            return True
        else:
            return False
       
            
import random
if __name__ == '__main__':
    lsts = [[int(x) for x in input().split()] for _ in range(2)]
    dice1 = Dice(lsts[0])
    dice2 = Dice(lsts[1])
    
    ans = 'No'
    for direction in 'EEENEEENEEESEEESEEENEEEN':
        if dice1.equal(dice2):
            ans = 'Yes'
            break
        else:
            dice1.roll(direction)
    print(ans)

Solution (Python):
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.face = {'head':1, 'tail':4, 'left':3, 'right':2, 'above':0, 'below':5}
    
    def roll(self, ch):
        dice = self.dice
        face = self.face
        if ch == 'S':
            tmp = dice[face['head']]
            dice[face['head']] = dice[face['above']]
            dice[face['above']] = dice[face['tail']]
            dice[face['tail']] = dice[face['below']]
            dice[face['below']] = tmp
        elif ch == 'N':
            tmp = dice[face['head']]
            dice[face['head']] = dice[face['below']]
            dice[face['below']] = dice[face['tail']]
            dice[face['tail']] = dice[face['above']]
            dice[face['above']] = tmp
        elif ch == 'W':
            tmp = dice[face['left']]
            dice[face['left']] = dice[face['above']]
            dice[face['above']] = dice[face['right']]
            dice[face['right']] = dice[face['below']]
            dice[face['below']] = tmp
        else:
            tmp = dice[face['left']]
            dice[face['left']] = dice[face['below']]
            dice[face['below']] = dice[face['right']]
            dice[face['right']] = dice[face['above']]
            dice[face['above']] = tmp

    def top(self):
        dice = self.dice
        face = self.face
        return dice[face['above']]
    
    def find_right(self, a, b):
        dice = self.dice
        face = self.face
        order = 'NNNNWNNNWNNNENNNENNNWNNN'
        for ch in order:
            self.roll(ch)
            if dice[face['above']] == a and dice[face['head']] == b:
                break
        return dice[face['right']]

    def equal(self, dice2):
        dice = self.dice
        dice2 = dice2.dice
        tag = False
        order = 'NNNNWNNNWNNNENNNENNNWNNN'
        for ch in order:
            self.roll(ch)
            flag = True
            for i in range(6):
                if dice[i] != dice2[i]:
                    flag = False
                    break
            if flag:
                tag = flag
                break
        return tag

dice = Dice([*map(int, input().split())])
dice2 = Dice([*map(int, input().split())])
print(['No','Yes'][dice.equal(dice2)])

Solution (Python):
class dice():
    def __init__(self,labels):
        self.l=labels
    def check(self,d2):
        l1=self.l
        for a in range(4):
            l1[1],l1[2],l1[3],l1[4]=l1[2],l1[4],l1[1],l1[3]
            for b in range(4):
                l1[0],l1[3],l1[2],l1[5]=l1[2],l1[0],l1[5],l1[3]
                for c in range(4):
                    l1[0],l1[1],l1[5],l1[4]=l1[4],l1[0],l1[1],l1[5]
                    if l1==d2.l:
                        return True
                        break
a=dice([int(i) for i in input().split()])
b=dice([int(i) for i in input().split()])
print("Yes" if a.check(b) else "No")

Solution (Python):
roll_dict = dict(E = (3, 1, 0, 5, 4, 2), W = (2, 1, 5, 0, 4, 3), S = (4, 0, 2, 3, 5, 1), N = (1, 5, 2, 3, 0, 4))

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

dices = []
dices.append(dice1)
judge = False

for i in "EWSN":
  dice = dices[0]
  new_dice = []
  for j in range(6):
    new_dice.append(dice[ roll_dict[i][j] ])
  dices.append(new_dice)

dice = dices[1]
new_dice = []
for i in range(6):
  new_dice.append(dice[ roll_dict["E"][i] ])
dices.append(new_dice)

for i in range(6):
  if dices[i][0] == dice2[0] and dices[i][5] == dice2[5]:
    str_dice1 = "".join(map(str, dices[i]))
    str_dice2 = "".join(map(str, dice2))

    side1 = str_dice1[1:3]+str_dice1[4]+str_dice1[3]
    side1 += side1
    side2 = str_dice2[1:3]+str_dice2[4]+str_dice2[3]

    judge = side2 in side1

if judge == True:
  print("Yes")
elif judge == False:
  print("No")

Solution (Python):


t, s, e, w, n, b = map(int, input().split())
t_2, s_2, e_2, w_2, n_2, b_2 = map(int, input().split())


dice_dic = {}
dice_dic[t] = {s:e, e:n, n:w, w:s}
dice_dic[b] = {n:e, w:n, s:w, e:s}
dice_dic[s] = {e:t, t:w, w:b, b:e}
dice_dic[n] = {t:e, e:b, b:w, w:t}
dice_dic[e] = {s:b, b:n, n:t, t:s}
dice_dic[w] = {s:t, t:n, n:b, b:s}

dice_dic_2 = {}
dice_dic_2[t_2] = {s_2:e_2, e_2:n_2, n_2:w_2, w_2:s_2}
dice_dic_2[b_2] = {n_2:e_2, w_2:n_2, s_2:w_2, e_2:s_2}
dice_dic_2[s_2] = {e_2:t_2, t_2:w_2, w_2:b_2, b_2:e_2}
dice_dic_2[n_2] = {t_2:e_2, e_2:b_2, b_2:w_2, w_2:t_2}
dice_dic_2[e_2] = {s_2:b_2, b_2:n_2, n_2:t_2, t_2:s_2}
dice_dic_2[w_2] = {s_2:t_2, t_2:n_2, n_2:b_2, b_2:s_2}

is_ok = True

for k in dice_dic:
    for k_2 in dice_dic[k]:
        if k_2 in dice_dic_2[k]:
            if not dice_dic[k][k_2]==dice_dic_2[k][k_2]:
                is_ok = False
                break
        else:
            is_ok = False
            break


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

Solution (Python):
dice1 = input().rstrip().split(' ')
dice2 = input().rstrip().split(' ')
indication = "EEENEEENEEESEEESEEENEEENSWWSWWWNWWWNWWWSWWWSWWW"
indic = list(indication)
length = len(indic)
count =0
for i in range(length):
  newdice = [0] * 6
  if str(indic[i]) == "N":
    newdice[0] = dice2[1]
    newdice[1] = dice2[5]
    newdice[2] = dice2[2]
    newdice[3] = dice2[3]
    newdice[4] = dice2[0]
    newdice[5] = dice2[4]
    dice2 = newdice
    if dice2 == dice1:
      count += 1
  elif str(indic[i]) == "S":
    newdice[0] = dice2[4]
    newdice[1] = dice2[0]
    newdice[2] = dice2[2]
    newdice[3] = dice2[3]
    newdice[4] = dice2[5]
    newdice[5] = dice2[1]
    dice2 = newdice
    if dice2 == dice1:
      count += 1
  elif str(indic[i]) == "E":
    newdice[0] = dice2[3]
    newdice[1] = dice2[1]
    newdice[2] = dice2[0]
    newdice[3] = dice2[5]
    newdice[4] = dice2[4]
    newdice[5] = dice2[2]
    dice2 = newdice
    if dice2 == dice1:
      count += 1
  elif str(indic[i]) == "W":
    newdice[0] = dice2[2]
    newdice[1] = dice2[1]
    newdice[2] = dice2[5]
    newdice[3] = dice2[0]
    newdice[4] = dice2[4]
    newdice[5] = dice2[3]
    dice2 = newdice
    if dice2 == dice1:
      count += 1

if count == 0:
  print("No")
else:
  print("Yes")

Solution (Python):
from copy import deepcopy

class Dice():

    def __init__(self):
        self.E = [4,2,1,6,5,3]
        self.N = [2,6,3,4,1,5]
        self.S = [5,1,3,4,6,2]
        self.W = [3,2,6,1,5,4]
        self.number = list(map(int,input().split()))
        

    def rotate(self,order):
        tmp = deepcopy(self.number)
        if order == "E":
            for i in range(6):
                self.number[i] = tmp[self.E[i]-1]
        elif order == "N":
            for i in range(6):
                self.number[i] = tmp[self.N[i]-1]
        elif order == "S":
            for i in range(6):
                self.number[i] = tmp[self.S[i]-1]
        elif order == "W":
            for i in range(6):
                self.number[i] = tmp[self.W[i]-1]
    
    def sidenum(self,x,y):
        for i in self.order:
            if self.number[1] == y and self.number[0] == x:
                print(self.number[2])
                break
            else:
                self.rotate(i)
    
    def check(self,other):
        flag = True
        for i in range(6):
            if self.number[i] != other.number[i]:
                flag = False
        return flag

if __name__ == "__main__":
    flag = False
    dice1 = Dice()
    dice2 = Dice()
    order = "NNNNWNNNWNNNENNNENNNWNNN"
    for i in order:
        dice1.rotate(i)
        if dice1.check(dice2):
            flag = True
            break
    if flag:
        print("Yes")
    else:
        print("No")