Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
1 2 3 4 5 6
6 2 4 3 5 1


Sample output:
Yes

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

class Dice:

    def __init__(self,dicelist):
        self.dice_list = dicelist
        self.all_pattern = 'NNNNWNNNWNNNENNNENNNWNNN'

    def roll(self, direction):
        work = list(self.dice_list)
        if (direction == 'N'):
            self.dice_list[0] = work[1]
            self.dice_list[1] = work[5]
            self.dice_list[2] = work[2]
            self.dice_list[3] = work[3]
            self.dice_list[4] = work[0]
            self.dice_list[5] = work[4]
        elif (direction == 'E'):
            self.dice_list[0] = work[3]
            self.dice_list[1] = work[1]
            self.dice_list[2] = work[0]
            self.dice_list[3] = work[5]
            self.dice_list[4] = work[4]
            self.dice_list[5] = work[2]
        elif (direction == 'S'):
            self.dice_list[0] = work[4]
            self.dice_list[1] = work[0]
            self.dice_list[2] = work[2]
            self.dice_list[3] = work[3]
            self.dice_list[4] = work[5]
            self.dice_list[5] = work[1]
        elif (direction == 'W'):
            self.dice_list[0] = work[2]
            self.dice_list[1] = work[1]
            self.dice_list[2] = work[5]
            self.dice_list[3] = work[0]
            self.dice_list[4] = work[4]
            self.dice_list[5] = work[3]

    def equals(self, another):
        for p in self.all_pattern:
            another.roll(p)
            if self.dice_list == another.dice_list:
                return True
        else:
            return False


dice_list1 = list(map(int, stdin.readline().rstrip().split()))
dice_list2 = list(map(int, stdin.readline().rstrip().split()))

dice1 = Dice(dice_list1)
dice2 = Dice(dice_list2)

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

Submission status: Accepted

Solution code:
import copy
from enum import IntEnum

class Face(IntEnum):
    One=1
    Two=2
    Three=3
    Four=4
    Five=5
    Six=6


class Dice:
    def __init__(self):
        self.top=Face.One
        self.bottom=Face.Six
        self.back=Face.Two
        self.front=Face.Five
        self.left=Face.Four
        self.right=Face.Three
        
    def set_face(self,face_ls):
        self.top=Face(face_ls[0])
        self.back=Face(face_ls[1])
        self.right=Face(face_ls[2])
        self.left=Face(face_ls[3])
        self.front=Face(face_ls[4])
        self.bottom=Face(face_ls[5])
        
    def __str__(self):
        return f"top: {self.top}, back: {self.back}, right: {self.right}, bottom: {self.bottom}, front: {self.front}, left: {self.left}"
        
    def __eq__(self,other):
        equal=self.top == other.top and self.bottom == other.bottom and self.back == other.back and self.front == other.front and self.left == other.left and self.right == other.right
            
        return equal
        
    def get_one_face(self):
        return self.get_n_face(Face.One)
        
    def get_n_face(self,n):
        #指定した面を取得する
        if self.top ==n:
            return self.top
        elif self.bottom==n:
            return self.bottom
        elif self.back==n:
            return self.back
        elif self.front==n:
            return self.front
        elif self.left==n:
            return self.left
        elif self.right==n:
            return self.right
        else:
            assert False
            
    
    def roll(self,command):
        if command=="E":
            #back-frontを軸として右回転
            temp=self.top
            self.top=self.left
            self.left=self.bottom
            self.bottom=self.right
            self.right=temp
            
        elif command=="N":
            #right-leftを固定して前転
            temp=self.top
            self.top=self.back
            self.back=self.bottom
            self.bottom=self.front
            self.front=temp
            
        elif command=="S":
            #right-leftを固定して後転
            temp=self.top
            self.top=self.front
            self.front=self.bottom
            self.bottom=self.back
            self.back=temp
            
        elif command=="W":
            #back-frontを軸として左回転
            temp=self.top
            self.top=self.right
            self.right=self.bottom
            self.bottom=self.left
            self.left=temp
    
    def roll_clockwise_fix_top(self):
        #top,bottomを固定して時計周りに回転させる
        temp=self.front
        self.front=self.left
        self.left=self.back
        self.back=self.right
        self.right=temp
      
def num_pattern_match(num_list,pattern):
    for i,x in enumerate(num_list):
        is_match=True
        for j,y in enumerate(pattern):
            if num_list[(i+j) % len(num_list)] == pattern[j]:
                pass
            else:
                is_match=False
        if is_match:
            return True
            
    return False      

