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:
import sys
from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def R(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_R(dice1, dice2) -> bool:
    """横回転をチェックする."""
    for _i in range(4):
        dice1.R()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False


# 提出用
data1 = [int(i) for i in input().split()]
data2 = [int(i) for i in input().split()]

# # 動作確認用1
# with open('input_itp1_11_c_2.txt', mode='r', encoding='utf8') as fin:
#     data1 = [int(i) for i in next(fin).split()]
#     data2 = [int(i) for i in next(fin).split()]

dice1 = Dice(data1)
dice2 = Dice(data2)


for _i in range(4):
    dice1.S()
    if dice1.get_upper_value() == dice2.get_upper_value():
        if check_R(dice1, dice2):
            print('Yes')
            sys.exit()

for _i in range(4):
    dice1.E()
    if dice1.get_upper_value() == dice2.get_upper_value():
        if check_R(dice1, dice2):
            print('Yes')
            sys.exit()

print('No')

Submission status: Accepted

Solution code:
from sys import stdin
from copy import deepcopy
import queue

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

d1_nums = [int(x) for x in stdin.readline().rstrip().split()]
d2_nums = [int(x) for x in stdin.readline().rstrip().split()]
if set(d1_nums) != set(d2_nums):
    print("No")

d1 = Dice(d1_nums)
d2 = Dice(d2_nums)

# TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする
memo = [[False] * 7 for i in range(7)]
memo[d1.pos["T"]][d1.pos["S"]] = ""

# クエリとさいころd1の状態を記憶
res = {}
for j in ["T", "S", "E"]:
    if d1.labels[d1.pos[j]] != d2.labels[d2.pos[j]]:
        break        
    else:
        res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

# BFSで探索, 今回は目の数字が同一である可能性があるため全探索
# ただし, T, S, Eがd2と同一のもののみresに登録
# diceの中身をいじってはならない
def solve(dice=d1):
    que = queue.Queue()
    que.put(dice)
    sol_q = ["E", "N", "S", "W"]
    
    while not que.empty():
        d = que.get()
        for i in sol_q:
            d_next = Dice.rolled(d, i)
            if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                que.put(d_next)
                memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                for j in ["T", "S", "E"]:
                    if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                        break
                else:
            	    res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next
    else:
        return True

solve()
check_pos = ["N", "W", "B"]
if len(res) == 0:
	print("No")
else:
    for k, v in res.items():
        for i in check_pos:
            if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                break
        else:
            print("Yes")
            break
    else:
        print("No")

Submission status: Accepted

Solution code:
from sys import stdin
from copy import deepcopy
import queue

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

    def isDiceSame(d1, d2):
        if not isinstance(d1, Dice) or not isinstance(d2, Dice):
            return False

        if set(d1.labels[1:]) != set(d2.labels[1:]):
            return False

        else:
            q = ["T", "S", "E", "N", "W", "B"]
            memo = [[False] * 7 for i in range(7)]
            memo[d1.pos["T"]][d1.pos["S"]] = ""
            res = {}
            for i in q[:3]:
                if d1.labels[d1.pos[i]] != d2.labels[d2.pos[i]]:
                    break
            else:
                res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

            def bfs_isDiceSame():
                que = queue.Queue()
                que.put(d1)

                while not que.empty():
                    d = que.get()
                    for i in q[1:5]:
                        d_next = Dice.rolled(d, i)
                        if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                            que.put(d_next)
                            memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                            for j in q[:3]:
                                if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                                    break
                            else:
                                res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next

            bfs_isDiceSame()
            if len(res) == 0:
                return False
            else:
                for k, v in res.items():
                    for i in q[3:]:
                        if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                            break
                    else:
                        return True
                else:
                    return False

d1_nums = [int(x) for x in stdin.readline().rstrip().split()]
d2_nums = [int(x) for x in stdin.readline().rstrip().split()]
d1 = Dice(d1_nums)
d2 = Dice(d2_nums)
if Dice.isDiceSame(d1, d2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face
  def check_face(self, face1):
    for i in range(4):
      if face1 == self.face:
        return self.face
      else:
        self.face[1],self.face[2],self.face[4],self.face[3] = self.face[2],self.face[4],self.face[3],self.face[1]

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = Dice()
dice2 = Dice()
dice1.make_dice(num1)
for i in range(6):
  dice2.make_dice(num2)
  if i == 0:
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 1:
    dice2.move("N")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 2:
    dice2.move("E")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 3:
    dice2.move("S")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 4:
    dice2.move("W")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
  elif i == 5:
    dice2.move("N")
    dice2.move("N")
    dice2.check_face(dice1.face)
    if dice1.face == dice2.face:
      print("Yes")
      break
    else:
      print("No")
      break

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    dice1 = Dice(*map(int, raw_input().split()))
    dice2 = Dice(*map(int, raw_input().split()))

    ref1 = set()
    ref2 = set()
    for _ in range(1000):
        if len(ref1) > 23:
            break

        ref1.add((dice1.top, dice1.s, dice1.e))
        ref2.add((dice2.top, dice2.s, dice2.e))

        dist = 'NSEW'[random.randint(0,3)]
        dice1.rotate(dist)
        dice2.rotate(dist)

    print 'Yes' if ref1==ref2 else 'No'

Submission status: Accepted

Solution code:
d1=list(map(int,input().split()))
d2=list(map(int,input().split()))
n=0

for i in range(4):
	d2[0],d2[1],d2[4],d2[5]=d2[1],d2[5],d2[0],d2[4]
	for i in range(4):
		d2[1],d2[3],d2[4],d2[2]=d2[3],d2[4],d2[2],d2[1]
		if d1[0]==d2[0] and d1[1]==d2[1] and d1[2]==d2[2] and d1[3]==d2[3] and d1[4]==d2[4] and d1[5]==d2[5]:
			n+=1
for i in range(4):
	d2[0],d2[3],d2[5],d2[2]=d2[3],d2[5],d2[2],d2[0]
	for i in range(4):
		d2[1],d2[3],d2[4],d2[2]=d2[3],d2[4],d2[2],d2[1]
		if d1[0]==d2[0] and d1[1]==d2[1] and d1[2]==d2[2] and d1[3]==d2[3] and d1[4]==d2[4] and d1[5]==d2[5]:
			n+=1		

if n==0:
	print('No')
elif n>0:
	print('Yes')

Submission status: Accepted

Solution code:
import copy


class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    def __eq__(self, other):
        if other is None or not isinstance(other, Dice):
            return False

        # different left side patterns
        dups = []
        for _ in range(6):
            dups.append(copy.copy(self))
        dups[1].roll('W')
        dups[2].roll('SW')
        dups[3].roll('NW')
        dups[4].roll('E')
        dups[5].roll('WW')

        for dup in dups:
            for _ in range(4):
                dup.roll('N')
                if other.eyes == dup.eyes:
                    return True

        return False

    @property
    def eyes(self):
        return self._eyes[1:6]

    def roll(self, direction_text):
        for d in direction_text:
            self.roll_once(d)

    def roll_once(self, direction):
        a = self._eyes
        if direction == 'N':
            self._eyes = ['dummy', a[2], a[6], a[3], a[4], a[1], a[5]]
        elif direction == 'S':
            self._eyes = ['dummy', a[5], a[1], a[3], a[4], a[6], a[2]]
        elif direction == 'W':
            self._eyes = ['dummy', a[3], a[2], a[6], a[1], a[5], a[4]]
        elif direction == 'E':
            self._eyes = ['dummy', a[4], a[2], a[1], a[6], a[5], a[3]]
        else:
            raise ValueError('NEWS箱推し')


dice1 = Dice(input().split())
dice2 = Dice(input().split())
if dice1 == dice2:
    result = 'Yes'
else:
    result = 'No'
print(result)

Submission status: Accepted

Solution code:
import random


def dice ( a , b , c , d , e , f , l ) :
    if l == "N" :
        return [ b , f , c , d , a , e ]
    if l == "S" :
        return [ e , a , c , d , f , b ]
    if l == "E" :
        return [ d , b , a , f , e , c ]
    if l == "W" :
        return [ c , b , f , a , e , d ]
d = list ( map ( int , input ( ).split ( ) ) )
s = [ "W" , "N" , "E" , "S" ]
a , b , c , g , e , f = map ( int , input ( ).split ( ) )
j = 0
while j <= 10000 :
    k = random.randrange ( 4 )
    d = dice ( d [ 0 ] , d [ 1 ] , d [ 2 ] , d [ 3 ] , d [ 4 ] , d [ 5 ] , s [ k ] )
    if d [ 0 ] == a and d [ 1 ] == b and d [ 2 ] == c and d [ 3 ] == g and d [ 4 ] == e and d [ 5 ] == f :
        print ( "Yes" )
        break
    if j == 10000 :
        print ( "No" )
    j += 1

Submission status: Accepted

Solution code:
import random


class Cube:
    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    u1, s1, e1, w1, n1, d1 = map(int, input().split())
    u2, s2, e2, w2, n2, d2 = map(int, input().split())
    cube1 = Cube(u1, s1, e1, w1, n1, d1)
    cube2 = Cube(u2, s2, e2, w2, n2, d2)

    ret = "No"
    for i in range(10000):
        cube2.rotate(random.choice("NWES"))
        if cube1.u == cube2.u and cube1.n == cube2.n and cube1.w == cube2.w and cube1.e == cube2.e and cube1.s == cube2.s and cube1.d == cube2.d:
            ret = "Yes"
            break
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8
import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}
    way = ("N","E","W","S")

    def __init__(self, data):
        self.label = data

    def move(self, data):
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare(self, dice2):
        ok = False
        for i in range(1000):
            check = True
            for i2 in range(6):
                if self.label[i2] == dice2.label[i2] :
                    continue
                else:
                    check = False
                    break

            if check :
                ok = True
                break
            else:
                self.move(self.way[random.randint(0,3)])
        return ok

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8
import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}
    way = ("N","E","W","S")

    def __init__(self, data):
        self.label = data

    def move(self, data):
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare(self, dice2):
        ok = False
        for i in range(1000):
            check = True
            for i2 in range(6):
                if self.label[i2] == dice2.label[i2] :
                    continue
                else:
                    check = False
                    break

            if check :
                ok = True
                break
            else:
                self.move(self.way[random.randint(0,1)])
        return ok

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8
import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1),'CW':(0,2,4,1,3,5)}

    way = ("N","E","W","S","CW","Nop")

    def __init__(self, data):
        self.label = data

    def move(self, data):
        if data == "Nop":
            return
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare_6sq(self, dice2):
        check = True
        for i in range(6):
            if self.label[i] == dice2.label[i] :
                continue
            else:
                check = False
                break

        return check
    
    def compare_4rot(self, dice2):
        ok = False
        for i in range(4):
            self.move("CW")
            if self.compare_6sq(dice2) :
                ok =True
                break
        return ok
    
    def compare(self,dice2):
        ok = False
        orderway =("Nop","E","N","E","N","E")

        for s in orderway:
            self.move(s)
            if self.compare_4rot(dice2):
                ok = True
                break
        
        return ok





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

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

