Problem:


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

Dice IV

 Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

  In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

  Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2 

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes



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


Sample output:
No

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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

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


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

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


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

        return False

n = int(input())
dice = []
for i in range(n):
    tmp_dice = Dice()
    table = list(map(int,input().split()))
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    dice.append(tmp_dice)

FLG = True
for i in range(n-1):
    for j in range(i+1, n):
        if dice[i].equals(dice[j]):
            FLG = False
            break

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

Submission status: Accepted

Solution code:
import sys
import math


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

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

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


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

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


    def query(self,top_num,front_num):

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

        ret = -1

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

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

        return ret

    def equals(self,another):

        ret = False

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

        return ret

num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


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

Submission status: Accepted

Solution code:
n = int(input())
d = [input().split() for i in range(n)]
# print(d)
# dice1 = input().split()
# dice2 = input().split()
# dice3 = input().split()

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

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

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


def check(a, b):
    # print(a, b)
    isMatch = equals(a, b)
    
    
    looping = True
    for j in range(4):
        #print(dice1)
        if isMatch:
            break
        for i in range(4):
            # print(a)
            rotate(a, "N")
            if equals(a, b):
                isMatch = True
                break
        #print('----')
        #print(dice1)
        rotate(a, "W")
        #print(dice1)
    
    # print('---- ---- ----')
    #print(copy_list)
    # print('---- ---- ----')
    
    rotate(a, "NW")
    
    for j in range(4):
        #print(dice1)
        if isMatch:
            break
        for i in range(4):
            #print(dice1)
            rotate(a, "N")
            if equals(a, b):
                isMatch = True
                break
        #print('----')
        #print(dice1)
        rotate(a, "W")
        #print(dice1)
    
    return isMatch
    

result = True
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        
        if (check(d[i], d[j])):
            result = False

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

Submission status: Accepted

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

n = int(input())
dlst = []
for i in range(n):
    dice1 = dice(input().split())
    if i >= 1:
        for d in dlst:
            if dice1.isSame(d):
                print("No")
                sys.exit()
    dlst.append(dice1)
print("Yes")

Submission status: Accepted

Solution code:

from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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

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


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

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


    def 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



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


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

Submission status: Accepted

Solution code:
import sys

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

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

n = int(input())
DiseList = [Dise(input().split()) for i in range(n)]
for x in range(n-1):
    for y in range(x+1,n):
        Dise1 = DiseList[x]
        Dise2 = DiseList[y]
        step1()

print("Yes")

Submission status: Accepted

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

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

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

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

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

is_eql = False
n = int(input())
init_states = []

for i in range(n):
  init_states.append(input().split())

try:
  for i in range(0, n):
    for j in range(i + 1, n):
      dice1 = Dice(init_states[i])
      dice2 = Dice(init_states[j])
  
      for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
        if c == 'N':
          dice2.north()
        elif c == 'S':
          dice2.south()
        elif c == 'W':
          dice2.west()
        elif c == 'E':
          dice2.east()
        if dice1.state == dice2.state:
          is_eql = True
          raise Exception
except Exception:
  pass

print('No' if is_eql else 'Yes')

Submission status: Accepted

Solution code:
import random

class  Dise:
    def __init__(self,top,flont,right,left,back,bottom):
        self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom
        self.order='NNNNWNNNWNNNENNNENNNWNN'
    def rot(self,d):
        if d=='N':
            self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top
        elif d=='E':
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        elif d=='S':
                self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom
        elif d=='W':
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
    
    def gettop(self):
        return self.top
    def getfront(self):
        return self.flont
    def getright(self):
        return self.right
    def getleft(self):
        return self.left
    def getback(self):
        return self.back
    def getbottom(self):
        return self.bottom
    
    def equals(self,another):
        for i in range(len(self.order)):
            self.rot(self.order[i])
            flag=0
            if dise1.gettop()==dise2.gettop() and dise1.getfront()==dise2.getfront() and dise1.getright()==dise2.getright() and dise1.getleft()==dise2.getleft() and dise1.getback()==dise2.getback() and dise1.getbottom()==dise2.getbottom():
                flag=1
                break
        if flag==1:
            return 1
        else:
            return 0

n=int(input())
A=[[0*6]for i in range(n)]
for i in range(n):
    A[i]=list(map(int,input().split()))
    
