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:
# サイコロ        初期状態
#    [1]           N
# [4][2][3][5]   W[1]E
#    [6]           S
#
# 上記の順番でラベルに対する整数が与えられる
# l1 l2 l3 l4 l5 l6
# 複数のサイコロが全て異なっていれば'Yes'
# 1組でも一致していたら'No'
import copy

class Dice:
    def __init__(self, l1, l2, l3, l4, l5, l6):
        self.l1 = l1
        self.l2 = l2
        self.l3 = l3
        self.l4 = l4
        self.l5 = l5
        self.l6 = l6
        self.tmp = 0
    def move_n(self):
        self.tmp = self.l5
        self.l5 = self.l1
        self.l1 = self.l2
        self.l2 = self.l6
        self.l6 = self.tmp
    def move_s(self):
        self.tmp = self.l2
        self.l2 = self.l1
        self.l1 = self.l5
        self.l5 = self.l6
        self.l6 = self.tmp
    def move_e(self):
        self.tmp = self.l3
        self.l3 = self.l1
        self.l1 = self.l4
        self.l4 = self.l6
        self.l6 = self.tmp
    def move_w(self):
        self.tmp = self.l4
        self.l4 = self.l1
        self.l1 = self.l3
        self.l3 = self.l6
        self.l6 = self.tmp
    def show(self):
        return self.l1, self.l2, self.l3, self.l4, self.l5, self.l6

n = int(input())
yn_f = False
d_inf1 = []
d_inf2 = []
for _ in range(n):
    d_inf1.append(Dice(*map(int, input().split())))
d_inf2 = copy.deepcopy(d_inf1)

for i, d1 in enumerate(d_inf1):
    for j, d2 in enumerate(d_inf2):
        if i == j:
            continue
        if set(d1.show()) == set(d2.show()):
            ne_switch = 0
            while d1.l2 != d2.l2:
                if ne_switch <= 3:
                    d1.move_n()
                    ne_switch+=1
                elif 4 == ne_switch :
                    d1.move_e()
                    ne_switch = 0
            e_cnt = 0
            while d1.l1 != d2.l1 and e_cnt <= 3:
                d1.move_e()
                e_cnt+=1

            if d1.l3 == d2.l3 and d1.l4 == d2.l4 and d1.l5 == d2.l5 and d1.l6 == d2.l6:
                yn_f = True
        if yn_f: break
    if yn_f: break            

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

class Dice:

    def __init__(self,dicelist):
        self.dice_list = dicelist
        self.all_pattern = 'NNNNWNNNWNNNENNNENNNWNNN'

    def roll(self, direction):
        work = list(self.dice_list)
        if (direction == 'N'):
            self.dice_list[0] = work[1]
            self.dice_list[1] = work[5]
            self.dice_list[2] = work[2]
            self.dice_list[3] = work[3]
            self.dice_list[4] = work[0]
            self.dice_list[5] = work[4]
        elif (direction == 'E'):
            self.dice_list[0] = work[3]
            self.dice_list[1] = work[1]
            self.dice_list[2] = work[0]
            self.dice_list[3] = work[5]
            self.dice_list[4] = work[4]
            self.dice_list[5] = work[2]
        elif (direction == 'S'):
            self.dice_list[0] = work[4]
            self.dice_list[1] = work[0]
            self.dice_list[2] = work[2]
            self.dice_list[3] = work[3]
            self.dice_list[4] = work[5]
            self.dice_list[5] = work[1]
        elif (direction == 'W'):
            self.dice_list[0] = work[2]
            self.dice_list[1] = work[1]
            self.dice_list[2] = work[5]
            self.dice_list[3] = work[0]
            self.dice_list[4] = work[4]
            self.dice_list[5] = work[3]

    def equals(self, another):
        for p in self.all_pattern:
            another.roll(p)
            if self.dice_list == another.dice_list:
                return True
        else:
            return False

N = int(stdin.readline().rstrip())
is_all_different = True
dices = [Dice(list(map(int, stdin.readline().rstrip().split()))) for d in range(N)]

import itertools
for pattern in list(itertools.combinations(range(N), 2)):
    if dices[pattern[0]].equals(dices[pattern[1]]):
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import copy
import random

n = int(input())

D = []
for x in range(n):
    D.append(list(map(int, input().split())))

dup = 0

