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

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

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):
def dicing(lis, inst):
    if inst == 'N':
        ans_lis = [lis[1],lis[5],lis[2],lis[3],lis[0],lis[4]]
    if inst == 'W':
        ans_lis = [lis[2],lis[1],lis[5],lis[0],lis[4],lis[3]]
    if inst == 'S':
        ans_lis = [lis[4],lis[0],lis[2],lis[3],lis[5],lis[1]]
    if inst == 'E':
        ans_lis = [lis[3],lis[1],lis[0],lis[5],lis[4],lis[2]]
    
    return(ans_lis)

def turn_right(lis):
    inst = list('ENW')
    for i in range(len(inst)):
        lis = dicing(lis, inst[i])
    return(lis)

def find_above(lis, num1, num2):
    inst1 = list('NNNEWW')
    for i in range(len(inst1)):
        if lis[0] == num1 and lis[5] == num2:
            break
        
        lis = dicing(lis, inst1[i])
        if lis[0] == num1 and lis[5] == num2:
            break
    return(lis)

def find_samedice(dice1,dice2):
    YN = 'No'
    lis = find_above(dice1, dice2[0], dice2[5])
    for i in range(4):
        lis = turn_right(lis)
        if lis == dice2:
            YN = 'Yes'
            break
    return(YN)

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

ans = 'Yes'
for i in range(N):
    for j in range(N):
        if i < j:
            if find_samedice(dices[i], dices[j]) == 'Yes':
                ans = 'No'

print(ans)

Solution (Python):
from collections import deque

def is_equal(dice1, dice2):

    equal = "No"

    if dice1.min != dice2.min or dice1.max != dice2.max:
        return "No"

    top0 = dice1.disp_top_face()
    front0 = dice1.disp_front_face()

    flag = 1

    for _ in range(100):

        if dice2.disp_top_face() == top0:
            flag = 0
            break

        for _ in range(4):
            dice2.lotate("S")

            if dice2.disp_top_face() == top0:
                flag = 0
                break

        if flag :
            dice2.lotate("E")
        else:
            break

    for _ in range(4):

        if dice2.disp_front_face() == front0:
            break

        dice2.lotate("E")
        dice2.lotate("S")
        dice2.lotate("W")

    if dice1.disp_top_face() == dice2.disp_top_face() and \
       dice1.disp_bottom_face() == dice2.disp_bottom_face() and \
       dice1.disp_front_face() == dice2.disp_front_face() and \
       dice1.disp_left_face() == dice2.disp_left_face() and \
       dice1.disp_right_face() == dice2.disp_right_face() and \
       dice1.disp_back_face() == dice2.disp_back_face():

       equal = "Yes"

    return equal

class Dice():
    def __init__(self, seq):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

        self.max = max(seq)
        self.min = min(seq)

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

    def disp_back_face(self):
        return self.v[1]

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input()
    n = int(param)

    dices = list()

    for _ in range(n):
        param = input().split(" ")
        seq = [int(a) for a in param]
        d = Dice(seq)
        dices.append(d)

    different = "Yes"

    for i in range(len(dices)-1):

        if len(dices) - 1 < 2:
            if is_equal(dices[i], dices[i+1]) == "Yes":
                different = "No"
        else:
            for j in range( i + 1, len(dices) - 1 ):
                if is_equal(dices[i], dices[j]) == "Yes":
                    different = "No"

    print(different)

Solution (Python):
import itertools


class Dice():
    def __init__(self, dice_labels):
        self.label = {
            'top': dice_labels[0],
            'south': dice_labels[1],
            'east': dice_labels[2],
            'west': dice_labels[3],
            'north': dice_labels[4],
            'bottom': dice_labels[5]
        }

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['west'], self.label['top'], self.label['bottom'], self.label['east'])

    def __roll_to_west(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['east'], self.label['bottom'], self.label['top'], self.label['west'])

    def __roll_to_south(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['north'], self.label['top'], self.label['bottom'], self.label['south'])

    def __roll_to_north(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['south'], self.label['bottom'], self.label['top'], self.label['north'])

    def __turn_right(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['east'], self.label['north'], self.label['south'], self.label['west'])

    def __turn_left(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['west'], self.label['south'], self.label['north'], self.label['east'])


def check_same_surface(dice1, dice2):
    for direction in ['top', 'bottom', 'east', 'west', 'south', 'north']:
        if dice1.label[direction] != dice2.label[direction]:
            return False
    return True


