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:
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def clock(self):
        t = dict(self._men)
        self._men["E"] = t["N"]
        self._men["N"] = t["W"]
        self._men["W"] = t["S"]
        self._men["S"] = t["E"]


    def simpleequal(self, d2):
        if self._men == d2._men:
            return True
        else:
            return False


    def equal(self, d2):
        for _ in range(4):
            d2.roll("N")

            for _ in range(4):
                d2.clock()
                if self.simpleequal(d2):
                    return True

        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True


        d2.roll("E")
        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True



    def gettop(self):
        return self._men["T"]

def decode():
    numlist1 = [int(x) for x in input().split()]
    numlist2 = [int(x) for x in input().split()]

    return numlist1, numlist2


if __name__ == '__main__':

    numlist1, numlist2 = decode()
    d1 = dice(numlist1)
    d2 = dice(numlist2)

    if d1.equal(d2):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import random

class Dice:
    def __init__(self, hoge):
        self.num = hoge
        self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} 
    
    def move(self, direct):
        previouse = {k: v for k, v in self.face.items()}
        if direct == 'E':
            self.face['U'] = previouse['W']
            self.face['W'] = previouse['B']
            self.face['E'] = previouse['U']
            self.face['B'] = previouse['E']
        elif direct == 'W':
            self.face['U'] = previouse['E']
            self.face['W'] = previouse['U']
            self.face['E'] = previouse['B']
            self.face['B'] = previouse['W']
        elif direct == 'N':
            self.face['U'] = previouse['S']
            self.face['N'] = previouse['U']
            self.face['S'] = previouse['B']
            self.face['B'] = previouse['N']
        elif direct == 'S':
            self.face['U'] = previouse['N']
            self.face['N'] = previouse['B']
            self.face['S'] = previouse['U']
            self.face['B'] = previouse['S']
    
    def get_num(self, place):
        return self.num[self.face[place]]
    
    def getFace(self):
        for k, v in sorted(self.face.items()):
            yield self.num[v]
    
        
if __name__ == '__main__':
    dice1 = Dice([int(x) for x in input().split()])
    dice2 = Dice([int(x) for x in input().split()])
    d = ['E', 'W', 'N', 'S']
    for k in range(1000):
        c = 0
        rand_num = random.randint(0, 3)
        dice2.move(d[rand_num])
        
        for v1, v2 in zip(dice1.getFace(), dice2.getFace()):
            if v1 == v2:
                c += 1
        if c == 6:
            print ('Yes')
            break
        if k == 999:
            print ('No')

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self, top, dside, rside, lside, uside, bottom):
        self.top = top
        self.dside = dside
        self.rside = rside
        self.lside = lside
        self.uside = uside
        self.bottom = bottom
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = Dice(num1[0], num1[1], num1[2], num1[3], num1[4], num1[5])
dice2 = Dice(num2[0], num2[1], num2[2], num2[3], num2[4], num2[5])
if len(set(num1))<4:
    while(dice1.top!=dice2.top or dice1.rside!=dice2.rside
          or dice1.dside!=dice2.dside):
        mode = random.randint(0, 2)
        if mode==0: 
            dice2.north()
        elif mode==1: 
            dice2.east()
        else: 
            dice2.south()
else:
    while dice1.top!=dice2.top or dice1.rside!=dice2.rside:
        mode = random.randint(0, 2)
        if mode==0: 
            dice2.north()
        elif mode==1: 
            dice2.east()
        else: 
            dice2.south()
if dice1.bottom==dice2.bottom and dice1.lside==dice2.lside:
    if dice1.dside==dice2.dside: 
        print("Yes")
    else: 
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
class dice():
    def __init__(self,number):
        self.number = number

    def korokoro(self,com):
        if com == 'E':
            self.number = [self.number[i] for i in [3,1,0,5,4,2]]
        if com == 'S':
            self.number = [self.number[i] for i in [4,0,2,3,5,1]]
        if com == 'N':
            self.number = [self.number[i] for i in [1,5,2,3,0,4]]
        if com == 'W':
            self.number = [self.number[i] for i in [2,1,5,0,4,3]]