roll = [3,3,3,3,1,3,3,3,1,3,3,3,2,3,3,3,2,3,3,3,1,3,3,3]
for x in range(n):
    for r in roll:
        if r == 0:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[4]
            Dt[4] = Dt[5]
            Dt[5] = Dt[1]
            Dt[1] = temp
        elif r== 1:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[2]
            Dt[2] = Dt[5]
            Dt[5] = Dt[3]
            Dt[3] = temp
        elif r== 2:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[3]
            Dt[3] = Dt[5]
            Dt[5] = Dt[2]
            Dt[2] = temp
        elif r == 3:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[1]
            Dt[1] = Dt[5]
            Dt[5] = Dt[4]
            Dt[4] = temp

        D[x] = copy.copy(Dt)
        
        for y in range(n):
            if x == y:
                continue
            else:
                flag = 0           
                for z in range(6):
                    if D[x][z] == D[y][z]:
                        flag += 1
                if flag == 6:
                    dup  = 1
                    print("No")
                    exit()

print("Yes")

Submission status: Accepted

Solution code:

import copy
from enum import IntEnum
import itertools

class Face(IntEnum):
    One=1
    Two=2
    Three=3
    Four=4
    Five=5
    Six=6


class Dice:
    def __init__(self):
        self.top=Face.One
        self.bottom=Face.Six
        self.back=Face.Two
        self.front=Face.Five
        self.left=Face.Four
        self.right=Face.Three
        
    def set_face(self,face_ls):
        self.top=Face(face_ls[0])
        self.back=Face(face_ls[1])
        self.right=Face(face_ls[2])
        self.left=Face(face_ls[3])
        self.front=Face(face_ls[4])
        self.bottom=Face(face_ls[5])
        
    def __str__(self):
        return f"top: {self.top}, back: {self.back}, right: {self.right}, bottom: {self.bottom}, front: {self.front}, left: {self.left}"
        
    def __eq__(self,other):
        equal=self.top == other.top and self.bottom == other.bottom and self.back == other.back and self.front == other.front and self.left == other.left and self.right == other.right
            
        return equal
        
    def get_one_face(self):
        return self.get_n_face(Face.One)
        
    def get_n_face(self,n):
        #指定した面を取得する
        if self.top ==n:
            return self.top
        elif self.bottom==n:
            return self.bottom
        elif self.back==n:
            return self.back
        elif self.front==n:
            return self.front
        elif self.left==n:
            return self.left
        elif self.right==n:
            return self.right
        else:
            assert False
            
    
    def roll(self,command):
        if command=="E":
            #back-frontを軸として右回転
            temp=self.top
            self.top=self.left
            self.left=self.bottom
            self.bottom=self.right
            self.right=temp
            
        elif command=="N":
            #right-leftを固定して前転
            temp=self.top
            self.top=self.back
            self.back=self.bottom
            self.bottom=self.front
            self.front=temp
            
        elif command=="S":
            #right-leftを固定して後転
            temp=self.top
            self.top=self.front
            self.front=self.bottom
            self.bottom=self.back
            self.back=temp
            
        elif command=="W":
            #back-frontを軸として左回転
            temp=self.top
            self.top=self.right
            self.right=self.bottom
            self.bottom=self.left
            self.left=temp
    
    def roll_clockwise_fix_top(self):
        #top,bottomを固定して時計周りに回転させる
        temp=self.front
        self.front=self.left
        self.left=self.back
        self.back=self.right
        self.right=temp
      
def num_pattern_match(num_list,pattern):
    for i,x in enumerate(num_list):
        is_match=True
        for j,y in enumerate(pattern):
            if num_list[(i+j) % len(num_list)] == pattern[j]:
                pass
            else:
                is_match=False
        if is_match:
            return True
            
    return False      