def check_same_dice(dice1, dice2):
    same_pattern_list = []
    for turn_lr in ['R'] * 4:
        for roll_sn in ['N'] * 4:
            for roll_ew in ['E'] * 4:
                dice2.roll(roll_ew)
                same_pattern_list.append(check_same_surface(dice1, dice2))
            dice2.roll(roll_sn)
            same_pattern_list.append(check_same_surface(dice1, dice2))
        dice2.turn(turn_lr)
        same_pattern_list.append(check_same_surface(dice1, dice2))
    return True in same_pattern_list


num_dices = int(input())
dices = []
for dice_number in range(0, num_dices):
    dice_labels = input().split(' ')
    dices.append(Dice(dice_labels))

is_same_dice_result_list = []
for dice1, dice2 in itertools.combinations(dices, 2):
    is_same_dice_result_list.append(check_same_dice(dice1, dice2))

if True in is_same_dice_result_list:
    print('No')
else:
    print('Yes')

Solution (Python):
D = [
    (1, 5, 2, 3, 0, 4), 
    (3, 1, 0, 5, 4, 2), 
    (4, 0, 2, 3, 5, 1), 
    (2, 1, 5, 0, 4, 3), 
]

N = int(input())
L = [None]*N
for i in range(N):
    *L[i], = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)
ok = 1
for i in range(N):
    Li = L[i]
    for j in range(i+1, N):
        Lj = L[j]
        for k in range(24):
            if Li == Lj:
                ok = 0
            Lj[:] = (Lj[e] for e in D[p[k%8]])
print("Yes" if ok else "No")

Solution (Python):
def lotate(dic, dire):
    if dire == 'N':
        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
    elif dire == 'S':
        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
    elif dire == 'W':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
    elif dire == 'E':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
    return dic


n = int(input())
dice = []
for i in range(n):
    a1,b1,c1,d1,e1,f1 = map(int, input().split())
    dice.append({'up': a1, 'front': b1, 'right': c1, 'left': d1, 'back': e1, 'bottom': f1})
ans = 'Yes'
for i in range(1, n):
    for j in range(1, i+1):
        if dice[i-j] == dice[i]:
            ans = 'No'
        else:
            s = 'EEENEEENEEESEEESEEENEEEN'
            for k in s:
                dice[i-j] = lotate(dice[i-j], k)
                if dice[i-j] == dice[i]:
                    ans = 'No'
print(ans)

Solution (Python):
import itertools
import random


class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]
        self.back = self.faces[6]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down, self.back = self.down, self.top, self.back, self.up
        elif direction == "S":
            self.top, self.up, self.down, self.back = self.up, self.back, self.top, self.down
        elif direction == "W":
            self.top, self.left, self.right, self.back = self.right, self.top, self.back, self.left
        elif direction == "E":
            self.top, self.left, self.right, self.back = self.left, self.back, self.top, self.right
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def __eq__(self, other):
        return (
           self.top, self.up, self.left, self.down, self.right, self.back
        ) == (
            other.top, other.up, other.left, other.down, other.right, other.back
        )


def is_equal_pair(d1, d2):
    i = 0
    while i < 100:
        if d1 == d2:
            return True
        d2.roll(random.choice(["N", "S", "W", "E"]))
        i += 1
    return False


n = int(input())
dices = []
for i in range(n):
    f = [int(i) for i in input().split()]
    dice = Dice(*f)
    dices.append(dice)

ans = "Yes"
for d1, d2 in itertools.combinations(dices, 2):
    if is_equal_pair(d1, d2):
        ans = "No"
        break

print(ans)

Solution (Python):
def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]
def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]
def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]
def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]
def Rot(a,b,c,d,e,f):
    return [a,d,b,e,c,f]



def Judge(change, change_after):
    flag=0
    for idx in range(0, 5):
        change=South(*change)
        
        if change==change_after:
            flag=flag+1
        for idx2 in range(0,4):
            change=Rot(*change)
            
            if change==change_after:
               flag=1+flag
               
    for idx in range(0, 5):
        change=West(*change)
        
        if change==change_after:
            flag=flag+1
        for idx2 in range(0,4):
            change=Rot(*change)
            
            if change==change_after:
               flag=1+flag
    return flag
    
n=int(input())
matrix=[]
for i in range(0, n):
    change=list( map(int,input().split()))
    matrix.append(change)
    

judge_number=0
for i in range(0, n-1):
    change=matrix[i]
    for j in range(i+1, n):
        change_after=matrix[j]
        judge_number=Judge(change, change_after)+judge_number
       

if judge_number==0:
    print("Yes")
else:
    print("No")

Solution (Python):
from itertools import combinations as combi