Submission status: Accepted

Solution code:
from enum import Enum
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]

    def equal(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.equal(diceB):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ 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 _ in range(6):
			self.work[_] = self.number[_]
		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 get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): return(self.number[2])
			elif(n2 == self.number[2]): return(self.number[4])
			elif(n2 == self.number[3]): return(self.number[1])
			elif(n2 == self.number[4]): return(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[0])
                        elif(n2 == self.number[3]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): return(self.number[1])
                        elif(n2 == self.number[1]): return(self.number[5])
                        elif(n2 == self.number[4]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): return(self.number[4])
                        elif(n2 == self.number[1]): return(self.number[0])
                        elif(n2 == self.number[4]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): return(self.number[2])
                        elif(n2 == self.number[2]): return(self.number[5])
                        elif(n2 == self.number[3]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[1])
                        elif(n2 == self.number[3]): return(self.number[4])
                        elif(n2 == self.number[4]): return(self.number[2])

	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
dice1 = Dice()
dice2 = Dice()

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

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

Submission status: Accepted

Solution code:
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

def spin(l):
    '''
    return right sppined list

    l : string list
    '''

    i = -1
    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]

    return res
def has_same_faces(a, b):
    '''
    check if all elements of a are equel to those of b.
    a : string list
    b : string list
    '''
    return set(a) == set(b)