def build_dice(top,back):
    #2つの面からさいころの状態を初期化する
    dice=Dice()
    dice.top=top
    dice.back=back
    
    dice.bottom=Face(7-int(dice.top))
    dice.front=Face(7-int(dice.back))

    #left-rightはどう計算する?
    #難しく考えないで確実にできる簡単な方法を実行する
    exist_dice_list=[int(dice.top),
    int(dice.bottom),
    int(dice.front),
    int(dice.back)]
    
    left_face_num=set([i+1 for i in range(6)]) - set(exist_dice_list)
    
    #top->front->bottom->backの面のリストを作成する
    #泥臭いプログラミングできるかどうかにかかっている
    face_list=[int(dice.top),int(dice.front),int(dice.bottom),int(dice.back)]

    #泥臭くても手を動かせば完了するときはさっさと手を動かして完了させる
    if 1 in left_face_num:
        #1,5が残されているパターン
        pattern=[2,3,5,4]
        if num_pattern_match(face_list,pattern):
            #top->front->bottom->backに走査したとき、2354に一致するとき
            #左に1が来る
            dice.right=Face.Six
            dice.left=Face.One
        else:
            dice.right=Face.One
            dice.left=Face.Six
            
    elif 2 in left_face_num:
        pattern=[1,4,6,3]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Five
            dice.left=Face.Two
        else:
            dice.right=Face.Two
            dice.left=Face.Five
            
    elif 3 in left_face_num:
        pattern=[2,6,5,1]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Four
            dice.left=Face.Three
        else:
            dice.right=Face.Three
            dice.left=Face.Four           
        
    return dice


def move_one_face_to_top(dice):
    #1をトップに持ってくる
    if dice.get_one_face() ==dice.top:
        return
    elif dice.get_one_face()==dice.left:
        #E側に転がす
        dice.roll("E")
        return
    elif dice.get_one_face()==dice.back:
        dice.roll("N")
    elif dice.get_one_face()==dice.right:
        dice.roll("W")
    elif dice.get_one_face()==dice.front:
        dice.roll("S")
    elif dice.get_one_face()==dice.bottom:
        dice.roll("N")
        dice.roll("N")
        

def create_all_equal_dice(dice):
    #等価なダイスをすべて作成する
    same_dice_ls=[]
    for face in list(Face):
        #特定の面を上に回す
        created_dice=copy.deepcopy(dice)
        move_n_face_to_top(created_dice,face)
        same_dice_ls.append(copy.deepcopy(created_dice))
        
        #1,2,3回topを軸にして回転させたものを作成する
        for i in range(3):
            created_dice.roll_clockwise_fix_top()
            same_dice_ls.append(copy.deepcopy(created_dice))
            
    return same_dice_ls
        
def move_n_face_to_top(dice,face):
    #指定した番号をトップに持ってくる
    spec_face=dice.get_n_face(face)
    if spec_face==dice.top:
        return
    elif spec_face==dice.left:
        dice.roll("E")
        return
    elif spec_face==dice.back:
        dice.roll("N")
        return
    elif spec_face==dice.right:
        dice.roll("W")
        return
    elif spec_face==dice.front:
        dice.roll("S")
        return
    elif spec_face==dice.bottom:
        dice.roll("N")
        dice.roll("N")
        return

def move_two_face_to_back(dice):
    #1がtopのときに、2をbackにそろえる
    assert dice.top == Face.One
    assert dice.bottom != Face.Two
    
    if dice.get_n_face(Face.Two)==dice.left:
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
    elif dice.get_n_face(Face.Two)==dice.front:
        dice.roll_clockwise_fix_top()
        dice.roll_clockwise_fix_top()
    elif dice.get_n_face(Face.Two)==dice.right:
        dice.roll_clockwise_fix_top()


def check_if_equal_dice(dice_x,dice_y):
    #2つの面をそろえて、残りの面を比較すると同じダイスか判定可能
    #1をtopに持ってくるアルゴリズム
    #2をbackに持ってくるアルゴリズム
    #比較する
    
    
    move_one_face_to_top(dice_x)
    move_one_face_to_top(dice_y)
    
    move_two_face_to_back(dice_x)
    move_two_face_to_back(dice_y)
    
    return dice_x==dice_y

def _run():
    dice_score_ls=list(map(int,input().split()))
    
    dice_score_dict={i+1:score for i,score in enumerate(dice_score_ls)}
    d_inv={v:k for k,v in dice_score_dict.items()}
    
    query_num=int(input())

    for i in range(query_num):
        top,back=tuple(map(int,input().split()))
        top=d_inv[top]
        back=d_inv[back]
        
        dice=build_dice(top,back)
        
        # print(int(dice.right))
        print(dice_score_dict[int(dice.right)])
        
    