d1 = dice([int(x) for x in input().split()])
d2 = dice([int(x) for x in input().split()])
for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE':
    d1.korokoro(com)
    if d1.number == d2.number:
        ans = 'Yes'
        break
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]
    def isSameDice(self, anotherDice):
        if \
        self.dice[0] == anotherDice.dice[0] and \
        self.dice[1] == anotherDice.dice[1] and \
        self.dice[2] == anotherDice.dice[2] and \
        self.dice[3] == anotherDice.dice[3] and \
        self.dice[4] == anotherDice.dice[4] and \
        self.dice[5] == anotherDice.dice[5]:
            return True
        return False


import random

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

flag = False
# rotate dice2 to random directions many times
# until we get the coincident between the two dices.
for i in range(1000):
    k = random.randint(0, 4)
    if k == 0:
        dice2.east()
    elif k == 1:
        dice2.west()
    elif k == 2:
        dice2.north()
    else:
        dice2.south()
    if dice2.isSameDice(dice1):
        flag = True
        break

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

side = ((2-1, 3-1, 5-1, 4-1), (6-1, 3-1, 1-1, 4-1), (1-1, 2-1, 6-1, 5-1),
        (1-1, 5-1, 6-1, 2-1), (1-1, 3-1, 6-1, 4-1), (5-1, 3-1, 2-1, 4-1))

def check_rotate(face1, face2, f2_index):
    f1_bot = face1[5]
    if face2[5-f2_index] != f1_bot:
        return False
    f2_side_index = side[f2_index] * 2
    f2_side = [face2[f2_side_index[i]] for i in range(len(f2_side_index))]
    f1_side = [face1[i] for i in (2-1, 3-1, 5-1, 4-1)]
    # print(f1_side, f2_side)

    for i in range(4):
        if f1_side == f2_side[i:i+4]:
            return True

    return False

def check_ident(face1, face2):
    f1_top = face1[0]
    for index in range(len(face2)):
        if face2[index] == f1_top:
            if check_rotate(face1, face2, index):
                return True

    return False


face1 = sys.stdin.readline().split()
face2 = sys.stdin.readline().split()

if check_ident(face1, face2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
        self.t = dice[0]
        self.s = dice[1]
        self.e = dice[2]
        self.w = dice[3]
        self.n = dice[4]
        self.b = dice[5]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]
    def spin(self):
        self.dice[1] = self.buff[3]
        self.dice[2] = self.buff[1]
        self.dice[4] = self.buff[2]
        self.dice[3] = self.buff[4]
        self.buff = [n for n in self.dice]
    def to_be_the_same_direction(self, anotherDice):
        if self.t == anotherDice.t:
            pass
        elif self.t == anotherDice.e:
            anotherDice.west()
        elif self.t == anotherDice.w:
            anotherDice.east()
        elif self.t == anotherDice.n:
            anotherDice.south()
        elif self.t == anotherDice.s:
            anotherDice.north()
        else:
            anotherDice.north()
            anotherDice.north()
    def isSameDice(self, anotherDice):
        if  self.dice[0] == anotherDice.dice[0] and \
            self.dice[1] == anotherDice.dice[1] and \
            self.dice[2] == anotherDice.dice[2] and \
            self.dice[3] == anotherDice.dice[3] and \
            self.dice[4] == anotherDice.dice[4] and \
            self.dice[5] == anotherDice.dice[5]:
                return True
        return False
    def compare(self, anotherDice):
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.west()
        self.west()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()
        return False

nums1 = [int(x) for x in input().split()]
nums2 = [int(x) for x in input().split()]
dice1 = Dice(nums1)
dice2 = Dice(nums2)

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

Submission status: Accepted