def build_dice(top,back):
    #2つの面からさいころの状態を初期化する
    dice=Dice()
    dice.top=top
    dice.back=back
    
    dice.bottom=Face(7-int(dice.top))
    dice.front=Face(7-int(dice.back))

    #left-rightはどう計算する?
    #難しく考えないで確実にできる簡単な方法を実行する
    exist_dice_list=[int(dice.top),
    int(dice.bottom),
    int(dice.front),
    int(dice.back)]
    
    left_face_num=set([i+1 for i in range(6)]) - set(exist_dice_list)
    
    #top->front->bottom->backの面のリストを作成する
    #泥臭いプログラミングできるかどうかにかかっている
    face_list=[int(dice.top),int(dice.front),int(dice.bottom),int(dice.back)]

    #泥臭くても手を動かせば完了するときはさっさと手を動かして完了させる
    if 1 in left_face_num:
        #1,5が残されているパターン
        pattern=[2,3,5,4]
        if num_pattern_match(face_list,pattern):
            #top->front->bottom->backに走査したとき、2354に一致するとき
            #左に1が来る
            dice.right=Face.Six
            dice.left=Face.One
        else:
            dice.right=Face.One
            dice.left=Face.Six
            
    elif 2 in left_face_num:
        pattern=[1,4,6,3]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Five
            dice.left=Face.Two
        else:
            dice.right=Face.Two
            dice.left=Face.Five
            
    elif 3 in left_face_num:
        pattern=[2,6,5,1]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Four
            dice.left=Face.Three
        else:
            dice.right=Face.Three
            dice.left=Face.Four           
        
    return dice


def move_one_face_to_top(dice):
    #1をトップに持ってくる
    if dice.get_one_face() ==dice.top:
        return
    elif dice.get_one_face()==dice.left:
        #E側に転がす
        dice.roll("E")
        return
    elif dice.get_one_face()==dice.back:
        dice.roll("N")
    elif dice.get_one_face()==dice.right:
        dice.roll("W")
    elif dice.get_one_face()==dice.front:
        dice.roll("S")
    elif dice.get_one_face()==dice.bottom:
        dice.roll("N")
        dice.roll("N")
        

def create_all_equal_dice(dice):
    #等価なダイスをすべて作成する
    same_dice_ls=[]
    for face in list(Face):
        #特定の面を上に回す
        created_dice=copy.deepcopy(dice)
        move_n_face_to_top(created_dice,face)
        same_dice_ls.append(copy.deepcopy(created_dice))
        
        #1,2,3回topを軸にして回転させたものを作成する
        for i in range(3):
            created_dice.roll_clockwise_fix_top()
            same_dice_ls.append(copy.deepcopy(created_dice))
            
    return same_dice_ls
        
def move_n_face_to_top(dice,face):
    #指定した番号をトップに持ってくる
    spec_face=dice.get_n_face(face)
    if spec_face==dice.top:
        return
    elif spec_face==dice.left:
        dice.roll("E")
        return
    elif spec_face==dice.back:
        dice.roll("N")
        return
    elif spec_face==dice.right:
        dice.roll("W")
        return
    elif spec_face==dice.front:
        dice.roll("S")
        return
    elif spec_face==dice.bottom:
        dice.roll("N")
        dice.roll("N")
        return

def move_two_face_to_back(dice):
    #1がtopのときに、2をbackにそろえる
    assert dice.top == Face.One
    assert dice.bottom != Face.Two
    
    if dice.get_n_face(Face.Two)==dice.left:
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
    elif dice.get_n_face(Face.Two)==dice.front:
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
    elif dice.get_n_face(Face.Two)==dice.right:
        dice.roll_clockwise_fix_top()


def check_if_equal_dice(dice_x,dice_y):
    #2つの面をそろえて、残りの面を比較すると同じダイスか判定可能
    #1をtopに持ってくるアルゴリズム
    #2をbackに持ってくるアルゴリズム
    #比較する
    
    
    move_one_face_to_top(dice_x)
    move_one_face_to_top(dice_y)
    
    move_two_face_to_back(dice_x)
    move_two_face_to_back(dice_y)
    
    return dice_x==dice_y