flag=1
for i in range(n):
    for j in range(i+1,n):
        dise1=Dise(A[i][0],A[i][1],A[i][2],A[i][3],A[i][4],A[i][5])
        dise2=Dise(A[j][0],A[j][1],A[j][2],A[j][3],A[j][4],A[j][5])
        if dise1.equals(dise2)==1:
            flag=0
            break
if flag==1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

n = int(input())
Dices = [Dice(0 for x in range(6)) for y in range(n)]
for ni in range(n):
 label = list(map(int, input().split() ))
 Dices[ni] = Dice(label)
bAllDiff = True
for no in range(n-1):
 D = Dices[no]
 for ni in range(no+1,n):
  E = Dices[ni]
  # outer loop: put all 6 faces to the top to check
  bChecked = False
  sMove = 'NNNEEE'
  for mi in range(len(sMove)+1):
   if D.gettop() == E.gettop() and D.getbottom() == E.getbottom():
    sRot = 'CCCC'
    for ri in range(len(sRot)):
     if D.getnorth() == E.getnorth() and D.geteast() == E.geteast() and D.getsouth() == E.getsouth() and D.getwest() == E.getwest():
      bChecked = True
      bAllDiff = False
      #print(no,ni,'Same')
      break
     if ri<len(sRot):
      E.move(sRot[ri])
   if bChecked:
    break
   if mi<len(sMove):
    E.move(sMove[mi])
  #if not bChecked:
  #print(no,ni,'Diff')
if bAllDiff:
 print('Yes')
else:
 print('No')

Submission status: Accepted

Solution code:
#アルゴリズム関数-サイコロを回転させる
def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1

#アルゴリズム関数-上面・前面の番号を指定番号へサイコロを回転させる
def dice_find(list1, int1, int2):
    try:
        position_numnber = list1.index(int2)
    except:
        position_numnber = -1
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    try:
        position_numnber = list1.index(int1)
    except:
        position_numnber = -1
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1

#アルゴリズム関数-サイコロの内容が
def list_overlapping_check(list1):
    result = True
    for i in range(1, len(list1)):
        list1[i] = dice_find(list1[i], list1[0][0], list1[0][1])
        if list1[0] == list1[i]:
            result = False
            break
    if result == True and len(list1) > 2:
        result = list_overlapping_check(list1[1:])
    return result

#インプットdataの格納
input_count = int(input())
check_data = list()
for i in range(input_count):
    check_data.append(list(map(int, input().split())))

#結果表示
if list_overlapping_check(check_data) == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, x):
        self.top = x[0]
        self.front = x[1]
        self.right = x[2]
        self.left = x[3]
        self.back = x[4]
        self.bottom = x[5]
        self.list = x

    def N(self):
        self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top

    def E(self):
        self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom

    def S(self):
        self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom

    def W(self):
        self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top

    def up_front_to_right(self, top, front):
        if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]:
            return self.right
        elif (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]:
            return self.left
        elif (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]:
            return self.top
        elif (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]:
            return self.bottom
        elif (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]:
            return self.front
        elif (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]:
            return self.back
        else:
            return -1

    def inverse(self, a):
        if a == self.top:
            return self.bottom
        elif a == self.front:
            return self.back
        elif a == self.right:
            return self.left
        elif a == self.left:
            return self.right
        elif a == self.back:
            return self.front
        elif a == self.front:
            return self.back
        else:
            return -1


def same(dice0, dice1):
    x = dice0.list
    for i in range(6):
        for j in range(i + 1, 6):
            if x[i] != dice0.inverse(x[j]):
                a = dice0.up_front_to_right(x[i], x[j])
                b = dice1.up_front_to_right(x[i], x[j])
                if a != b:
                    return False
    return True


n = int(input())
X = []
for i in range(n):
    *x, = map(int, input().split())
    X.append(Dice(x))
for i in range(n):
    for j in range(i + 1, n):
        if same(X[i], X[j]):
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
import os


N = int(input())
dices = []
for i in range(N):
    dice = list(map(int, input().split()))
    dices.append(dice)

def dice_roll(dice, c):
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
    # Y???????????¢
    elif c == 'R':
        dice[2] = copy[1]
        dice[4] = copy[2]
        dice[3] = copy[4]
        dice[1] = copy[3]
    return dice