Solution code:
class Dice:
    """サイコロを操作するクラス"""
    def __init__(self, num):
        self.num = num
    def roll_north(self):
        tmp = self.num[:]
        self.num[0] = tmp[1]
        self.num[1] = tmp[5]
        self.num[4] = tmp[0]
        self.num[5] = tmp[4]
    def roll_east(self):
        tmp = self.num[:]
        self.num[0] = tmp[3]
        self.num[2] = tmp[0]
        self.num[3] = tmp[5]
        self.num[5] = tmp[2]
    def roll_right(self):
        tmp = self.num[:]
        self.num[1] = tmp[3]
        self.num[2] = tmp[1]
        self.num[3] = tmp[4]
        self.num[4] = tmp[2]
    def print_dice(self):
        print(self.num)

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))
flg = False
for i in range(20):
    if flg == True:
        break
    dice2.roll_north()
    for k in range(20):
        if flg == True:
            break
        dice2.roll_east()
        for l in range(20):
            dice2.roll_right()
            if dice1.num == dice2.num:
                flg = True
                break
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, v1, v2, v3, v4, v5, v6):
        self.faces = [(v1, v6), (v2, v5), (v3, v4)]

    def rotate_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, rgt, bck, fnt, lft, btm)

    def rotate_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, lft, fnt, bck, rgt, btm)

    def turn_back(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(fnt, btm, rgt, lft, top, bck)

    def turn_front(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(bck, top, rgt, lft, btm, fnt)

    def turn_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(lft, fnt, top, btm, bck, rgt)

    def turn_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(rgt, fnt, btm, top, bck, lft)

    def __str__(self):
        return "<{}>".format(",".join([str(t) for t in self.faces]))

    def __eq__(self, other):
        def equals(d1, d2):
            return d1.faces == d2.faces

        (top, btm) = self.faces[0]
        if (top, btm) in other.faces:
            return (equals(self, other)
                    or equals(self.rotate_right(), other)
                    or equals(self.rotate_left(), other)
                    or equals(self.turn_right(), other)
                    or equals(self.turn_front(), other)
                    or equals(self.rotate_left().rotate_left(), other)
                    or equals(self.turn_back().rotate_left(), other)
                    or equals(self.turn_front().rotate_right(), other)
                    or equals(self.turn_right().rotate_left(), other)
                    or equals(self.turn_left().rotate_right(), other)
                    or equals(self.turn_right().turn_back().turn_back(),
                              other)
                    or equals(self.turn_front().turn_right().turn_right(),
                              other))
        elif (btm, top) in other.faces:
            return self.turn_front().turn_front() == other
        else:
            return False


def run():
    dice1 = Dice(*[int(i) for i in input().split()])
    dice2 = Dice(*[int(i) for i in input().split()])

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


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
d = input().split()
a = input().split()
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]
ts = [i for i, x in enumerate(d) if x == a[0]]
fs = [i for i, x in enumerate(d) if x == a[1]]
b = 0
for t in ts:
  for f in fs:
    if t == f: continue
    r = p[t][f]
    if r == -1: continue
    l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
    if a == l: b += 1; break
print("Yes") if b > 0 else print("No")

Submission status: Accepted

Solution code:
class Dice3():
    def check(self,dice1,dice2):
        #縦回転
        for i in range(4):
            dice1[0],dice1[1],dice1[5],dice1[4]=dice1[4],dice1[0],dice1[1],dice1[5]
        #横回転
            for j in range(4):
                dice1[0],dice1[2],dice1[5],dice1[3]=dice1[3],dice1[0],dice1[2],dice1[5]
        #ひねり
                for k in range(4):
                    dice1[1],dice1[2],dice1[4],dice1[3]=dice1[2],dice1[4],dice1[3],dice1[1]
                    if dice1 == dice2:
                        print('Yes')
                        return 0
        return

        
#Dice3
dc3 = Dice3()
Dice1 = [int(i) for i in input().split()]
Dice2 = [int(i) for i in input().split()]
ck = dc3.check(Dice1,Dice2)
if ck != 0:
    print('No')

Submission status: Accepted

Solution code:
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]
 
