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:
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):
    if sorted(dice1) != sorted(dice2):
        return False
    
    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

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')

Submission status: Accepted

Solution code:
import sys

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

    def __init__(self):
        self.number = [i for i in range(6)]  #[0, 1, 2, 3, 4, 5]
        self.work = [i for i in range(6)]

    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 equal(self, dice):  # 自分と引数のサイコロが同一か判定
        directions = "EEEENEEEENEEEENEEEEWSEEEESSEEEE"  # サイコロの向きの全通りを試すための転がす命令（余分な転がしも含む）
        for d in directions:
            self.roll(d)
            for i in range(6):
                if self.number[i] != dice.number[i]:
                    break
                if i == 5:
                    return True
        return False

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

for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].equal(dice_list[j]):  # 同じのが見つかった
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
import itertools


class Dice(object):
    def __init__(self, faces: list):
        self.list_sn = [faces[5], faces[4], faces[0], faces[1]]  # 6,5,1,2
        self.list_we = [faces[5], faces[2], faces[0], faces[3]]  # 6,5,1,2

    def _roll_positive(self, list_a: list, list_b: list) -> list:
        list_a = list_a[1:] + list_a[0:1]  # Roll one unit in the positive direction.
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def _roll_negative(self, list_a: list, list_b: list) -> list:
        list_a = list_a[3:] + list_a[0:3]
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def roll(self, direction: str):
        if "N" == direction:
            self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we)
        elif "S" == direction:
            self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we)
        elif "E" == direction:
            self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn)
        else:
            self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn)


if __name__ == "__main__":
    dice_num = int(input())
    dice_list = [
        Dice(list(map(lambda x: int(x), input().split()))) for _ in range(dice_num)
    ]

    for Dice_a, Dice_b in itertools.combinations(dice_list, 2):
        for command in "NNNNWNNNWNNNENNNENNNWNNN":  # Check all patterns.
            Dice_b.roll(command)
            if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we:
                print("No")  # Some pair is identical.
                sys.exit()
    print("Yes")  # All dices are different.

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



#ダイスオブジェクト#############################################################
class dice():
    
    def __init__(self,a,b,c,d,e,f):
        self.A=[a,b,c,d,e,f]
#判定オブジェクト###############################################################
class determine():

    def __init__(self,P,Q):
        self.P=P
        self.Q=Q
    def run(self):
        global point 
        if (self.P.A[0]==self.Q.A[0] and self.P.A[5]==self.Q.A[5]):

            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            else:
                pass
        elif (self.P.A[0]==self.Q.A[1] and self.P.A[5]==self.Q.A[4]):
            if self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            else:
                pass

        elif (self.P.A[0]==self.Q.A[2]and self.P.A[5]==self.Q.A[3]):
            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            else:
                pass

        elif (self.P.A[0]==self.Q.A[3] and self.P.A[5]==self.Q.A[2]):
            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            else:
                pass

        elif (self.P.A[0]==self.Q.A[4] and self.P.A[5]==self.Q.A[1]):
            if self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            else:
                pass


        elif (self.P.A[0]==self.Q.A[5] and self.P.A[5]==self.Q.A[0]):
            if self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            else:
               pass
        else:
            pass
     
##実行部分######################################################################
if __name__=="__main__":
    
    #入力用関数の定義##########################################
    def in_data():
       input_text=""
       input_text=input()
       array=[]
       array=input_text.split()
       return array
    
    def in_number():
        input_n=""
        input_n=input()
        input_n=int(input_n)
        return input_n
    ###########################################################
    ###ダイスの目の入力
    
    point=0
    ob_array=[]
    i=0
    j=0
    n=in_number()
    for i in range(n):

        number=in_data()
        #一つ目のダイス
        ob_array.append(dice( number[0], number[1], number[2], number[3], number[4], number[5]))

    for i in range(n):

        for j in range(len(ob_array)):
        ##同一かどうかの判定
            if not i==j:
                det=determine(ob_array[i],ob_array[j])
                det.run()

if point==0:
    print("Yes")
else:
    print("No")
    
#################################################################################

Submission status: Accepted

