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:
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice

def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice

def judge(dice1, dice2):
  flag = True
  for i in range(6):
    if dice1[i] != dice2[i]:
      flag = False
      break
  return flag

import sys

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

mvdice = dice2
cnt = 0

while True:
  mvdice = move(mvdice, "E")
  cnt += 1
  if dice1[0] == mvdice[0]:
    rolldice = mvdice
    cntroll = 0
    while True:
      rolldice = roll(rolldice)
      cntroll += 1
      if judge(dice1, rolldice) == True:
        print("Yes")
        sys.exit()
      if cntroll == 4:
        break
  if cnt == 4:
    break

mvdice = dice2
cnt = 0
    
while True:
  mvdice = move(mvdice, "N")
  cnt += 1
  if dice1[0] == mvdice[0]:
    rolldice = mvdice
    cntroll = 0
    while True:
      rolldice = roll(rolldice)
      cntroll += 1
      if judge(dice1, rolldice) == True:
        print("Yes")
        sys.exit()
      if cntroll == 4:
        break
  if cnt == 4:
    break

print("No")

Submission status: Accepted

Solution code:
class Dice():
  def __init__ (self):
    # 1:ue 2:syomen 3:migi 4:hidari 5:oku 6:shita
    self.position = [0,0,0,0,0,0]
    self.search_result = []
  
  def setNumber (self, num):
    for i,x in enumerate(num):
      self.position[i] = x
    #print(self.position)
      
  def roll(self, roll):
    for i in range(len(roll)):
      s = roll[i:i+1]
      p = self.position
      if s == 'E':
        self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]])
      elif s == 'W':
        self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]])
      elif s == 'S':
        self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]])
      elif s == 'N':
        self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]])
      elif s == 'R':
        self.setNumber([p[0], p[2], p[4], p[1], p[3], p[5]])
      elif s == 'L':
        self.setNumber([p[0], p[3], p[1], p[4], p[4], p[5]])

  def printTop(self):
    print(self.position[0])

  def searchRight(self, a, b):
    i1 = self.position.index(a)
    i2 = self.position.index(b)
    #print("i1:" + str(i1) + " i2:" + str(i2) )
    
    # 0
    if (i1 == 1 and i2 == 2) or (i1 == 2 and i2 == 4) or (i1 == 4 and i2 == 3) or (i1 == 3 and i2 == 1):
      self.search_result.append(self.position[0])
    # 1
    elif (i1 == 0 and i2 == 3) or (i1 == 3 and i2 == 5) or (i1 == 5 and i2 == 2) or (i1 == 2 and i2 == 0):
      self.search_result.append(self.position[1])
    # 2
    elif (i1 == 0 and i2 == 1) or (i1 == 1 and i2 == 5) or (i1 == 5 and i2 == 4) or (i1 == 4 and i2 == 0):
      self.search_result.append(self.position[2])
    # 3
    elif (i1 == 1 and i2 == 0) or (i1 == 0 and i2 == 4) or (i1 == 4 and i2 == 5) or (i1 == 5 and i2 == 1):
      self.search_result.append(self.position[3])
    # 4
    elif (i1 == 0 and i2 == 2) or (i1 == 2 and i2 == 5) or (i1 == 5 and i2 == 3) or (i1 == 3 and i2 == 0):
      self.search_result.append(self.position[4])
    # 5
    elif (i1 == 2 and i2 == 1) or (i1 == 1 and i2 == 3) or (i1 == 3 and i2 == 4) or (i1 == 4 and i2 == 2):
      self.search_result.append(self.position[5])
    
  def printResult(self):
    for i in self.search_result:
      print (i)
  
  def isSame(self, d):
    for r in ["", "R", "R", "R", 
              "RE",  "R", "R", "R",
              "RE",  "R", "R", "R",
              "RE",  "R", "R", "R",
              "RS",  "R", "R", "R",
              "RNN", "R", "R", "R"]:
      self.roll(r)
      #print(self.position)
      if self.position == d.position:
        print("Yes")
        return
    print("No")
    


d1 = Dice()
d2 = Dice()

n = list(int(x) for x in input().split())
d1.setNumber(n)

n = list(int(x) for x in input().split())
d2.setNumber(n)

d1.isSame(d2)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == 0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.right, self.front, self.bottom, self.top, self.back, self.left
        
        if i == 1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.left, self.front, self.top, self.bottom, self.back, self.right
        
        if i == 2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.back, self.top, self.right, self.left, self.bottom, self.front
            
        if i == 3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.front, self.bottom, self.right, self.left, self.top, self.back

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

def CheckData(data,top,front):
    for i in range(len(data)):
        if(data[i][0] == top and data[i][1] == front):
            print(data[i][2])
            break
            