def _run():
    dice_score_ls=list(map(int,input().split()))
    
    dice_score_dict={i+1:score for i,score in enumerate(dice_score_ls)}
    d_inv={v:k for k,v in dice_score_dict.items()}
    
    query_num=int(input())

    for i in range(query_num):
        top,back=tuple(map(int,input().split()))
        top=d_inv[top]
        back=d_inv[back]
        
        dice=build_dice(top,back)
        
        # print(int(dice.right))
        print(dice_score_dict[int(dice.right)])
        
    

def compare_dice_with_dict(dice_x,d_x,dice_y_face_list):
    
    is_top_same=d_x[dice_x.top]==dice_y_face_list[0]
    is_bottom_same=d_x[dice_x.bottom]==dice_y_face_list[5]
    is_right_same=d_x[dice_x.right]==dice_y_face_list[2]
    is_left_same=d_x[dice_x.left]==dice_y_face_list[3]
    is_front_same=d_x[dice_x.front]==dice_y_face_list[4]
    is_back_same=d_x[dice_x.back]==dice_y_face_list[1]
    
    return is_top_same and is_bottom_same and is_right_same and is_left_same and is_front_same and is_back_same
    

def run():
    dice_x_face_list=list(map(int,input().split()))
    
    dice_y_face_list=list(map(int,input().split()))
    
    #整数の1-6に変換
    face_dict={Face(i+1):x for i,x in enumerate(dice_x_face_list)}
    
    

    # dice_x=build_dice(Face(dice_x_face_list[0]),Face(dice_x_face_list[1]))
    # dice_y=build_dice(Face(dice_y_face_list[0]),Face(dice_y_face_list[1]))
    dice_x=Dice()
    # dice_x.set_face(dice_x_face_list)
    
    #通常のダイスを作成してから、辞書で面を置き換える

    ls=create_all_equal_dice(dice_x)


    is_same_dice=False
    for d in ls:
        if compare_dice_with_dict(d,face_dict,dice_y_face_list):
            is_same_dice=True


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

    # result=check_if_equal_dice(dice_x,dice_y)
    
    # if result:
    #     print("Yes")
    # else:
    #     print("No")
    

run()

Submission status: Accepted

Solution code:
import copy
import random

D1 = list(map(int, input().split()))
D2 = list(map(int, input().split()))

for x in range(1000):
    r = random.randint(0,3)
    if r == 0:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[4]
        Dt[4] = Dt[5]
        Dt[5] = Dt[1]
        Dt[1] = temp
    elif r== 1:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[2]
        Dt[2] = Dt[5]
        Dt[5] = Dt[3]
        Dt[3] = temp
    elif r== 2:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[3]
        Dt[3] = Dt[5]
        Dt[5] = Dt[2]
        Dt[2] = temp
    elif r == 3:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[1]
        Dt[1] = Dt[5]
        Dt[5] = Dt[4]
        Dt[4] = temp

    D2 = copy.copy(Dt)
        
    flag = 0
    for y in range(6):
        if D1[y] == D2[y]:
            flag += 1
    if flag == 6:
        break