def check(dice0_input, dice1_input):
    # ??????????????¶?????????????????????????????????copy?????±???
    dice0 = dice0_input[:]
    dice1 = dice1_input[:]

    # up???????????????
    num = 0
    while dice0[0] != dice1[0]:
        if num % 2 == 0:
            dice0 = dice_roll(dice0, 'E')
        else:
            dice0 = dice_roll(dice0, 'N')
        num += 1
        if num > 10:
            return False

    # front???????????????
    num = 0
    while dice0[1] != dice1[1]:
        dice0 = dice_roll(dice0, 'R')
        num += 1
        if num > 10:
            return False

    if dice0[2] == dice1[2] and dice0[3] == dice1[3] and dice0[4] == dice1[4] and dice0[5] == dice1[5]:
        return True
    else:
        return False


def check2(dice0, dice1):
    # ?????¨????????¢???????????????6????????§????????????
    for i in range(6):
        result = check(dice0, dice1)
        if result:
            return True
        else:
            if i % 2 == 0:
                dice0 = dice_roll(dice0, 'N')
            else:
                dice0 = dice_roll(dice0, 'E')
    return False

for i in range(N):
    for j in range(i+1, N):
        is_same = check2(dices[i], dices[j])
        if is_same:
            print('No')
            quit()
print('Yes')

Submission status: Accepted

Solution code:
import math

class Dice():
    top   = 0 #上
    left  = 0 #左
    right = 0 #右
    front = 0 #前面
    back  = 0 #後面
    below = 0 #真下

    DEBUG_MODE = False
    def __init__(self,lst,dbg = False):
        if len(lst) == 6:
            self.top   = lst[0]
            self.front = lst[1]
            self.right = lst[2]
            self.left  = lst[3]
            self.back  = lst[4]
            self.below = lst[5]

        if dbg == True:
            self.DEBUG_MODE = True
        else:
            self.DEBUG_MODE = False
    
    def __repr__(self):
        return f"<<Dice: bk:{self.back} le:{self.left} tp:{self.top} ri:{self.right} be:{self.below} fr:{self.front}>>"

    def rotate(self,string):
        
        for ch in string:
            if   ch == 'W':
                self.left,self.top,self.right,self.below = self.top,self.right,self.below,self.left

            elif ch == 'E':
                self.left,self.top,self.right,self.below = self.below,self.left,self.top,self.right

            elif ch == 'S':
                self.top,self.back,self.below,self.front = self.back,self.below,self.front,self.top

            elif ch == 'N':
                self.top,self.back,self.below,self.front = self.front,self.top,self.back,self.below
            
            # デバッグモードなら全部の値をモニタする
            if self.DEBUG_MODE:
                self.dbg_PRINT_ALL_VALUE()

    def front_and_top_to_right(self,top,front):

        for i in range(4):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") #ヨコ回転
        
        for i in range(2):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("SS")
        
        return None

    def equals(self,dice):
        if not isinstance(dice,Dice):
            return False

        for i in range(4):
            for j in range(4):
                if self.__non_rotate_equals(dice):
                    return True
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") #ヨコ回転
        
        for i in range(2):
            for j in range(4):
                if self.__non_rotate_equals(dice):
                    return True
                self.rotate("W")
            self.rotate("SS")
        
        return False

    def __non_rotate_equals(self,dice):
        if (self.top   == dice.top   and
            self.left  == dice.left  and
            self.right == dice.right and
            self.front == dice.front and
            self.back  == dice.back  and
            self.below == dice.below ) :
            return True
        
        return False
        
    def get_topvalue(self):
        return self.top
    
    def dbg_PRINT_ALL_VALUE(self):
        print(f"        bk:{self.back:04} ")
        print(f"le:{self.left:04} tp:{self.top:04} ri:{self.right:04} be:{self.below:04}")
        print(f"        fr:{self.front:04} ")

# 実コードはここに書く
rep = int(input())
lst = [list(map(int,input().split())) for i in range(rep)]
dicelist = [Dice(lst[i]) for i in range(rep)]

is_not_same = True
for i in range(rep):
    for j in range(i+1,rep):
        if dicelist[i].equals(dicelist[j]):
            is_not_same = False

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

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
    def output(self):
        return self.dice
    def move(self, direction):
        for _ in direction: self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

N, A = int(input()), []
for _ in range(N): A.append(Dice([int(x) for x in input().split()]))

Dir, Flag = 'NSEW', 0

for i in range(N):
    for j in range(i+1, N):
        for _ in range(100):
            A[i].move(Dir[random.randint(0,3)])
            if A[i].output() == A[j].output():
                Flag = 1
                break

print('No') if Flag else print('Yes')