def CheckDice(data1,data2):
    if(data1 == data2):
        print("Yes")
        
    else:
        print("No")

def MakeData(dice):
    num_data = 4 * 6 -1
    
    dataset = list()
    data = [dice.top, dice.front, dice.right]

    dataset.append(data)
    
    isOnly = True
    
    n = 0
    while 0 < num_data:
        n += 1
        if (n > 1000):break
        data = [dice.top, dice.front, dice.right]

        isOnly = True
        for i in range (len(dataset)):
            if(data == dataset[i]):
                isOnly = False
                break
        if isOnly == True:
            dataset.append(data)
            dataset.sort()
            num_data -= 1
        
        dice.Roll(int(random.random() * 4))
    return dataset

import random

my_label1 = [int(x) for x in input().split(" ")]
my_label2 = [int(x) for x in input().split(" ")]

dice1 = Dice(my_label1)
dice2 = Dice(my_label2)

data1 = MakeData(dice1)
data2 = MakeData(dice2)

CheckDice(data1,data2)

Submission status: Accepted

Solution code:
import random

class dice:
    def __init__(self, t, S, E):
        self.dice = list(map(int, input().split()))
        self.t = t
        self.S = S
        self.E = E
        self.now_dice()
    
    def roll(self, order):
        if order == 'E':
            self.t, self.E = self.W, self.t
        elif order == 'N':
            self.t, self.S = self.S, self.g
        elif order == 'S':
            self.t, self.S = self.N, self.t
        elif order == 'W':
            self.t, self.E = self.E, self.g
        self.now_dice()
    
    def now_dice(self):
        self.N = 7 - self.S
        self.g = 7 - self.t
        self.W = 7 - self.E
        self.now = [self.t, self.S, self.E, self.N, self.W, self.g]
        return self.now

if __name__ == '__main__':
    dice_1 = dice(1, 2, 3)
    dice_2 = dice(1, 2, 3)
    loop = ['N', 'N', 'N', 'E']*4
    loop_2 = ['E']*5
    p = 0
    ans = 0
    for v in loop:
        dice_1.roll(v)
        if dice_1.dice[dice_1.S-1] == dice_2.dice[dice_2.S-1]:
            for v in loop_2:
                dice_1.roll(v)
                p = 0
                for i in range(6):
                    if dice_1.dice[dice_1.now[i]-1] != dice_2.dice[dice_2.now[i]-1]:
                        break
                    p += 1
                    if p >= 6:
                        ans += 1
    if ans:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def sgn(a, b):
    return int(a*b/abs(a*b))

class Dice:
    def __init__(self, numbers):
        self.numbers_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1:numbers[5]}
        self.numbers_ver_dict = {numbers[0]:1, numbers[1]:2,numbers[2]:3,numbers[3]:-3, numbers[4]:-2,numbers[5]:-1}

    # a:top, b:front
    def show_right(self, a, b):
        var_a = self.numbers_ver_dict[a]
        var_b = self.numbers_ver_dict[b]
        if abs(var_a) == 1:
            if abs(var_b) == 2:
                return self.numbers_dict[sgn(var_a,var_b)*3]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)*2]
        elif abs(var_a) == 2:
            if abs(var_b) == 1:
                return self.numbers_dict[-sgn(var_a, var_b)*3]
            else:
                return self.numbers_dict[sgn(var_a,var_b)]
        else:
            if abs(var_b) == 1:
                return self.numbers_dict[sgn(var_a, var_b)*2]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)]

if __name__ == '__main__':
    examin_list = list(map(int, input().split()))
    dice1 = Dice(examin_list)
    dice2 = Dice(list(map(int, input().split())))
    yes_flag = True
    exam_tuple = ((examin_list[0], examin_list[1]), (examin_list[0], examin_list[2]), (examin_list[0], examin_list[4]),
                  (examin_list[0], examin_list[3]), (examin_list[1], examin_list[5]))
    for num in exam_tuple:
        if dice1.show_right(num[0], num[1]) != dice2.show_right(num[0], num[1]):
            print('No')
            yes_flag = False
            break
    if yes_flag:
        print('Yes')

Submission status: Accepted

Solution code:
def f():
	a = input().split()
	b = input().split()
	for i,s in enumerate(((3,1,2,4),(2,0,3,5),(4,0,1,5),(1,0,4,5),(3,0,2,5),(2,1,3,4))):
		for j in range(4):
			r = s[j:] + s[:j]
			if [a[k] for k in (i, r[1], r[2], r[0], r[3], 5-i)] == b:
				print('Yes')
				return
	print('No')
f()

Submission status: Accepted

Solution code:
buff = "NNNNWNNNWNNNENNNENNNWNNN"

class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                #print(self.num[m])
                return self.num[m]
        
        def return_lst(self):
                return self.num