if flag == 6:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, numbers):
        self.dice = {"上" :numbers[0],
                     "下":numbers[5], 
                     "前":numbers[1],
                     "後":numbers[4],
                     "左":numbers[3],
                     "右":numbers[2]
                    }
    
    def order(self, order_seq):
        for _, order in enumerate(order_seq):
            if order == "N":
                self.north()
            elif order == "E":
                self.east()
            elif order == "W":
                self.west()
            elif order == "S":
                self.south()
        
        return self.dice["上"]

    def north(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = F
        self.dice["前"] = D
        self.dice["下"] = B
        self.dice["後"] = U

    def east(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = L
        self.dice["下"] = R
        self.dice["左"] = D
        self.dice["右"] = U

    def west(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = R
        self.dice["下"] = L
        self.dice["左"] = U
        self.dice["右"] = D

    def south(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = B
        self.dice["前"] = U
        self.dice["下"] = F
        self.dice["後"] = D   

    def set_position(self, n, position_seq):
        self.ans = []
        for i in range(n):
            self.up = position_seq[i][0]
            self.front = position_seq[i][1]

            self.search()
            self.west()
            self.search()
            self.west()
            self.search()
            self.north()
            self.search()
            self.west()
            self.search()
            self.west()
            self.search()
        
        return self.ans
    
    def search(self):
        # print("goal:上", self.up, ":", self.dice["上"])
        if self.dice["上"] == self.up:
            for _ in range(4):
                # print("goal:前|上 ", self.front, ":", self.dice["前"],
                #      "|", self.dice["上"], "→", self.dice["右"])
                if self.dice["前"] == self.front:
                    self.ans = [self.dice["右"], self.dice["後"], self.dice["左"], self.dice["下"]]
                    break
                self.rotate()
            # self.ans.append(self.dice["右"])

    def rotate(self):
        F, R, B, L = [self.dice["前"], self.dice["右"], self.dice["後"], self.dice["左"]]
        self.dice["前"] = R
        self.dice["右"] = B
        self.dice["後"] = L
        self.dice["左"] = F
        
numbers = list(map(int, input().split()))
dice1 = Dice(numbers)
numbers = list(map(int, input().split()))
dice2 = Dice(numbers)

position_seq = [[dice2.dice["上"], dice2.dice["前"]]]
answer = [dice2.dice["右"], dice2.dice["後"], dice2.dice["左"], dice2.dice["下"]]

ans = dice1.set_position(1, position_seq)

for i in range(4):
    if ans == None or ans[i] != answer[i]:
        print('No')
        break
if i == 3:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, num):
        self.state = {}
        for i in range(1,6+1):
            self.state[i] = num[i-1]

        self.reversed_state = {}
        for key,val in zip(self.state.keys(), self.state.values()):
            self.reversed_state[val] = key
        
    def search_side(self, x,y):
        a = self.reversed_state[x]
        b = self.reversed_state[y]
        if str(a)+str(b) in '12651':
            side = self.state[3]
        elif str(b)+str(a) in '12651':
            side = self.state[4]
        elif str(a)+str(b) in '13641':
            side = self.state[5]
        elif str(b)+str(a) in '13641':
            side = self.state[2]
        elif str(a)+str(b) in '23542':
            side = self.state[1]
        elif str(b)+str(a) in '23542':
            side = self.state[6]
        else:
            side = None
        return side
        
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))

dice1 = Dice(num1)
dice2 = Dice(num2)


pairs = [(1,2), (2,6),(6,5),(5,1), (1,3),(3,6),(6,4),(4,1), (2,3),(3,5),(5,4),(4,2)]
pairs = [(dice1.state[a], dice1.state[b]) for (a,b) in pairs]

ans = 'Yes'
for x,y in pairs:
    side1 = dice1.search_side(x,y)
    side2 = dice2.search_side(x,y)
    if side1!=side2:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

class Dice:
    def __init__(self,a):
        self.dice = [0 for i in range(len(a))]
        for i in range(len(a)):
            self.dice[i] = a[i]

    def N(self):
        self.dice[0],self.dice[1],self.dice[4],self.dice[5] = self.dice[1],self.dice[5],self.dice[0],self.dice[4]

    def S(self):
        self.dice[0],self.dice[1],self.dice[4],self.dice[5] = self.dice[4],self.dice[0],self.dice[5],self.dice[1]

    def E(self):
        self.dice[0],self.dice[2],self.dice[3],self.dice[5] = self.dice[3],self.dice[0],self.dice[5],self.dice[2]

    def W(self):
        self.dice[0],self.dice[2],self.dice[3],self.dice[5] = self.dice[2],self.dice[5],self.dice[0],self.dice[3]

    def R(self):
        self.dice[1],self.dice[2],self.dice[3],self.dice[4] = self.dice[3],self.dice[1],self.dice[4],self.dice[2]

    def L(self):
        self.dice[1],self.dice[2],self.dice[3],self.dice[4] = self.dice[2],self.dice[4],self.dice[1],self.dice[3]

    #確認用
    def output(self):
        print(self.dice)


dice1 = Dice(a)
dice2 = Dice(b)
dir = 'RRRRNRRRRSWRRRREERRRRWSRRRRNNNRRRR'
for c in dir:
    if c == "R":
        dice1.R()
    elif c == "N":
        dice1.N()
    elif c == "S":
        dice1.S()
    elif c == "W":
        dice1.W()
    elif c == "E":
        dice1.E()
    elif c == "L":
        dice1.L()
    if dice1.dice == dice2.dice:
        break

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

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def rotate_right(self):
        tmp = self.ns
        tmp.reverse()
        self.ns = self.we
        self.we = tmp

    def fit_top_s(self, top, s):
        while self.get_top() != top:
            if top in self.ns:
                self.n()
            elif top in self.we:
                self.w()
            else:
                self.n()
                self.n()
        while self.get_s() != s:
            self.rotate_right()

    def get_top(self):
        return self.ns[1]

    def get_s(self):
        return self.ns[2]

    def get_e(self):
        return self.we[2]


def resolve():
    nums = [int(i) for i in input().split()]
    dc1 = Dice(nums)
    nums = [int(i) for i in input().split()]
    dc2 = Dice(nums)
    dc2.fit_top_s(dc1.get_top(), dc1.get_s())
    if dc1.get_e() == dc2.get_e():
        print("Yes")
    else:
        print("No")


resolve()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, front, right, left, rear, bottom):
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.rear = rear
        self.bottom = bottom
    def print(self):
        '''print top of dice'''
        print(self.top)
    def north(self):
        self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
    def south(self):
        self.top, self.front, self.bottom, self.rear = \
            self.rear, self.top, self.front, self.bottom
    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 clockwise(self):
        self.front, self.right, self.rear, self.left = \
            self.right, self.rear, self.left, self.front
    def ccw(self):
        self.front, self.right, self.rear, self.left = \
            self.left, self.front, self.right, self.rear
    def __eq__(self, other):
        # top, front, bottom, rear, left, right をこの順で上面にする回転パターン
        pattern = ['', 'N', 'N', 'N', 'E', 'EE']
        tmp = Dice(other.top, other.front, other.right, other.left, other.rear, other.bottom)
        for i in pattern:
            if i == 'N':
                tmp.north()
            elif i == 'E':
                tmp.east()
            elif i == 'EE':
                tmp.east()
                tmp.east()
            else:
                pass
            if self.top != tmp.top or self.bottom != tmp.bottom:
                continue
            for j in range(4):
                if self.front == tmp.front and self.right == tmp.right and \
                   self.rear == tmp.rear and self.left == tmp.left:
                    return True
                tmp.clockwise()
        return False