def set_top(dice, top):
    return [dice[i] for i in mask[top]]
 
def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]
 
def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
         
dice1 = input().split()
dice2 = input().split()
 
print('Yes' if equal(dice1, dice2) else 'No')

Submission status: Accepted

Solution code:
class Dice:
    TOP, SOUTH, EAST, WEST, NORTH, BOTTOM = 0, 1, 2, 3, 4, 5
    def __init__(self, d):
        self.dice = d[:]
        self.top = d[0]
        self.south = d[1]
        self.east = d[2]
        self.west = d[3]
        self.north = d[4]
        self.bottom = d[5]

    def __eq__(self, other):
        a = self.permutations()
        a.sort()

        d2 = Dice(other.dice)
        b = d2.permutations()
        b.sort()

        return a == b

    def permutations(self):
        copy = self.dice[:]
        perm = []
        for d in [(), ("S"), ("N"), ("E"), ("W"), ("W", "W")]:
            t = Dice(copy)
            for m in d:
                t.move(m)

            perm.append(t.dice[:])
            for i in range(3):
                t.move("R")
                perm.append(t.dice[:])

        return perm
        
    def set_top_front(self, top, front):
        for i, n in enumerate(self.dice):
            if n == top:
                if i == Dice.TOP: pass
                elif i == Dice.SOUTH: self.move("N")
                elif i == Dice.EAST: self.move("W")
                elif i == Dice.WEST: self.move("E")
                elif i == Dice.NORTH: self.move("S")
                elif i == Dice.BOTTOM:
                    self.move("S")
                    self.move("S")

                break
        else:
            return False
        
        for i, n in enumerate(self.dice):
            if n == front:
                if i == Dice.TOP: return False
                elif i == Dice.SOUTH: pass
                elif i == Dice.EAST: self.move("R")
                elif i == Dice.WEST: self.move("L")
                elif i == Dice.NORTH:
                    self.move("R")
                    self.move("R")
                elif i == Dice.BOTTOM: return False

                break
        else:
            return False

        return True
        
    def move(self, d):
        if d == "N":
            self.move_north()
        elif d == "W":
            self.move_west()
        elif d == "S":
            self.move_south()
        elif d == "E":
            self.move_east()
        elif d == "R":
            self.move_right()
        elif d == "L":
            self.move_left()

        self.dice = [
            self.top,
            self.south,
            self.east,
            self.west,
            self.north,
            self.bottom,
        ]

    def move_right(self):
        self.north, self.west, self.south, self.east \
            = self.west, self.south, self.east, self.north

    def move_left(self):
        self.north, self.west, self.south, self.east \
            = self.east, self.north, self.west, self.south

    def move_north(self):
        self.top, self.south, self.bottom, self.north \
            = self.south, self.bottom, self.north, self.top

    def move_south(self):
        self.top, self.south, self.bottom, self.north \
            = self.north, self.top, self.south, self.bottom

    def move_east(self):
        self.top, self.east, self.bottom, self.west \
            = self.west, self.top, self.east, self.bottom

    def move_west(self):
        self.top, self.east, self.bottom, self.west \
            = self.east, self.bottom, self.west, self.top

if __name__ == "__main__":
    import re

    nums1 = [int(n) for n in re.split(r"\s+", input().strip())]
    dice1 = Dice(nums1)

    nums2 = [int(n) for n in re.split(r"\s+", input().strip())]
    dice2 = Dice(nums2)

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

Submission status: Accepted

Solution code:
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List
dice = list(map(int, input().split()))
D = [dice]
for i in range(0, 3):
    D.append(north(D[i]))
D.append(south(west(D[0])))
D.append(south(east(D[0])))
for i in range(6):
    for j in range(3):
        if j == 0:
            D.append(east(D[i + j]))
        else:
            D.append(east(D[5 + 3 * i + j]))