Solution code:
import random
def dice_move(a,s):
    if s=="E":
        return [a[3],a[1],a[0],a[5],a[4],a[2]]
    elif s=="S":
        return [a[4],a[0],a[2],a[3],a[5],a[1]]
    elif s=="W":
        return [a[2],a[1],a[5],a[0],a[4],a[3]]
    elif s=="N":
        return [a[1],a[5],a[2],a[3],a[0],a[4]]
    
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
h=("N","W","S","E")
judge=[True]*n
cnt=0
for i in range(30000):
    num=random.randrange(4)
    a[0]=dice_move(a[0],h[num])
    for i in range(1,n):
        if judge[i] and a[0]==a[i]:
            cnt+=1
            judge[i]=False
print("Yes" if cnt==0 else "No")

Submission status: Accepted

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

class Dice:
    def __init__(self, num):
        self.num = num
        
    def roll(self, direction):
        """ 転がす処理 """
        data = []
        new_num = []
        if direction == "N":
            data = [1, 5, 2, 3, 0, 4]
        elif direction == "S":
            data = [4, 0, 2, 3, 5, 1]
        elif direction == "E":
            data = [3, 1, 0, 5, 4, 2]
        elif direction == "W":
            data = [2, 1, 5, 0, 4, 3]
        elif direction == "L":
            data = [0, 2, 4, 1, 3, 5]
        elif direction == "R":
            data = [0, 3, 1, 4, 2, 5]

        for i in data:
            new_num.append(self.num[i])
        self.num = new_num
        
def dice_roll1(dice, dice_tf):
    dice_roll = ""
    top = dice_tf[0]
    
    if dice.num.index(top) == 1:
        dice_roll = "N"
    elif dice.num.index(top) == 2:
        dice_roll = "W"
    elif dice.num.index(top) == 3:
        dice_roll = "E"
    elif dice.num.index(top) == 4:
        dice_roll = "S"
    elif dice.num.index(top) == 5:
        dice_roll = "NN"
        
    return dice_roll

def dice_roll2(dice, dice_tf):
    dice_roll = ""
    front = dice_tf[1]

    if dice.num.index(front) == 2:
        dice_roll = "L"
    elif dice.num.index(front) == 3:
        dice_roll = "R"
    elif dice.num.index(front) == 4:
        dice_roll = "LL"
        
    return dice_roll

dice_list = []
n = int(input())

for _ in range(n):
    dice_list.append(Dice(list(map(int, input().split()))))

dice_tf = dice_list[0].num[:2]
is_same = True
for i in dice_list[1:]:
    """ 構成が違ったら位置の判定を飛ばす """
    if set(dice_list[0].num) != set(i.num):
        continue
    direction = dice_roll1(i, dice_tf)
    for j in direction:
        i.roll(j)
    direction = dice_roll2(i, dice_tf)
    for j in direction:
        i.roll(j) 
    if i.num == dice_list[0].num:
        is_same = False
        break