d = list(map(int, input().split()))
dice1 = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
d = list(map(int, input().split()))
dice2 = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
print('Yes' if dice1 == dice2 else 'No')

Submission status: Accepted

Solution code:
class Dice():
    directions = "EEENEEENEEESEEESEEENEEEN"

    def __init__(self, lst):
        self.top = lst[0]
        self.front = lst[1]
        self.right = lst[2]
        self.left = lst[3]
        self.back = lst[4]
        self.bottom = lst[5]

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

    def fit_top_front(self, num_top, num_front):
        for direction in Dice.directions:
            if self.top == num_top and self.front == num_front:
                break
            self.rotate(direction)

    def fit_all(self, dice):
        for direction in Dice.directions:
            if self.top == dice.top and self.front == dice.front and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.bottom == dice.bottom:
                return True
            self.rotate(direction)
        return False


def main():
    diceA_nums = list(map(int, input().split()))
    diceA = Dice(diceA_nums)

    diceB_nums = list(map(int, input().split()))
    diceB = Dice(diceB_nums)

    result = diceB.fit_all(diceA)
    if result == True:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
class _Dice:
    
    def __init__(self, nums):
        self.nums = list(nums)
        
    @property
    def top(self):
        return self.nums[0]
        
    def _shift(self, *pairs):
        for pair in pairs:
            num = self.nums[pair[0]]
            self.nums[pair[0]] = self.nums[pair[1]]
            self.nums[pair[1]] = num
            
    def get_matches(self, num):
        return [i for i, m in enumerate(self.nums) if m == num]
            
    def go(self, opes:str):
        for ope in opes:
            if ope == "N":
                self.go_north()
            elif ope == "E":
                self.go_east()
            elif ope == "W":
                self.go_west()
            else:
                self.go_south()
                
    def go_top(self, index):
        
        if index == 1:
            self.go_north()
        elif index == 2:
            self.go_west()
        elif index == 3:
            self.go_east()
        elif index == 4:
            self.go_south()
        elif index == 5:
            self.go_north()
            self.go_north()
            
    def go_ahead(self, index):

        if index == 2:
            self.go_cw()
        elif index == 4:
            self.go_cw()
            self.go_cw()
        elif index == 3:
            self.go_ccw()
            
        
    def go_north(self):
        self._shift((0, 1), (1, 5), (5, 4))
        
    def go_east(self):
        self._shift((0, 3), (3, 5), (5, 2))
        
    def go_west(self):
        self._shift((0, 2), (2, 5), (5, 3))
        
    def go_south(self):
        self._shift((0, 4), (4, 5), (5, 1))
        
    def go_ccw(self):
        self._shift((3, 4), (4, 2), (2, 1))
        
    def go_cw(self):
        self._shift((3, 1), (1, 2), (2, 4))
        
        