def is_identical_lists(a, b):
    for x, y in zip(a, b):
        if x != y:
            return False

    return True

def check_two_dice(a, b):
    if not has_same_faces(a, b):
        return False
    
    orig_a = a[:]

    #roll and spin to check
    for i in range(6):
        if 1 <= i <= 3:
            a = roll(a, "N")
        elif i == 4:
            pass
            a = orig_a[:]
            a = roll(a, "W")
        elif i == 5:
            a = orig_a[:]
            a = roll(a, "E")

        # spin 4 times
        for _ in range(4): #spin 3 times
            a = spin(a)
            if is_identical_lists(a, b):
                return True
        
    return False


if __name__ == "__main__":
    a_list = input().split()
    b_list = input().split()
    res = check_two_dice(a_list, b_list)  
    print("Yes") if res else print("No")

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

    def isSameDice(self, anotherDice):
        if self.s1 == anotherDice.s1 and \
           self.s2 == anotherDice.s2 and \
           self.s3 == anotherDice.s3 and \
           self.s4 == anotherDice.s4 and \
           self.s5 == anotherDice.s5 and \
           self.s6 == anotherDice.s6:
            return True
        return False


s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice1 = Dice(s1, s2, s3, s4, s5, s6)
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice2 = Dice(s1, s2, s3, s4, s5, s6)

flag = False
for j in range(6):
    if j % 2 == 0:
        dice2.north()
    else:
        dice2.west()

    for k in range(4):
        dice2.rotate()
        if dice2.isSameDice(dice1):
            flag = True
            break
    if flag:
        break

if flag:
    print("Yes")
else:
    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:
IDX_TBL = \
{1:[2,3,5,4],
 2:[3,1,4,6],
 3:[1,2,6,5],
 4:[1,5,6,2],
 5:[1,3,6,4],
 6:[2,4,5,3]}

l1=["-"] + raw_input().split(" ")
l2=["-"] + raw_input().split(" ")

if l1[1] not in l2:
    print "No"
else:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]

    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])

        if nums2 in nums1*2:
            print "Yes"
            break
        else:
            continue
    else:
        print "No"

Submission status: Accepted

Solution code:
import sys

IDX_TBL = {1:[2,3,5,4], 2:[3,1,4,6], 3:[1,2,6,5],
           4:[1,5,6,2], 5:[1,3,6,4], 6:[2,4,5,3]}

l1=["_"] + raw_input().split(" ")
l2=["_"] + raw_input().split(" ")

if l1[1] in l2:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]

    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])
        if nums2 in nums1*2:
            print "Yes"
            sys.exit(0)
print "No"