class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
    
    def counterclockwise(self):
        temp = self.back
        self.back = self.left
        self.left = self.front
        self.front = self.right
        self.right = temp
    
    def clockwise(self):
        temp = self.back
        self.back = self.right
        self.right = self.front
        self.front = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
    def fix_up(self, up):
        if self.down == up:
            self.north()
            self.north()
        elif self.right == up:
            self.west()
        elif self.left == up:
            self.east()
        elif self.front == up:
            self.south()
        elif self.back == up:
            self.north()

    def fix_back_with_fixed_up(self, back):
        if self.right == back:
            self.clockwise()
        elif self.left == back:
            self.counterclockwise()
        elif self.front == back:
            self.clockwise()
            self.clockwise()
            
    def equals_narrow_sense(self, dice):
        if self.up == dice.up and self.down == dice.down and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.front == dice.front:
            return True
        else:
            return False

def is_equal_dice(dice1, dice2):
    for i in range(6):
        if 0 < i <= 3:
            dice1.north()
        elif i == 4:
            dice1.west()
        elif i == 5:
            dice1.east()
            dice1.east()

        for l in range(4):
            dice1.clockwise()

            for j in range(6):
                if 0 < j <= 3:
                    dice2.north()
                elif j == 4:
                    dice2.west()
                elif j == 5:
                    dice2.east()
                    dice2.east()

                for k in range(4):
                    dice2.clockwise()

                    if dice1.equals_narrow_sense(dice2):
                        return True
    return False

dice_n = int(input())

dice_lst = []
for _ in range(dice_n):
    up, back, right, left, front, down = map(int, input().split())
    dice_lst.append(Dice(up, back, right, left, front, down))
    
equal_flag = False
for pair in combi(dice_lst, 2):
    if is_equal_dice(pair[0], pair[1]):
        equal_flag = True
        break

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

Solution (Python):
import sys

class Dice():
    top=0
    n=1
    e=3
    w=2
    s=4
    bottom=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.bottom,self.n,self.s = self.n,5-self.n,5-self.top,self.top
        elif(direction=="E"):
            self.top,self.bottom,self.e,self.w = self.e,5-self.e,5-self.top,self.top
        elif(direction=="W"):
            self.top,self.bottom,self.e,self.w = self.w,5-self.w,self.top,5-self.top
        elif(direction=="S"):
            self.top,self.bottom,self.n,self.s = self.s,5-self.s,self.top,5-self.top

    def equal(self,another):
        if(self.dice[self.top] != another.dice[another.top]):
            return False
        if(self.dice[self.n] != another.dice[another.n]):
            return False
        if(self.dice[self.e] != another.dice[another.e]):
            return False
        if(self.dice[self.w] != another.dice[another.w]):
            return False
        if(self.dice[self.s] != another.dice[another.s]):
            return False
        if(self.dice[self.bottom] != another.dice[another.bottom]):
            return False

        return True

n=int(input())
dicea=Dice(list(map(int,input().split())))

for i in range(n-1):
    diceb=Dice(list(map(int,input().split())))

    roll_order="NNNNWNNNWNNNENNNENNNWNNNN"
    for j in range(len(roll_order)):
        if(dicea.equal(diceb)):
            print("No")
            sys.exit()
        else:
            diceb.roll(roll_order[j])
print("Yes")

Solution (Python):
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
    
    def rot(self,way):
        
        if way == 0:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c
        
        if way == 1:
            c = self.e
            self.e = self.n
            self.n = self.w
            self.w = self.s
            self.s = c
        
        if way == 2:
            c = self.w
            self.w = self.d
            self.d = self.e
            self.e = self.u
            self.u = c