if is_same == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
houkou={'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)}
moji="SSSSEEEENEEEENEEEENEEEENWSSSSWSSSSWSSSSWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWN:"
answer=0

n=int(input())
S=[0]*n
for i in range(n):
  S[i]=list(map(int,input().split()))
  
for i in range(n):
  for j in range(i+1,n):
    for k in range(len(moji)):
      if moji[k]==":":
        answer+=0
        break
      if S[j]==S[i]:
        answer+=1
        break
      S[j]=[S[j][l]for l in houkou[moji[k]]]
if answer==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from sys import exit

def rotate(l, d):
    if d == 'S':
        return [l[4], l[0], l[2], l[3], l[5], l[1]]
    if d == 'N':
        return [l[1], l[5], l[2], l[3], l[0], l[4]]
    if d == 'W':
        return [l[2], l[1], l[5], l[0], l[4], l[3]]
    if d == 'E':
        return [l[3], l[1], l[0], l[5], l[4], l[2]]
    if d == 'R':
        return [l[0], l[2], l[4], l[1], l[3], l[5]]

def check(d1, d2):
    for k in 'EE':
        for i in 'NNNN':
            for j in 'RRRR':
                if d1 == d2:
                    return 1
                else:
                    d2 = rotate(d2, j)
            d2 = rotate(d2, i)
        d2 = rotate(d2, k)
    return 0


if __name__ == '__main__':
    ds = []
    n = int(input())

    for i in range(n):
        ds.append(list(map(int, input().split())))

    for i in range(n):
        for j in range(i + 1, n):
            if check(ds[i], ds[j]):
                print('No')
                exit(0)
    print('Yes')

Submission status: Accepted

Solution code:
import itertools

class Dice:
    N = [0, 1, 5, 4]
    S = N[::-1]
    E = [0, 3, 5, 2]
    W = E[::-1]
    R = [1, 2, 4, 3]
    L = R[::-1]

    def __init__(self, numbers):
        self.numbers = numbers

    def __eq__(self, other):
        if isinstance(other, Dice):
            newdice = Dice(other.numbers.copy())
            for x in range(6):
                if 1 <= x <= 3:
                    newdice.toX('N')
                elif x == 4:
                    newdice.toX('N')
                    newdice.toX('E')
                elif x == 5:
                    [newdice.toX('E') for _ in range(2)]
                for _ in range(4):
                    if self.numbers == newdice.numbers:
                        return True
                    newdice.toX('R')

            else:
                return False

        else:
            return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def toX(self, x):
        data = getattr(self, x)
        self.numbers.append(0)
        for k in range(5):
            i1 = data[k - 1] if k != 0 else 6
            i2 = data[k] if k != 4 else 6
            self.numbers[i1] = self.numbers[i2]
        del self.numbers[6]

    def setTopandFront(self, top, front):
        while self.numbers[0] != top:
            if self.numbers.index(top) in self.N:
                self.toX('N')
            else:
                self.toX('E')
        while self.numbers[1] != front:
            self.toX('R')


n = int(input())
dices = [Dice([int(i) for i in input().split()]) for _ in range(n)]
if all(dices[i1] != dices[i2] for i1, i2 in itertools.combinations(range(n), 2)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self,rot,Face):
        self.rot= rot
        self.Face = Face
    def Rotate(rot,Face):
        r=len(rot)
        intFace=[int(Face[i]) for i in range(6)]

        for i in range(r):
            Temp=[intFace[i] for i in range(6)]

            if rot[i]== "E":
                intFace[0]=Temp[3]
                intFace[1]=Temp[1]
                intFace[2]=Temp[0]
                intFace[3]=Temp[5]
                intFace[4]=Temp[4]
                intFace[5]=Temp[2]

            elif rot[i]== "W":
                intFace[0]=Temp[2]
                intFace[1]=Temp[1]
                intFace[2]=Temp[5]
                intFace[3]=Temp[0]
                intFace[4]=Temp[4]
                intFace[5]=Temp[3]

            elif rot[i]== "N":
                intFace[0]=Temp[1]
                intFace[1]=Temp[5]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[0]
                intFace[5]=Temp[4]

            elif rot[i]== "S":
                intFace[0]=Temp[4]
                intFace[1]=Temp[0]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[5]
                intFace[5]=Temp[1]

        return intFace
#returnしてなかったわ インデント幅も注意
n=int(input())
Face=[[] for i in range(n)]
i=0
while i<n:
    Face[i] = input().split()
    i+=1

###################
#同じ整数があるので前のは使えず。ごっそり修正
####################3
D1=["","N","W","E","S","NN"]
D2= ["","NWS","NWSNWS","NWSNWSNWS",]
same=False
for l in range(n):
    for m in range(n):
        if m==l:
            pass
        else:
            for k in range(6):
                for i in range(4):
                    rot = D1[k]+D2[i]
                    tempFace= Dice.Rotate(rot,Face[l])
                    j=0
                    while j<6:
                        if tempFace[j]!=int(Face[m][j]):
                            break
                        else:
                            if j==5:
                                same=True
                            j+=1

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

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

def check_all_different(dice):
    '''
    if all dice are different, return True

    dice : string list

    '''
    for i in range(len(dice)):
        if i == 0:
            continue
        for j in range(i):
            res = check_two_dice(dice[i], dice[j])

            if res:
                return False
    
    return True


if __name__ == "__main__":
    res = False
    n = int(input())
    dice = []
    for _ in range(n): 
        dice.append(input().split())

    res = check_all_different(dice)

    print("Yes") if res else print("No")

Submission status: Accepted

Solution code:
import itertools



class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.command_allpattern = "NNNNENNNNENNNNENNNNNENNNNEENNNNWWWSE"

    def set_number(self, d0, d1, d2, d3, d4, d5):
        self.number[0] = d0
        self.number[1] = d1
        self.number[2] = d2
        self.number[3] = d3
        self.number[4] = d4
        self.number[5] = d5

    def roll(self, command):
        if   command == "E":
            self.set_number(self.number[3],self.number[1],self.number[0],self.number[5],self.number[4],self.number[2])
        elif command == "N":
            self.set_number(self.number[1],self.number[5],self.number[2],self.number[3],self.number[0],self.number[4])
        elif command == "S":
            self.set_number(self.number[4],self.number[0],self.number[2],self.number[3],self.number[5],self.number[1])
        elif command == "W":
            self.set_number(self.number[2],self.number[1],self.number[5],self.number[0],self.number[4],self.number[3])
        else:
            raise

    def get_top(self):
        return self.number[0]

    def get_d2(self, d0, d1):
        flag_correct = False
        
        for command in self.command_allpattern:
            self.roll(command)

            if ((d0 == self.number[0]) and
                (d1 == self.number[1])):
                d2 = self.number[2]
                flag_correct = True

        if flag_correct:
            return d2
        else:
            raise

    def is_equal_dice_number(self, Dice):
        if set(Dice.number) == set(self.number):
            return True
        else:
            return False

    def equal_dice(self, Dice):

        if not self.is_equal_dice_number(Dice):
            return("No")

        flag_correct = False

        for command in self.command_allpattern:
            Dice.roll(command)

            if ((Dice.number[0] == self.number[0]) and
                (Dice.number[1] == self.number[1]) and
                (Dice.number[2] == self.number[2]) and
                (Dice.number[3] == self.number[3]) and
                (Dice.number[4] == self.number[4]) and
                (Dice.number[5] == self.number[5])):
                flag_correct = True

        if flag_correct:
            return("Yes")
        else:
            return("No")



n = int(input())

list_dice_class = []

for _ in range(n):
    list_face = list(map(int, input().split()))

    dice = Dice()
    dice.set_number(list_face[0], list_face[1], list_face[2], list_face[3], list_face[4], list_face[5])

    list_dice_class.append(dice)


flag_equal = False

for dice_a, dice_b in list(itertools.combinations(list_dice_class, 2)):
    if dice_a.equal_dice(dice_b) == "Yes":
        flag_equal = True
        break

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

Submission status: Accepted

Solution code:
# ITP_11_D
import sys

class Dice :
    def __init__(self, dice) :
        self.dice = dice
    def roll(self, direction):
        tmp = self.dice[:]
        if direction == "N":
            self.dice[0] = tmp[1]
            self.dice[1] = tmp[5]
            self.dice[4] = tmp[0]
            self.dice[5] = tmp[4]
        elif direction == "E":
            self.dice[0] = tmp[3]
            self.dice[2] = tmp[0]
            self.dice[3] = tmp[5]
            self.dice[5] = tmp[2]
        elif direction == "W":
            self.dice[0] = tmp[2]
            self.dice[2] = tmp[5]
            self.dice[3] = tmp[0]
            self.dice[5] = tmp[3]
        else:
            self.dice[0] = tmp[4]
            self.dice[1] = tmp[0]
            self.dice[4] = tmp[5]
            self.dice[5] = tmp[1]

    def check_dice(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def check_dice_some(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def dice_top(self):
        print(self.dice[0])
    
dice_list = []
for i in range(int(input())):
    dice_list.append(Dice(list(map(str, input().split()))))
    
for i in range(len(dice_list)-1):
    judge = dice_list[0].check_dice(dice_list[i+1])
    if judge == True:
        print("No")
        sys.exit()
        
print("Yes")