def _compare_dice_with_dict(dice_x,d_x,dice_y_face_list):
    
    is_top_same=d_x[dice_x.top]==dice_y_face_list[0]
    is_bottom_same=d_x[dice_x.bottom]==dice_y_face_list[5]
    is_right_same=d_x[dice_x.right]==dice_y_face_list[2]
    is_left_same=d_x[dice_x.left]==dice_y_face_list[3]
    is_front_same=d_x[dice_x.front]==dice_y_face_list[4]
    is_back_same=d_x[dice_x.back]==dice_y_face_list[1]
    
    return is_top_same and is_bottom_same and is_right_same and is_left_same and is_front_same and is_back_same

def compare_dice_with_dict(dice_x,d_x,d_y):
    
    is_top_same=d_x[dice_x.top]==d_y[Face.One]
    is_bottom_same=d_x[dice_x.bottom]==d_y[Face.Six]
    is_right_same=d_x[dice_x.right]==d_y[Face.Three]
    is_left_same=d_x[dice_x.left]==d_y[Face.Four]
    is_front_same=d_x[dice_x.front]==d_y[Face.Five]
    is_back_same=d_x[dice_x.back]==d_y[Face.Two]
    
    return is_top_same and is_bottom_same and is_right_same and is_left_same and is_front_same and is_back_same
    
def is_equal_dice(src_face_dict,tgt_face_list,all_dice_ls):

    is_same_dice=False
    for d in all_dice_ls:
        if compare_dice_with_dict(d,src_face_dict,tgt_y_face_list):
            is_same_dice=True
            
    return is_same_dice
    

def run():
    
    dice_num=int(input())
    
    dice_info=[]
    
    dice_face_info=[]
    
    
    for i in range(dice_num):
        ls=list(map(int,input().split()))
        
        dice_info.append(ls)
        
        face_dict={Face(i+1):x for i,x in enumerate(ls)}
        
        dice_face_info.append(face_dict)

    
    #各々のdice_face_dictの組み合わせで比較を行う
    all_dice_ls=create_all_equal_dice(Dice())
    
    is_there_same_dice=False
    for dict_x,dict_y in itertools.combinations(dice_face_info,2):
        for d in all_dice_ls:
            if compare_dice_with_dict(d,dict_x,dict_y):
                is_there_same_dice=True
                
    if is_there_same_dice:
        print("No")
    else:
        print("Yes")
    
    
run()

Submission status: Accepted

Solution code:
def createDice(n):
    dice = []
    for _ in range(n):
        numbers = list(map(int, input().split()))
        dice.append(Dice(numbers))

    return dice