def compare(inp1,inp2):
    if not inp1[0] in inp2:
        return 'No'
    dice1 = Dice(inp1[0],inp1[1],inp1[2],inp1[3],inp1[4],inp1[5])
    dice2 = Dice(inp2[0],inp2[1],inp2[2],inp2[3],inp2[4],inp2[5])
    count = 0
    flag = 0
    while True:
        if dice1.u == dice2.u:
            for s in range(5):
                if dice1.s == dice2.s and dice1.e == dice2.e and dice1.w == dice2.w and dice1.n == dice2.n:
                    if dice1.d == dice2.d:
                        flag = 1
                        return 'Yes'
                    break
                else:
                    dice2.rot(1)
            if not flag:
                if dice1.d == dice2.s and dice1.u == dice2.n:
                    if (dice1.s == dice2.u) and (dice1.n == dice2.d) and (dice1.e == dice2.e) and (dice1.w == dice2.w):
                        return 'Yes'
                    else:
                        return 'No'
                elif dice1.d == dice2.e and dice1.u == dice2.w:
                    if (dice1.s == dice2.s) and (dice1.n == dice2.n) and (dice1.e == dice2.u) and (dice1.w == dice2.d):
                        return 'Yes'
                    else:
                        return 'No'
                elif dice1.d == dice2.w and dice1.u == dice2.e:
                    if (dice1.s == dice2.s) and (dice1.n == dice2.n) and (dice1.e == dice2.d) and (dice1.w == dice2.u):
                        return 'Yes'
                    else:
                        return 'No'
                elif dice1.d == dice2.n and dice1.u == dice2.s:
                    if (dice1.s == dice2.d) and (dice1.n == dice2.u) and (dice1.e == dice2.e) and (dice1.w == dice2.w):
                        return 'Yes'
                    else:
                        return 'No'
                else:
                    return 'No'
            break
        elif count < 5:
            dice2.rot(0)
            count += 1
        else:
            dice2.rot(1)
            count = 0
            
times = int(input())
input_list = list()
results = list()
for t in range(times):
    inp = list(map(int,input().split()))
    input_list.append(inp)

for il in input_list:
    for l in input_list:
        if input_list.index(il) != input_list.index(l):
            results.append(compare(il,l))

if 'Yes' in results:
    print('No')
else:
    print('Yes')

Solution (Python):
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]


def roll(s, rolllist):
    news = list(s)
    for i in range(6):
        news[i] = s[rolllist[i]]
    return news



def isSameDice(s1, s2):
    rl = {0: [0, 1, 2, 3, 4, 5],
          1: [1, 5, 2, 3, 0, 4],  
          2: [2, 1, 5, 0, 4, 3],  
          3: [3, 1, 0, 5, 4, 2],  
          4: [4, 0, 2, 3, 5, 1],  
          5: [5, 4, 2, 3, 1, 0]}
    roll_z = [0, 3, 1, 4, 2, 5]
    if not (s1[0] in s2):
        return False
    
    tl = [i for i, x in enumerate(s2) if x == s1[0]]
    for t in tl:
        s2 = roll(s2, rl[t])
        ss = s2
        for i in range(6):
            if s1 == ss:
                return True
            ss = roll(ss, roll_z)
    return False


c = []
for i in range(len(s)):
    for j in range(len(s)):
        if i < j:
            c.append([i, j])
for cc in c:
    if isSameDice(s[cc[0]], s[cc[1]]):
        print("No")
        exit()
print("Yes")

Solution (Python):
face = [0]*6
class Dice():

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

    def setnumbers(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 spin(self, command):
        for i in range(6):
            face[i] = self.number[i]
        if command == 'S':
            self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1])
            
        elif command == 'N':
            self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4])
            
        elif command == 'E':
            self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2])
            
        elif command == 'W':
            self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3])
            
    def equal(self, another):
        set = False
        for i in self.order:
            self.spin(i)
            FLAG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLAG = False
                    break
            if FLAG == True:
                return True
        return set

dice = []
n = int(input())
for i in range(n):
    inp = list(map(int, input().split()))

    k= Dice()
    dice.append(k)

    k.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])


flag = True
j = 0
for i in range(n):
    for j in range(i+1, n):
        if dice[i].equal(dice[j]):
            flag = False
            break
if flag == True:
    print('Yes')
else:
    print('No')

Solution (Python):
def main():
    n = int(input())
    dices=[]
    same = 0
    for _ in range(n):
        dices.append(list(map(int, input().split())))

    for i in range(n-1):
        for j in range(i+1,n):
            same += check_dice(dices[i], dices[j])
        if same >= 1:
            print('No')
            break

    if same == 0:
        print('Yes')


def check_dice(f, s):
    yes = 0
    for _ in range(4):
        s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]
        for _ in range(4):
            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
            if f == s:
                yes = 1

    for _ in range(4):
        s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]
        for _ in range(4):
            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
            if f == s:
                yes = 1

    return yes

if __name__ == '__main__':
    main()

Solution (Python):
import random

class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

    def top(self):
        return self.face[0]

n = int(input())
dice1 = Dice()
dice1.setface(list(map(int,input().split())))
flag = 0
for d in range(n-1):
    dicei = Dice()
    dicei.setface(list(map(int,input().split())))
    for i in range(1000):
        dicei.roll(['E','N','S','W'][random.randint(0,3)])
        for j in range(6):
            if dice1.face[j]!=dicei.face[j]:
                break
        else:
            if not flag:print('No' )
            flag = 1
            break
if not flag:
    print('Yes')