dice2 = list(map(int, input().split()))
k = 0
for i in range(len(D)):
    if dice2 == D[i]:
        print('Yes')
        k = 1
        break
if k == 0:
    print('No')

Submission status: Accepted

Solution code:
#! python3
# dice_iii.py

class dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.south = arr[1]
        self.east = arr[2]
        self.west = arr[3]
        self.north = arr[4]
        self.bottom = arr[5]

    def rotate(self, ope):
        if ope == 'S':
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif ope == 'N':
            self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
        elif ope == 'E':
            self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
        elif ope == 'W':
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif ope == 'R': # clockwise
            self.south, self.east, self.north, self.west = self.east, self.north, self.west, self.south
        elif ope == 'L': # reversed clockwise
            self.south, self.east, self.north, self.west = self.west, self.north, self.east, self.south
        else:
            pass

    def get_surfaces(self):
        return [self.top, self.south, self.east, self.north, self.west, self.bottom]

dc1 = dice([int(x) for x in input().split(' ')])
dc2 = dice([int(x) for x in input().split(' ')])

judged = False
if len((dc1.get_surfaces() and dc2.get_surfaces())) == 6:
    opes = ['', 'S', 'E', 'S', 'E', 'S']
    for op in opes:
        dc2.rotate(op)
        for i in range(4):
            if dc1.get_surfaces() == dc2.get_surfaces():
                judged = True
                break
            dc2.rotate('R')
        if judged: break

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

Submission status: Accepted

Solution code:
d,e=[input().split()for _ in'12'];e[3:5]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3:5]=f[4:2:-1]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Submission status: Accepted

Solution code:
import sys

class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    def west(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0]
    def north(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0]
    def south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]

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

south_cnt = 0

for i in range(8):
    for j in range(4):    
        if dice1.labels[0] == dice2.labels[0] and dice1.labels[1] == dice2.labels[1] and dice1.labels[2] == dice2.labels[2] and dice1.labels[3] == dice2.labels[3] and dice1.labels[4] == dice2.labels[4] and dice1.labels[5] == dice2.labels[5]:
            print("Yes")
            sys.exit()

        dice2.south()
        dice2.east()
        dice2.north()

    if south_cnt == 4:
        dice2.east()
    else:
        dice2.south()
        south_cnt += 1
    
print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def __eq__(self, other):
        return self.upper == other.upper and self.backward == other.backward and self.right == other.right and self.left == other.left and self.ahead == other.ahead and self.bottom == other.bottom

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper

    def roll_side(self):
        self.ahead, self.right, self.backward, self.left = self.left, self.ahead, self.right, self.backward


def match_dice(dice1, dice2):
    for i in range(4):
        dice1.roll_north()

        for j in range(4):
            dice1.roll_east()

            for k in range(4):
                dice1.roll_side()

                if dice2 == dice1:
                    return 0
    return 1


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

if result is 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[t,f,r,l,b,u]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d):
        self.a=[self.a[i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice1=Dice(t,f,r,l,b,u)
t,f,r,l,b,u=map(int,input().split())
dice2=Dice(t,f,r,l,b,u)
s='SSSWEEE'
w='YYYY'
ans='No'
for j in s:
    for r in w:
        if dice1.a==dice2.a:
            ans='Yes'
            break
        dice2.roll(r)
    else:
        dice2.roll(j)
        continue
    break
print(ans)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[t,f,r,l,b,u]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d):
        self.a=[self.a[i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice1=Dice(t,f,r,l,b,u)
t,f,r,l,b,u=map(int,input().split())
dice2=Dice(t,f,r,l,b,u)
s='SSSEWWW'
w='YYYY'
ans='No'
for j in s:
    for r in w:
        if dice1.a==dice2.a:
            ans='Yes'
            break
        dice2.roll(r)
    else:
        dice2.roll(j)
        continue
    break
print(ans)