class Dice:
    def __init__(self, numbers):
        self.dice = {"上" :numbers[0],
                     "下":numbers[5], 
                     "前":numbers[1],
                     "後":numbers[4],
                     "左":numbers[3],
                     "右":numbers[2]
                    }

    def query(self):
        return [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"], self.dice["左"], self.dice["右"]]

    def rotate_x(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = F
        self.dice["前"] = D
        self.dice["下"] = B
        self.dice["後"] = U

    def rotate_y(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = R
        self.dice["下"] = L
        self.dice["左"] = U
        self.dice["右"] = D

    def rotate_z(self):
        F, R, B, L = [self.dice["前"], self.dice["右"], self.dice["後"], self.dice["左"]]
        self.dice["前"] = R
        self.dice["右"] = B
        self.dice["後"] = L
        self.dice["左"] = F

    def set_position(self, position_seq):
        self.ans = []
        self.up = position_seq[0]
        self.front = position_seq[2]
        
        for i in range(6):
            self.search()
            if i == 2:
                self.rotate_y()
            else:
                self.rotate_x()
        
        return self.ans
    
    def search(self):
        # print("goal:上", self.up, ":", self.dice["上"])
        if self.dice["上"] == self.up:
            for _ in range(4):
                # print("goal:前|上 ", self.front, ":", self.dice["前"], "|", self.dice["上"], "→", self.dice["右"])
                if self.dice["前"] == self.front:
                    self.ans.append(self.query())
                    break
                self.rotate_z()

FLAG = 0
n = int(input())
dice = createDice(n)

for i in range(n-1):
    for j in range(i+1, n):
        next_dice = dice[j].query()
        next_dice_seq = dice[j].set_position(next_dice)
        nice_dice_seq = dice[i].set_position(next_dice)
        # print("サイコロ", i, ":", nice_dice_seq)
        # print("サイコロ", j, ":", next_dice_seq)
        # print()

        for k in range(len(nice_dice_seq)):
            for l in range(len(next_dice_seq)):
                FLAG += (nice_dice_seq[k] == next_dice_seq[l])

if FLAG > 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, num):
        self.number = num
        self.order  = 'NNNNWNNNWNNNENNNENNNWNNN' # 6x4=24 patterns in total
        
    def roll(self, action):
        num_tmp = self.number.copy()
        if action=='N':
            self.number = [num_tmp[1], num_tmp[5], num_tmp[2], num_tmp[3], num_tmp[0], num_tmp[4]]
        elif action=='S':
            self.number = [num_tmp[4], num_tmp[0], num_tmp[2], num_tmp[3], num_tmp[5], num_tmp[1]]
        elif action=='W':
            self.number = [num_tmp[2], num_tmp[1], num_tmp[5], num_tmp[0], num_tmp[4], num_tmp[3]]
        elif action=='E':
            self.number = [num_tmp[3], num_tmp[1], num_tmp[0], num_tmp[5], num_tmp[4], num_tmp[2]]
        
    def check_is_same(self, dice2):
        is_same = False
        for a in self.order:
            dice2.roll(a)
            tmp_is_same = True
            for i in range(6):
                if self.number[i]!=dice2.number[i]:
                    tmp_is_same = False
                    break
            if tmp_is_same:
                is_same = True
                break
        return is_same
        
n = int(input())
N = [list(map(int, input().split())) for i in range(n)]

ans = 'Yes'
for i in range(n-1):
    for j in range(i+1,n):
        dice_i = Dice(N[i])
        dice_j = Dice(N[j])
        if dice_i.check_is_same(dice_j):
            ans = 'No'
            break
    else:
        continue
    break
print(ans)

Submission status: Accepted

Solution code:
import sys
class Dice:
    def __init__(self,a):
        self.dice = [0 for i in range(len(a))]
        for i in range(len(a)):
            self.dice[i] = a[i]

    def N(self):
        self.dice[0],self.dice[1],self.dice[4],self.dice[5] = self.dice[1],self.dice[5],self.dice[0],self.dice[4]

    def S(self):
        self.dice[0],self.dice[1],self.dice[4],self.dice[5] = self.dice[4],self.dice[0],self.dice[5],self.dice[1]

    def E(self):
        self.dice[0],self.dice[2],self.dice[3],self.dice[5] = self.dice[3],self.dice[0],self.dice[5],self.dice[2]

    def W(self):
        self.dice[0],self.dice[2],self.dice[3],self.dice[5] = self.dice[2],self.dice[5],self.dice[0],self.dice[3]

    def R(self):
        self.dice[1],self.dice[2],self.dice[3],self.dice[4] = self.dice[3],self.dice[1],self.dice[4],self.dice[2]

    def L(self):
        self.dice[1],self.dice[2],self.dice[3],self.dice[4] = self.dice[2],self.dice[4],self.dice[1],self.dice[3]

    #確認用
    def output(self):
        print(self.dice)

def comparison(dice1,dice2):
    dir = 'RRRRNRRRRSWRRRREERRRRWSRRRRNNNRRRR'
    for c in dir:
        if c == "R":
            dice1.R()
        elif c == "N":
            dice1.N()
        elif c == "S":
            dice1.S()
        elif c == "W":
            dice1.W()
        elif c == "E":
            dice1.E()
        elif c == "L":
            dice1.L()
        if dice1.dice == dice2.dice:
            return True
    if dice1.dice != dice2.dice:
        return False

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

for i in range(n):
    a = [int(i) for i in input().split()]
    dice = Dice(a)
    dice_list.append(dice)
for i in range(n-1):
    for j in range(i+1,n):
        if comparison(dice_list[i],dice_list[j]) == True:
            print("No")
            sys.exit()
        else:
            Judge.append(comparison(dice_list[i],dice_list[j]))

print('Yes')

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def rotate_right(self):
        tmp = self.ns
        tmp.reverse()
        self.ns = self.we
        self.we = tmp

    def fit_top_s(self, top, s):
        if not (top in self.ns or top in self.we or top in self.bk) or not (
                s in self.ns or s in self.we or s in self.bk):
            return False
        while self.get_top() != top:
            if top in self.ns:
                self.n()
            elif top in self.we:
                self.w()
            else:
                self.n()
                self.n()
        count = 0
        while self.get_s() != s and count < 4:
            self.rotate_right()
            count += 1
        if count == 4:
            return False
        else:
            return True

    def get_top(self):
        return self.ns[1]

    def get_s(self):
        return self.ns[2]

    def get_e(self):
        return self.we[2]


def resolve():
    n = int(input())
    chk = {}
    for i in range(n):
        nums = [int(i) for i in input().split()]
        key = "-".join([str(i) for i in sorted(nums)])
        if key in chk.keys():
            chk[key]["nums"].append(nums)
            chk[key]["count"] += 1
        else:
            chk[key] = {}
            chk[key]["nums"] = [nums]
            chk[key]["count"] = 1
    for value in chk.values():
        if value["count"] > 1:
            dc = Dice(value["nums"][0])
            top = dc.get_top()
            s = dc.get_s()
            chks = {str(dc)}
            for num in value["nums"][1:]:
                dc = Dice(num)
                dc.fit_top_s(top, s)
                chks.add(str(dc))
            if len(chks) != value["count"]:
                print("No")
                return
    else:
        print("Yes")


resolve()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, front, right, left, rear, bottom):
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.rear = rear
        self.bottom = bottom
    def print(self):
        '''print top of dice'''
        print(self.top)
    def north(self):
        self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
    def south(self):
        self.top, self.front, self.bottom, self.rear = \
            self.rear, self.top, self.front, self.bottom
    def east(self):
        self.top, self.right, self.bottom, self.left = \
            self.left, self.top, self.right, self.bottom
    def west(self):
        self.top, self.right, self.bottom, self.left = \
            self.right, self.bottom, self.left, self.top
    def clockwise(self):
        self.front, self.right, self.rear, self.left = \
            self.right, self.rear, self.left, self.front
    def ccw(self):
        self.front, self.right, self.rear, self.left = \
            self.left, self.front, self.right, self.rear
    def __eq__(self, other):
        # top, front, bottom, rear, left, right をこの順で上面にする回転パターン
        pattern = ['', 'N', 'N', 'N', 'E', 'EE']
        tmp = Dice(other.top, other.front, other.right, other.left, other.rear, other.bottom)
        for i in pattern:
            if i == 'N':
                tmp.north()
            elif i == 'E':
                tmp.east()
            elif i == 'EE':
                tmp.east()
                tmp.east()
            else:
                pass
            if self.top != tmp.top or self.bottom != tmp.bottom:
                continue
            for j in range(4):
                if self.front == tmp.front and self.right == tmp.right and \
                   self.rear == tmp.rear and self.left == tmp.left:
                    return True
                tmp.clockwise()
        return False

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

for i in range(n-1):
    for j in range(i+1, n):
        if dice[i] == dice[j]:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice():
    directions = "EEENEEENEEESEEESEEENEEEN"

    def __init__(self, lst):
        self.top = lst[0]
        self.front = lst[1]
        self.right = lst[2]
        self.left = lst[3]
        self.back = lst[4]
        self.bottom = lst[5]

    def rotate(self, direction):
        if direction == "E":
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        if direction == "N":
            self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        if direction == "S":
            self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom
        if direction == "W":
            self.top, self.left, self.bottom, self.right = self.right, self.top, self.left, self.bottom

    def fit_top_front(self, num_top, num_front):
        for direction in Dice.directions:
            if self.top == num_top and self.front == num_front:
                break
            self.rotate(direction)

    def fit_all(self, dice):
        for direction in Dice.directions:
            if self.top == dice.top and self.front == dice.front and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.bottom == dice.bottom:
                return True
            self.rotate(direction)
        return False


def compare(lst, dice):
    for direction in Dice.directions:
        if lst[0] == dice.top and lst[1] == dice.front and lst[2] == dice.right and lst[3] == dice.left and lst[4] == dice.back and lst[5] == dice.bottom:
            return True
        dice.rotate(direction)
    return False


def main():
    num_dices = int(input())  # number of dices
    dices = []  # label of dices
    dices.append(list(map(int, input().split())))  # first dice
    for _ in range(num_dices - 1):
        label_dice = list(map(int, input().split()))
        dice = Dice(label_dice)
        for i in range(len(dices)):
            result = compare(dices[i], dice)
            if result == True:
                print("No")
                return 0
        dices.append(label_dice)
    print("Yes")


if __name__ == "__main__":
    main()