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:
#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = "NNNNWNNNWNNNENNNENNNWNNN"

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

    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == "E":
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == "N":
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == "S":
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == "W":
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def query(self,top_num,front_num):
        self.save_data =[i for i in range(6)]

        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1
        
        for i in range(len(self.order)):
            self.roll(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_data[i]
        
        return ret
    def get_Top(self):
        return self.number[0]
    
    def equals(self,another):
        ret = False
        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG =False
                    break
            if FLG :
                return True
        return ret
diceA = Dice()
diceB = Dice()
table = list(map(int,input().split()))
diceA.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])
table = list(map(int,input().split()))
diceB.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])

if diceA.equals(diceB):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import itertools
def get_dice():
    input_data = input().split(" ")
    items = [int(cont) for cont in input_data]
    keys = ['T', 'S', 'E', 'W', 'N', 'B']
    return dict(zip(keys, items))

def rot_dice(rot, dice):
    if rot == "N":
        keys = ['T', 'S', 'B', 'N']
        items = dice['S'], dice['B'], dice['N'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "S":
        keys = ['T', 'S', 'B', 'N']
        items = dice['N'], dice['T'], dice['S'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "E":
        keys = ['T', 'E', 'B', 'W']
        items = dice['W'], dice['T'], dice['E'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "W":
        keys = ['T', 'E', 'B', 'W']
        items = dice['E'], dice['B'], dice['W'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "R":
        keys = ['N', 'W', 'S', 'E']
        items = dice['E'], dice['N'], dice['W'], dice['S']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

def search_right_surf(conds, dice):
    a, b = conds
    a_key = [k for k, v in dice.items() if v == a]
    b_key = [k for k, v in dice.items() if v == b]
    key_list = a_key + b_key

    part_st = ''.join(key_list)

    def search(part_st):
        if part_st in "TNBST":
            return "W"

        if part_st in "TSBNT":
            return "E"

        if part_st in "TEBWT":
            return "N"

        if part_st in "TWBET":
            return "S"

        if part_st in "NESWN":
            return "B"

        if part_st in "NWSEN":
            return "T"

    target_key = search(part_st)
    print(dice[target_key])

def search_top_surf(top_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == top_surf]

    if dice2_surf == 'N':
        rot_dice("S", dice)

    if dice2_surf == 'B':
        controls = list("SS")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'S':
        controls = list("N")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'W':
        controls = list("E")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'E':
        controls = list("W")
        for i in controls:
            rot_dice(i, dice)

def search_flont_surf(flont_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == flont_surf]

    if dice2_surf == 'E':
        controls = list("R")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'S':
        controls = list("RR")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'W':
        controls = list("RRR")
        for i in controls:
            rot_dice(i, dice)

def perfect_rot_compare(dice1, dice2):

        def compare_dice():
            if dice1 == dice2:
                return True
        if compare_dice():
            return True
        Rs = ["", "R", "RR", "RRR", "RRRR"]
        Ns = ["", "N", "NN", "NNN", "NNNN"]
        Es = ["", "E", "EE", "EEE", "EEEE"]
        for i, j, k in itertools.product(Rs, Ns, Es):
            controls = list(i+j+k)
            for t in controls:
                rot_dice(t, dice2)
            if compare_dice():
                return True
        return False


def q1():

    dice=get_dice()
    controls = list(input())
    for i in controls:
        rot_dice(i, dice)
    print(dice["T"])

def q2():

    dice=get_dice()
    a = input()
    repeater = int(a)

    for neee in range(repeater):
        control_input = input().split(" ")
        conds = [int(i) for i in control_input]
        search_right_surf(conds, dice)

def q3():
    dice1 = get_dice()
    dice2 = get_dice()

    if perfect_rot_compare(dice1, dice2):
        print("Yes")
    else:
        print("No")

def q4():
    inp = input()
    dice_num = int(inp)
    dice_list = list()
    for i in range(dice_num):
        dice_list.append(get_dice())

    def compare_many_dices():
        dice1 = dice_list[0]
        for dice in dice_list:
            if not perfect_rot_compare(dice1, dice):
                return False
        return True

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

q3()

Submission status: Accepted

Solution code:
def create_dice(nums):
    a, b, c, d, e, f = nums
    vertical = [a, b, f, e]
    horizontal = [b, c, e, d]
    return Dice(vertical, horizontal)


class Dice:
    def __init__(self, v, h):
        self.vertical = v
        self.horizontal = h

    def v2h(self):
        self.horizontal[0] = self.vertical[1]
        self.horizontal[2] = self.vertical[3]

    def h2v(self):
        self.vertical[1] = self.horizontal[0]
        self.vertical[3] = self.horizontal[2]

    def roll(self, direction):
        if direction == 'N':
            tmp1 = self.vertical[0]
            tmp2 = self.vertical[1:]
            self.vertical = tmp2 + [tmp1]
            self.v2h()
        elif direction == 'S':
            tmp1 = self.vertical[-1]
            tmp2 = self.vertical[:-1]
            self.vertical = [tmp1] + tmp2
            self.v2h()
        elif direction == 'E':
            tmp1 = self.horizontal[0]
            tmp2 = self.horizontal[1:]
            self.horizontal = tmp2 + [tmp1]
            self.h2v()
        elif direction == 'W':
            tmp1 = self.horizontal[-1]
            tmp2 = self.horizontal[:-1]
            self.horizontal = [tmp1] + tmp2
            self.h2v()


s1 = map(int, input().split(" "))
d1 = create_dice(s1)

s2 = map(int, input().split(" "))
d2 = create_dice(s2)


def match(l1, l2):
    lenlist = len(l1)
    lenset = len(set(l1))
    if lenlist == lenset:
        return l1[0] == l2[0]
    else:
        diff = 4 - (lenlist - lenset) + 1
        for i in range(diff):
            if l1[i] != l2[i]:
                return False
        return True

r = 0
while d1.vertical != d2.vertical and d1.horizontal != d2.horizontal and r < 4:
    # 強制的に一つ回す
    d2.roll("E")

    v = 0
    while not match(d1.vertical, d2.vertical) and v < 4:
        d2.roll("N")
        v += 1

    h = 0
    while not match(d1.horizontal, d2.horizontal) and v < 4:
        d2.roll("E")
        h += 1

    r += 1

if d1.vertical == d2.vertical and d1.horizontal == d2.horizontal:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, d):
        self.d = d

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

    def roll(self, direction):
        if direction == "E":
            self.setNum(
                self.d[3], self.d[1], self.d[0], self.d[5], self.d[4], self.d[2]
            )
        elif direction == "N":
            self.setNum(
                self.d[1], self.d[5], self.d[2], self.d[3], self.d[0], self.d[4]
            )
        elif direction == "S":
            self.setNum(
                self.d[4], self.d[0], self.d[2], self.d[3], self.d[5], self.d[1]
            )
        elif direction == "W":
            self.setNum(
                self.d[2], self.d[1], self.d[5], self.d[0], self.d[4], self.d[3]
            )

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

flag = False
for i in list("NNNNWNNNWNNNENNNENNNWNNN"):
    d2.roll(i)
    if d1.d[0] == d2.d[0]:
        if d1.d == d2.d:
            flag = True

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

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self,top,front,right,left,back,bottom):
        self.top, self.bottom=top,bottom
        self.right, self.left=right,left
        self.front, self.back=front,back
    def turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
d1=map(int,raw_input().split())
d2=map(int,raw_input().split())
dice1=Dice(d1[0],d1[1],d1[2],d1[3],d1[4],d1[5])
dice2=Dice(d2[0],d2[1],d2[2],d2[3],d2[4],d2[5])
flg=0
for i in range(1000):
    d="NSWE"[random.randint(0,3)]
    dice1.turn(d)
    if dice1.top==dice2.top and dice1.front==dice2.front and dice1.right==dice2.right and dice1.left==dice2.left and dice1.back==dice2.back and dice1.bottom==dice2.bottom:
        print "Yes"
        flg=1
        break
if flg==0:
    print "No"

Submission status: Accepted

Solution code:
import copy


def move(lon, lat, com):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if com == "E" or com == "W":
        target, other = lat, lon
    if com == "S" or com == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    com = "N" if upper in lon else "E"
    for _i in range(4):
        move(lon, lat, com)
        if lon[0] == upper:
            break


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


longitude = [0, 1, 5, 4]
latitude = [0, 3, 5, 2]

values = list(input().split())
u, f = values[longitude[0] - 1], values[longitude[1] - 1]
values2 = list(input().split())
longitude2, latitude2 = copy.copy(longitude), copy.copy(latitude)
result = "No"
for i in range(6):
    set_upper(longitude2, latitude2, i)
    for j in range(4):
        rotate(longitude2, latitude2, "R")
        if values[0] != values2[longitude2[0]]:
            continue
        elif values[1] != values2[longitude2[1]]:
            continue
        elif values[2] != values2[latitude2[3]]:
            continue
        elif values[3] != values2[latitude2[1]]:
            continue
        elif values[4] != values2[longitude2[3]]:
            continue
        elif values[5] != values2[longitude2[2]]:
            continue
        else:
            result = "Yes"
            break
    if result == "Yes":
        break
print(result)

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

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

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


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]
        
    def query(self, top_num, front_num):
        self.save_data = [i for i in range(6)]
        for i in range(6):
            self.save_data[i] = self.number[i]
            
        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
            
        for i in range(6):
            self.number[i] = self.save_data[i]
            
        return ret
        
    def equals(self, another):
        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return False

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

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
import math


#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

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

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


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def query(self,top_num,front_num):

        self.save_data = [i for i in range(6)]
        #元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1

        for i in range(len(self.order)):
            self.roll(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_data[i]

        return ret

    def equals(self,another):

        ret = False

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret

diceA = Dice()
diceB = Dice()

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

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

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def rotate(faces, move):
    for i in range(len(move)):
        m = move[i]
        
        if m == "N":
            # N
            tmp = faces[4]
            faces[4] = faces[0]
            faces[0] = faces[1]
            faces[1] = faces[5]
            faces[5] = tmp
            
        elif m == "S":
            # S
            tmp = faces[1]
            faces[1] = faces[0]
            faces[0] = faces[4]
            faces[4] = faces[5]
            faces[5] = tmp
            
        elif m == "E":
            # E
            tmp = faces[2]
            faces[2] = faces[0]
            faces[0] = faces[3]
            faces[3] = faces[5]
            faces[5] = tmp
            
        elif m == "W":
            # W
            tmp = faces[3]
            faces[3] = faces[0]
            faces[0] = faces[2]
            faces[2] = faces[5]
            faces[5] = tmp

# for k, v in enumerate(dice1):
#     print(k, v)
#     if v in dice2:
#         index1 = dice2.index(v)
#         print(index1)

# if dice1[2] in dice2:
#     index1 = dice2.index(dice1[2])
#     if index1 == 0:
#         rotate(dice1, "W")
#     elif index1 == 1:
#         rotate(dice1, "WS")
#     elif index1 == 2:
#         pass
#     elif index1 == 3:
#         rotate(dice1, "WW")
#     elif index1 == 4:
#         rotate(dice1, "WN")
#     elif index1 == 5:
#         rotate(dice1, "E")
        
def equals(a, b):
    for (a, b) in zip(dice1, dice2):
        if a != b:
            return False
            
    return True

isMatch = equals(dice1, dice2)

copy_list = dice1.copy()

looping = True
for j in range(4):
    #print(dice1)
    if isMatch:
        break
    for i in range(4):
        # print(dice1)
        rotate(dice1, "N")
        if equals(dice1, dice2):
            isMatch = True
            break
    #print('----')
    #print(dice1)
    rotate(dice1, "W")
    #print(dice1)

# print('---- ---- ----')
#print(copy_list)
# print('---- ---- ----')

rotate(dice1, "NW")

for j in range(4):
    #print(dice1)
    if isMatch:
        break
    for i in range(4):
        #print(dice1)
        rotate(dice1, "N")
        if equals(dice1, dice2):
            isMatch = True
            break
    #print('----')
    #print(dice1)
    rotate(dice1, "W")
    #print(dice1)


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

Submission status: Accepted

Solution code:
class dice:
    def __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
    
    def W(s):
        tmp = s.d1
        s.d1 = s.d3
        s.d3 = s.d6
        s.d6 = s.d4
        s.d4 = tmp
        
    def E(s):
        tmp = s.d1
        s.d1 = s.d4
        s.d4 = s.d6
        s.d6 = s.d3
        s.d3 = tmp
        
    def N(s):
        tmp = s.d1
        s.d1 = s.d2
        s.d2 = s.d6
        s.d6 = s.d5
        s.d5 = tmp
        
    def S(s):
        tmp = s.d1
        s.d1 = s.d5
        s.d5 = s.d6
        s.d6 = s.d2
        s.d2 = tmp
        
    def L(s):
        tmp = s.d2
        s.d2 = s.d3
        s.d3 = s.d5
        s.d5 = s.d4
        s.d4 = tmp
        
    def isSame(s, d):
        flg = False
        
        #1つのダイスを基準に6面回す
        for i in range(6):
            #2つ目のダイスを6面全て上部に設定し、総当たり
            for j in range(6):
                if s.d1 == d.d1 and s.d6 == d.d6:
                    #上部、下部が一致した場合、左周りに回転させ側面が全て一致するか確認
                    for j in range(3):
                        if s.d2 == d.d2 and s.d3 == d.d3 and s.d4 == d.d4 and s.d5 == d.d5:
                            #全部の面が一致した場合、Trueを返し判定終了
                            return True
                        else:
                            #一致しない場合は左周り
                            d.L()
                    
                #一致するケースが無い場合、2つ目のダイスを回転させる
                if j <= 3:
                    d.N()
                elif j == 4:
                    d.E()
                else:
                    d.E()
                    d.E()
            
            #一致するケースが無い場合、基準のダイスを回転させる
            if i <= 3:
                s.N()
            elif i == 4:
                s.E()
            else:
                s.E()
                s.E()
        
        #全ケース一致する場合が無ければFalseを返す
        return False
        
dice1 = dice(input().split())
dice2 = dice(input().split())
if dice1.isSame(dice2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.NEWS = {"N": [0,4,5,1],
                     "E": [0,2,5,3],
                     "W": [0,3,5,2],
                     "S": [0,1,5,4],
                     "R": [1,2,4,3]}
       
    def move(self,aNEWS):
        idx = self.NEWS[aNEWS]
        tmp = self.LabelList[idx[0]]
        self.LabelList[idx[0]] = self.LabelList[idx[3]]
        self.LabelList[idx[3]] = self.LabelList[idx[2]]
        self.LabelList[idx[2]] = self.LabelList[idx[1]]
        self.LabelList[idx[1]] = tmp

def step2():
    for i in range(4):
        if Dise1.LabelList[1] == Dise2.LabelList[1] and \
           Dise1.LabelList[2] == Dise2.LabelList[2] and \
           Dise1.LabelList[3] == Dise2.LabelList[3] and \
           Dise1.LabelList[4] == Dise2.LabelList[4]:
            print("Yes")
            sys.exit()
        else:
            Dise2.move("R")
    print("No")
    sys.exit()

Dise1 = Dise(input().split())
Dise2 = Dise(input().split())

for i in range(4):
    if Dise1.LabelList[0] == Dise2.LabelList[0] and \
       Dise1.LabelList[5] == Dise2.LabelList[5]:
        step2()
    else:
        Dise2.move("E")

Dise2.move("N")
if Dise1.LabelList[0] == Dise2.LabelList[0] and \
   Dise1.LabelList[5] == Dise2.LabelList[5]:
    step2()

Dise2.move("S")
Dise2.move("S")
if Dise1.LabelList[0] == Dise2.LabelList[0] and \
   Dise1.LabelList[5] == Dise2.LabelList[5]:
    step2()

print("No")

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
nums2 = list(map(int, input().split()))

import random

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

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

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

Submission status: Accepted

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

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

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

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

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

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

if dice1.state == dice2.state:
  print('Yes')
else:
  is_eql = False
  for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
    if c == 'N':
      dice1.north()
    elif c == 'S':
      dice1.south()
    elif c == 'W':
      dice1.west()
    elif c == 'E':
      dice1.east()
    if dice1.state == dice2.state:
      is_eql = True
      break
  print('Yes' if is_eql else 'No')

Submission status: Accepted

Solution code:
import random

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

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

Submission status: Accepted

Solution code:
#East[north][top] -> E
class Dice():
 East = [ [0,3,5,2,4,0]
		 ,[4,0,1,6,0,3]
		 ,[2,6,0,0,1,5]
		 ,[5,1,0,0,6,2]
		 ,[3,0,6,1,0,4]
		 ,[0,4,2,5,3,0]
		 ]
 def __init__(self,N):
  self.label = N
  self.top = 1
  self.north = 5
 def move(self,ori):
  #print(self.top,self.north,ori)
  if ori=='S':
   t = self.top
   self.top = self.north
   self.north = 7-t
  elif ori=='N':
   t = self.top
   self.top = 7-self.north
   self.north = t
  elif ori=='E':
   east = self.East[self.north-1][self.top-1]
   self.top = 7-east
  elif ori=='W':
   east = self.East[self.north-1][self.top-1]
   self.top = east
# Clockwise
  elif ori=='C': 
   east = self.East[self.north-1][self.top-1]
   self.north = east
 def gettop(self):
  return( self.label[self.top-1] )
 def getbottom(self):
  return( self.label[6-self.top] )
 def getnorth(self):
  return( self.label[self.north-1] )
 def getsouth(self):
  return( self.label[6-self.north] )
 def geteast(self):
  east = self.East[self.north-1][self.top-1]
  return( self.label[east-1] )
 def getwest(self):
  east = self.East[self.north-1][self.top-1]
  return( self.label[6-east] )

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

# outer loop: put all 6 faces to the top to check
sMove = 'NNNEEE'
for mi in range(len(sMove)+1):
 if D.gettop() == E.gettop() and D.getbottom() == E.getbottom():
  sRot = 'CCCC'
  for ri in range(len(sRot)):
   if D.getnorth() == E.getnorth() and D.geteast() == E.geteast() and D.getsouth() == E.getsouth() and D.getwest() == E.getwest():
    print('Yes')
    exit()
   if ri<len(sRot):
    E.move(sRot[ri])
 if mi<len(sMove):
  E.move(sMove[mi])
print('No')