def isSameDice(D1, D2):
        for d in buff:
                D1.roll(d)
                if D1.return_lst() == D2.return_lst():
                        return True
        return False

lst = [ int(i) for i in input().split() ]
D1 = Dice(lst)

lst = [ int(i) for i in input().split() ]
D2 = Dice(lst)

if isSameDice(D1, D2):
        print("Yes")
else:
        print("No")

Submission status: Accepted

Solution code:
d1=input().split()
d2=input().split()
m=[[1,2,4,3,1],[5,2,0,3,5],[5,4,0,1,5],[5,1,0,4,5],[5,3,0,2,5],[4,2,1,3,4]]
ans='No'

if sorted(d1)==sorted(d2):
    if len(set(d1))>=4:
        for i in range(3):
            if d1[5-i]==d2[5-d2.index(d1[i])]:
                mae,migi=[d1[m[i][s]] for s in range(2)]
                for j in range(4):
                    if mae==d2[m[d2.index(d1[i])][j]] and migi==d2[m[d2.index(d1[i])][j+1]]:
                        ans='Yes'
                        break
            else:
                ans='No'
                break
    else:
        ans='Yes'

print(ans)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, labels):
        self.labels = labels
        
    def __str__(self):
        return str(self.labels[0])
    
    def roll_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]
            
    def roll_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 roll_west(self):
        self.labels[0], self.labels[3], self.labels[5], self.labels[2] = self.labels[2], self.labels[0], self.labels[3], self.labels[5]
    
    def roll_north(self):
        self.labels[0], self.labels[4], self.labels[5], self.labels[1] = self.labels[1], self.labels[0], self.labels[4], self.labels[5]
        
    def get_faces(self):
        return self.labels
        
def main():
    labels0 = list(map(int, input().split()))
    labels = list(map(int, input().split()))
    d = Dice(labels)
    
    d0 = Dice(labels0)
    f = labels0[0]
    for i in labels0:
        if labels0.count(i) < labels0.count(f):
            f = i
    ind = labels0.count(f)
    if ind == 1:
        d0.roll_north()
    elif ind == 4:
        d0.roll_south()
    else:
        while d0.get_faces()[0] != f:
            d.roll_east()
    labels0 = d0.get_faces()
    

    ind0 = labels.index(labels0[0])
    ind1 = labels.index(labels0[1])
    if ind0 == 1:
        d.roll_north()
    elif ind0 == 4:
        d.roll_south()
    else:
        while d.get_faces()[0] != labels0[0]:
            d.roll_east()
    while d.get_faces()[1] != labels0[1]:
        d.roll_east()
        d.roll_south()
        d.roll_west()
    for i in range(2,6):
        if d.get_faces()[i] != labels0[i]:
            print('No')
            return
    print('Yes')
    return
            
main()

Submission status: Accepted