class Dice(_Dice):
    
    @classmethod
    def isequal(cls, a:_Dice, b:_Dice):
                
        for top in a.get_matches(b.nums[0]):
            a.go_top(top)
            for ahead in a.get_matches(b.nums[1]):
                a.go_ahead(ahead)
                
                for i, j in zip(a.nums, b.nums):
                    if i != j:
                        break
                else:
                    return True
            
        else:
            return False
        

dice_A = Dice(map(int, input().split()))
dice_B = Dice(map(int, input().split()))
print("Yes" if Dice.isequal(dice_A, dice_B) else "No")

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self):
        self.nums = list(range(6))
        self.work = list(range(6))

    def set_nums(self, n0, n1, n2, n3, n4, n5):
        self.nums[0] = n0
        self.nums[1] = n1
        self.nums[2] = n2
        self.nums[3] = n3
        self.nums[4] = n4
        self.nums[5] = n5

    def rotate(self, cmd):
        for i in range(6):
            # deepcopy
            self.work[i] = self.nums[i]

        if cmd == 'N':
            self.set_nums(self.work[1], self.work[5], self.work[2], self.work[3], self.work[0], self.work[4])
        elif cmd == 'S':
            self.set_nums(self.work[4], self.work[0], self.work[2], self.work[3], self.work[5], self.work[1]),
        elif cmd == 'E':
            self.set_nums(self.work[3], self.work[1], self.work[0], self.work[5], self.work[4], self.work[2])
        else:
            self.set_nums(self.work[2], self.work[1], self.work[5], self.work[0], self.work[4], self.work[3])

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

    def right(self, top, front):
        # サイコロの面IDを返す
        if top == 1:
            return [3,5,2,4][front-2]
        elif top == 6:
            return [4,2,5,3][front-2]
        elif top == 2:
            # 0が返る場合は不正なサイコロ
            return [4,0,1,6,0,3][front-1]
        elif top == 5:
            # 0が返る場合は不正なサイコロ
            return [3,0,6,1,0,4][front-1]
        elif top == 3:
            # 0が返る場合は不正なサイコロ
            return [2,6,0,0,1,5][front-1]
        elif top == 4:
            # 0が返る場合は不正なサイコロ
            return [5,1,0,0,6,2][front-1]
        else:
            pass

    def rolls(self):
        # 上面、前面、右面、左面、奥面、下面の値を返す
        return [self.nums[i] for i in range(6)]

import random
nums_1 = [int(arg) for arg in input().split()]
nums_2 = [int(arg) for arg in input().split()]
d1 = Dice()
d1.set_nums(*nums_1)
d2 = Dice()
d2.set_nums(*nums_2)
d1_roll = d1.rolls()


for i in range(10000):
    cmd = ['N', 'S', 'E', 'W'][random.randint(0,3)]
    d2.rotate(cmd)
    d2_roll = d2.rolls()
    if all([d1_roll[i] == d2_roll[i] for i in range(6)]):
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
import sys

class Dice:
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.dice = [d1,d2,d3,d4,d5,d6]
    def turn(self,dir):
        if dir == 'S':
            self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
        if dir == 'N':
            self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
        if dir == 'W':
            self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
        if dir == 'E':
            self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]


def check(dice1,dice2):
    for b in range(4):
        dice1.turn('N')
        if dice1.dice[0] == dice2.dice[0] and dice1.dice[1] == dice2.dice[1] and dice1.dice[2] == dice2.dice[2] and dice1.dice[3] == dice2.dice[3] and dice1.dice[4] == dice2.dice[4] and dice1.dice[5] == dice2.dice[5]:
            print('Yes')
            sys.exit()

dice1_num = list(map(int,input().split()))
dice2_num = list(map(int,input().split()))
init_Dice1 = Dice(dice1_num[0],dice1_num[1],dice1_num[2],dice1_num[3],dice1_num[4],dice1_num[5])
init_Dice2 = Dice(dice2_num[0],dice2_num[1],dice2_num[2],dice2_num[3],dice2_num[4],dice2_num[5])


check(init_Dice1,init_Dice2)
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
init_Dice2.turn('N')
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
init_Dice2.turn('E')
check(init_Dice1,init_Dice2)
print('No')