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

Solution (Python):
class Dice():
    def __init__(self):
        self.num = [0 for _ in range(6)]
    
    def set_num(self, n0, n1, n2, n3, n4, n5):
        self.num[0] = n0
        self.num[1] = n1
        self.num[2] = n2
        self.num[3] = n3
        self.num[4] = n4
        self.num[5] = n5
    
    
    def roll(self, order):
        tmp = self.num.copy()
        
        if order == "N":
            self.set_num(tmp[1], tmp[5], tmp[2], tmp[3], tmp[0], tmp[4])
        elif order == "S":
            self.set_num(tmp[4], tmp[0], tmp[2], tmp[3], tmp[5], tmp[1])
        elif order == "E":
            self.set_num(tmp[3], tmp[1], tmp[0], tmp[5], tmp[4], tmp[2])
        elif order == "W":
            self.set_num(tmp[2], tmp[1], tmp[5], tmp[0], tmp[4], tmp[3])
        elif order == "rot_Clock":
            self.set_num(tmp[0], tmp[2], tmp[4], tmp[1], tmp[3], tmp[5])
        else:
            print("Error: 不正な入力です")

    def get_top_num(self):
        return self.num[0]
        

    

n_dice = int(input())
list_dice_num = []
for _ in range(n_dice):
    list_dice_num.append([int(_) for _ in input().split()])


list_dice = []
for init_num1 in list_dice_num:
    dice1 = Dice()
    dice1.set_num(init_num1[0], init_num1[1], init_num1[2], init_num1[3], init_num1[4], init_num1[5])
    list_dice.append(dice1)


def check_dice_equal_1(dice1, dice2):
    checker = False
    for i in range(3):
        for j in range(3):
            orders = "N" * (i + 1) + "E" * (j + 1)
            
            
            for order in orders:
                dice2.roll(order)
            if dice1.num == dice2.num:
                checker = True
            
    for i in range(3):
        for j in range(3):
            orders = "E" * (i + 1) + "N" * (j + 1)
            
            
            for order in orders:
                dice2.roll(order)
            if dice1.num == dice2.num:
                checker = True
    
    for i in range(3):
        for j in range(3):
            for k in range(3):
                orders = "E" * (i + 1) + "N" * (j + 1) + "E" * (k + 1)
                
                
                for order in orders:
                    dice2.roll(order)
                if dice1.num == dice2.num:
                    checker = True
    
    for i in range(3):
        for j in range(3):
            for k in range(3):
                orders = "N" * (i + 1) + "E" * (j + 1) + "N" * (k + 1)
                
                
                for order in orders:
                    dice2.roll(order)
                if dice1.num == dice2.num:
                    checker = True
    return checker


def check_dice_equal_2(dice1, dice2):
    checker = False
    num_dice1_top, num_dice1_front = dice1.num[0], dice1.num[1]
    
    index_top = dice2.num.index(num_dice1_top)
    index_front = dice2.num.index(num_dice1_front)
    
    counter = 0
    while (index_top != 0) & (counter < 3):
        counter += 1
        if index_top in [0, 1, 4, 5]:
            dice2.roll("N")
            index_top = dice2.num.index(num_dice1_top)
            index_front = dice2.num.index(num_dice1_front)
        else:
            dice2.roll("E")
            index_top = dice2.num.index(num_dice1_top)
            index_front = dice2.num.index(num_dice1_front)
    
    counter = 0
    while (index_front != 1) & (counter < 3):
            dice2.roll("rot_Clock")
            index_top = dice2.num.index(num_dice1_top)
            index_front = dice2.num.index(num_dice1_front)
    
    
    
    
    if dice1.num == dice2.num:
        checker = True
        
    return checker



ans_checker = True
for i in range(len(list_dice) - 1):
    for j in range(len(list_dice) - i - 1):
        j2 = j + (i + 1)
        dice1 = list_dice[i]
        dice2 = list_dice[j2]
        
        checker1 = check_dice_equal_1(dice1, dice2)
        checker2 = check_dice_equal_1(dice1, dice2)
        
        
        if checker1 or checker2:
            ans_checker = False
    
if ans_checker:
    print("Yes")
else:
    print("No")

Solution (Python):
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')

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001




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")

Solution (Python):
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")

Solution (Python):









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')

Solution (Python):

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")

Solution (Python):
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")

Solution (Python):

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":
            
            temp=self.top
            self.top=self.left
            self.left=self.bottom
            self.bottom=self.right
            self.right=temp
            
        elif command=="N":
            
            temp=self.top
            self.top=self.back
            self.back=self.bottom
            self.bottom=self.front
            self.front=temp
            
        elif command=="S":
            
            temp=self.top
            self.top=self.front
            self.front=self.bottom
            self.bottom=self.back
            self.back=temp
            
        elif command=="W":
            
            temp=self.top
            self.top=self.right
            self.right=self.bottom
            self.bottom=self.left
            self.left=temp
    
    def roll_clockwise_fix_top(self):
        
        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):
    
    dice=Dice()
    dice.top=top
    dice.back=back
    
    dice.bottom=Face(7-int(dice.top))
    dice.front=Face(7-int(dice.back))

    
    
    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)
    
    
    
    face_list=[int(dice.top),int(dice.front),int(dice.bottom),int(dice.back)]

    
    if 1 in left_face_num:
        
        pattern=[2,3,5,4]
        if num_pattern_match(face_list,pattern):
            
            
            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):
    
    if dice.get_one_face() ==dice.top:
        return
    elif dice.get_one_face()==dice.left:
        
        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))
        
        
        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):
    
    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):
    
    
    
    
    
    
    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(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)

    
    
    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()

Solution (Python):
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):
        
        if self.dice["上"] == self.up:
            for _ in range(4):
                
                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)
        
        
        

        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')

Solution (Python):
class Dice:
    def __init__(self, num):
        self.number = num
        self.order  = 'NNNNWNNNWNNNENNNENNNWNNN' 
        
    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)

Solution (Python):
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')