Solution code:
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 set(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 kaiten(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.set(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.set(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.set(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.set(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def tansaku(self,top_num,front_num):
 
        self.save = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save[i] = self.number[i]
 
        ret = -1;
 
        for i in range(len(self.order)):
            self.kaiten(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[i]
 
        return ret;
 
    def hyouka(self,b):
        for i in range(len(self.order)):
            self.kaiten(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != b.number[k]: 
                    FLG = False
                    break
            if FLG == True:
                return True
        
        return False
        
 
 
A = Dice()
B = Dice()

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

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

if A.hyouka(B):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice():

    patterns = {"N":[1,5,2,3,0,4],"S":[4,0,2,3,5,1],"W":[2,1,5,0,4,3],"E":[3,1,0,5,4,2]}

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

    #0->上、1->正面、2->右面、3->左面、4->裏面、5->下面
    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,command,int):
        for i in command:
            self.number = [self.number[j] for j in self.patterns[i]]
        return self.number[int]


dice = Dice()

###d1を基準として、d2の目を合わせる
d1 = list(map(int,input().split()))
d2 = list(map(int,input().split()))

dice.setNumber(d2[0],d2[1],d2[2],d2[3],d2[4],d2[5])

command1 = ["S","S","S","S","E","E","E"] #topを一致させるための回転
command2 = ["S","E","N","S","E","N","S","E","N","S","E","N"] #frontを一致させるための回転

chk = False
for i in command1:
    if d1[0] == dice.roll(i,0):
        for j in command2:
            if d1[1] == dice.roll(j,1):
                if d1[2] == dice.number[2] and d1[3] == dice.number[3] and d1[4] == dice.number[4] and d1[5] == dice.number[5]:
                    chk = True
                else:chk = False
            else:continue
    else:continue

if chk == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = ['402351', '152304', '310542', '215043']   
t = []
t.append(a)
i = 0; j = 0
while True:
    if t[i][0] == b[0] and t[i][1] == b[1]:
        ans = "Yes" if t[i][2] == b[2] and t[i][3] == b[3] else "No"
        print(ans)
        break
    if i == len(t)-1: # add if it finishes searching all path
        for h in range(len(s)):
            t.append([ t[j][int(k)] for k in list(s[h]) ])
        j+=1
    i+=1

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

surfaceNum1 = [int(i) for i in input().split()]
surfaceNum2 = [int(i) for i in input().split()]
rollCommandList = ["E", "W", "S", "N"]
dice1 = Dice(surfaceNum1)
dice2 = Dice(surfaceNum2)
counter = 0
    
while True:
    counter += 1
    rollCommand = random.choice(rollCommandList)
    if rollCommand == "E":
        dice2.east()
    if rollCommand == "W":
        dice2.west()
    if rollCommand == "S":
        dice2.south()
    if rollCommand == "N":
        dice2.north()
    if counter == 10000:
        print('No')
        break
        
    if dice1.surface == dice2.surface:
        print('Yes')
        break

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]

    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True



p1 = [ int(n) for n in input().split()]
p2 = [ int(n) for n in input().split()]

dice1 = Dice(p1)
dice2 = Dice(p2)


print('Yes' if dice1.same(dice2) else 'No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True

p1 = [ int(n) for n in input().split()]
p2 = [ int(n) for n in input().split()]

dice1 = Dice(p1)
dice2 = Dice(p2)

print('Yes' if dice1.same(dice2) else 'No')

Submission status: Accepted

Solution code:
n1 = list(map(int,input().split()))
n2 = list(map(int,input().split()))
a = "No"
for i in range(6):
    for j in range(4):
        n1 = [n1[0],n1[3],n1[1],n1[4],n1[2],n1[5]]
        if n1 == n2:
            a = "Yes"
    if i % 2 == 0:
        n1 = [n1[4],n1[0],n1[2],n1[3],n1[5],n1[1]]
    else:
        n1 = [n1[2],n1[1],n1[5],n1[0],n1[4],n1[3]]
print(a)

Submission status: Accepted

Solution code:

class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N(self):
        ls = self.S().S().S().ls
        return Dice(ls)
        
    def E(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W(self):
        ls = self.E().E().E().ls
        return Dice(ls)
        
        
        
    def R_rot(self):
        return self.E().S().W()
        
    def rot(self, num):
        for _ in range(num):
            self = self.R_rot()
        return self
    
        
ls = list(map(int, input().split()))
LS = list(map(int, input().split()))

a = Dice(ls)
b = Dice(LS)
#print(a.ls)
#print(b.ls)

me = [a, a.N(), a.W(), a.E(), a.S(), a.S().S()]

judge = False
for i in me:
    for j in range(4):
        #print(i.rot(j).ls)
        if i.rot(j).ls == b.ls:
            judge = True

if judge == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# coding: utf-8
import copy
class Dice:
    
    def __init__(self, d):
        self.data = {"bottom":d[5], "north":d[4], "west": d[3],
                    "east":d[2],"south":d[1],"top":d[0]}

    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self, directions):
        for direction in directions:
            self.moveOne(direction)
            
    def setDiceII(self, a, b):
        if self.data["east"] == a:
            self.moveOne("W")
        elif self.data["north"] == a:
            self.moveOne("S")
        elif self.data["west"] == a:
            self.moveOne("E")
        elif self.data["south"] == a:
            self.moveOne("N")
        elif self.data["bottom"] == a:
            self.movePart("WW")

        if self.data["north"] == b:
            self.rotateRight()
            self.rotateRight()
        elif self.data["east"] == b:
            self.rotateRight()
        elif self.data["west"] == b:
            self.rotateLeft()
            
        # self.printDice()
    
    def rotateRight(self):
        temp = self.data["east"]
        self.data["east"] = self.data["north"]
        self.data["north"] = self.data["west"]
        self.data["west"] = self.data["south"]
        self.data["south"] = temp
    
    def rotateLeft(self):
        temp = self.data["west"]
        self.data["west"] = self.data["north"]
        self.data["north"] = self.data["east"]
        self.data["east"] = self.data["south"]
        self.data["south"] = temp
      
    def getSurface(self):
        return self.data["top"]
    
    def getEast(self):
        return self.data["east"]
    
    def getData(self):
        return self.data
    
    def getPatterns(self):
        patterns = []
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.rotateRight()
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        return patterns
                

    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])

num1 = list(map(int,input().rstrip().split()))
num2 = list(map(int,input().rstrip().split()))
dice1 = Dice(num1)
dice2 = Dice(num2)
flag = False
for i in dice2.getPatterns():
    if dice1.getData()==i:
        print("Yes")
        flag = True
        break;
if not flag:
    print("No")