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):
def sgn(a, b):
    return int(a*b/abs(a*b))

class Dice:
    def __init__(self, numbers):
        self.numbers_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1:numbers[5]}
        self.numbers_ver_dict = {numbers[0]:1, numbers[1]:2,numbers[2]:3,numbers[3]:-3, numbers[4]:-2,numbers[5]:-1}

    
    def show_right(self, a, b):
        var_a = self.numbers_ver_dict[a]
        var_b = self.numbers_ver_dict[b]
        if abs(var_a) == 1:
            if abs(var_b) == 2:
                return self.numbers_dict[sgn(var_a,var_b)*3]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)*2]
        elif abs(var_a) == 2:
            if abs(var_b) == 1:
                return self.numbers_dict[-sgn(var_a, var_b)*3]
            else:
                return self.numbers_dict[sgn(var_a,var_b)]
        else:
            if abs(var_b) == 1:
                return self.numbers_dict[sgn(var_a, var_b)*2]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)]

    def exam_equal(self, dice):
        for key in dice.numbers_ver_dict:
            if key not in self.numbers_ver_dict:
                return False
        exam_tuple = ((examin_list[0], examin_list[1]), (examin_list[0], examin_list[2]), (examin_list[0], examin_list[4]),
        (examin_list[0], examin_list[3]), (examin_list[1], examin_list[5]))
        for num in exam_tuple:
            if dice1.show_right(num[0], num[1]) != dice.show_right(num[0], num[1]):
                return False
        return True


if __name__ == '__main__':
    n = int(input())
    examin_list = list(map(int, input().split()))
    dice1 = Dice(examin_list)
    dice = []
    for i in range(n-1):
        dice.append(Dice(list(map(int, input().split()))))
    diff_flag = False
    for d in dice:
        if dice1.exam_equal(d):
            print('No')
            diff_flag = True
            break
    if not diff_flag:
        print('Yes')

Solution (Python):
transforms = []
for i, sides in enumerate(((3,1,2,4),(2,0,3,5),(4,0,1,5),(1,0,4,5),(3,0,2,5),(2,1,3,4))):
	for j in range(4):
		r = sides[j:] + sides[:j]
		transforms.append((i, r[1], r[2], r[0], r[3], 5-i))

possibilities = set()
for _ in range(int(input())):
	die = input().split()
	new_possibilities = {tuple(die[t] for t in transform) for transform in transforms}
	if new_possibilities.intersection(possibilities):
		print('No')
		break
	possibilities.update(new_possibilities)
else:
	print('Yes')

Solution (Python):
buff = "NNNNWNNNWNNNENNNENNNWNNN"

class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                
                return self.num[m]
        
        def return_lst(self):
                return self.num

def isSameDice(D1, D2):
        for d in buff:
                D1.roll(d)
                if D1.return_lst() == D2.return_lst():
                        return True
        return False

N = int(input())
dices = []

for n in range(N):
        lst = [ int(i) for i in input().split() ]
        dices.append(Dice(lst))

for i in range(N):
        for j in range(i + 1, N):
                if isSameDice(dices[i], dices[j]):
                        print("No")
                        exit()

print("Yes")

Solution (Python):
def rotate(id, l)->list:
    dir = ['S', '', 'WS', 'ES', 'SS', 'N']
    for o in dir[id]:
        l = [ l[int(k)] for k in list(s[o])]
    return l 

def search(j, i):
    lj = a[j]
    li = a[i]
    if len(set(lj) ^ set(li)) == 0: 
        at = 0
        for l in range(6): 
            if lj.count(lj[l]) == 1: 
                at = l
                break
        bt = li.index(lj[at]) 
        lj = rotate(at, lj)
        li = rotate(bt, li)
        for o in 'EEEE':
            lj = [ lj[int(k)] for k in list(s[o]) ]
            if li == lj: return True
    else: return False

s = {'E': '310542', 'W': '215043', 'S': '402351', 'N': '152304'}  
a = []
n = int(input())
i = 0
while i < n:
    a.append(list(map(int, input().split())))
    j = 0
    while j <= i-1: 
        if search(j, i): 
            print('No')
            i = n
            break 
        j+=1
    if i == n-1: print('Yes')
    i+=1

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 set(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 kaiten(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.set(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.set(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.set(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.set(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def tansaku(self,top_num,front_num):
 
        self.save = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save[i] = self.number[i]
 
        ret = -1;
 
        for i in range(len(self.order)):
            self.kaiten(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
        
        for i in range(len(self.number)):
            self.number[i] = self.save[i]
 
        return ret;
 
    def hyouka(self,b):
        for i in range(len(self.order)):
            self.kaiten(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != b.number[k]: 
                    FLG = False
                    break
            if FLG == True:
                return True
        
        return False
        
 
 
N = int(input())
D = []

for i in range(N):
    table = list(map(int,input().split()))
    dice = Dice()
    dice.set(table[0], table[1], table[2], table[3], table[4], table[5])
    D.append(dice)
    
FLG = True

for i in range(N-1):
    for k in range(i+1,N):
        if D[i].hyouka(D[k]) == True:
            FLG = False
            break

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

Solution (Python):
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

diceNum = int(input())
rollCommandList = ["E", "W", "S", "N"]
counter = 1
answer = [0]
surfaceNum = list()
dice = list()
for i in range(diceNum):
    surfaceNum = [int(i) for i in input().split()]
    dice.append(Dice(surfaceNum))
for i in range(diceNum-1):
    for j in range(i+1,diceNum):
        counter = 0
        while True:    
            rollCommand = random.choice(rollCommandList)
            if rollCommand == "E":
                dice[j].east()
            if rollCommand == "W":
                dice[j].west()
            if rollCommand == "S":
                dice[j].south()
            if rollCommand == "N":
                dice[j].north()
            if counter == 100:
                answer.append('Yes')
                
                break        
            if dice[i].surface == dice[j].surface:
                answer.append('No')
                
                break
            counter += 1
if answer.count('No') > 0:
    print('No')
else:
    print('Yes')

Solution (Python):
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True



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


yes = all([not dices[0].same(other) for other in dices[1:]])
print('Yes' if yes else 'No')

Solution (Python):
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True

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

yes = all([not dices[0].same(other) for other in dices[1:]])
print('Yes' if yes else 'No')

Solution (Python):
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if b[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Solution (Python):
nl = []
n = int(input())
for i in range(n):
    nl.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(6):
            for l in range(4):
                nl[i] = [nl[i][0],nl[i][3],nl[i][1],nl[i][4],nl[i][2],nl[i][5]]
                if nl[i] == nl[j]:
                    print("No")
                    exit()
            if k % 2 == 0:
                nl[i] = [nl[i][4],nl[i][0],nl[i][2],nl[i][3],nl[i][5],nl[i][1]]
            else:
                nl[i] = [nl[i][2],nl[i][1],nl[i][5],nl[i][0],nl[i][4],nl[i][3]]
print("Yes")

Solution (Python):
class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N(self):
        ls = self.S().S().S().ls
        return Dice(ls)
        
    def E(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W(self):
        ls = self.E().E().E().ls
        return Dice(ls)
        
        
        
    def R_rot(self):
        return self.E().S().W()
        
    def rot(self, num):
        for _ in range(num):
            self = self.R_rot()
        return self

n = int(input())

ls = [ list(map(int, input().split())) for _ in range(n)]


a = Dice(ls[0])

me = [a, a.N(), a.W(), a.E(), a.S(), a.S().S()]

judge = False

for i in me:
    for j in range(4):
        
        for k in ls:
            
            if i.rot(j).ls != a.ls and i.rot(j).ls == k:
                judge = True
                

if judge == True:
    print('No')
else:
    print('Yes')

Solution (Python):

import copy
class Dice:
    
    def __init__(self, d):
        self.data = {"bottom":d[5], "north":d[4], "west": d[3],
                    "east":d[2],"south":d[1],"top":d[0]}

    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self, directions):
        for direction in directions:
            self.moveOne(direction)
            
    def setDiceII(self, a, b):
        if self.data["east"] == a:
            self.moveOne("W")
        elif self.data["north"] == a:
            self.moveOne("S")
        elif self.data["west"] == a:
            self.moveOne("E")
        elif self.data["south"] == a:
            self.moveOne("N")
        elif self.data["bottom"] == a:
            self.movePart("WW")

        if self.data["north"] == b:
            self.rotateRight()
            self.rotateRight()
        elif self.data["east"] == b:
            self.rotateRight()
        elif self.data["west"] == b:
            self.rotateLeft()
            
        
    
    def rotateRight(self):
        temp = self.data["east"]
        self.data["east"] = self.data["north"]
        self.data["north"] = self.data["west"]
        self.data["west"] = self.data["south"]
        self.data["south"] = temp
    
    def rotateLeft(self):
        temp = self.data["west"]
        self.data["west"] = self.data["north"]
        self.data["north"] = self.data["east"]
        self.data["east"] = self.data["south"]
        self.data["south"] = temp
      
    def getSurface(self):
        return self.data["top"]
    
    def getEast(self):
        return self.data["east"]
    
    def getData(self):
        return self.data
    
    def getPatterns(self):
        patterns = []
        temp0 = copy.copy(self.getData())
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.rotateRight()
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.data = temp0
        return patterns
                

    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])

n = int(input().rstrip())
num = []
dice = []
for i in range(n):
    num.append(list(map(int,input().rstrip().split())))
for i in range(n):
    dice.append(Dice(num[i]))

flag = True
for i in range(n-1):
    for j in range(i+1,n):
        for k in dice[j].getPatterns():
            if dice[i].getData() == k:
                flag = False
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
num = int(input())
dice_ = [0 for i in range(num)]
dice = [0 for i in range(num)]
rdice = [0 for i in range(num)]
ndice_ = [0 for i in range(num)]
ndice = [0 for i in range(num)]
nrdice = [0 for i in range(num)]
dice_norm = [0 for i in range(num)]
varif = [0 for i in range(num)]
varif_child = [0 for i in range(6)]

def cross(a,b):
	return((a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0]))

for n in range(num):
	dice_[n] = [int(i) for i in input().split()]
	
	dice[n] = {
		(0,0,1):dice_[n][0],
		(0,-1,0):dice_[n][1],
		(1,0,0):dice_[n][2],
		(-1,0,0):dice_[n][3],
		(0,1,0):dice_[n][4],
		(0,0,-1):dice_[n][5]
	}

for n in range(num):
	dice_keys = [i for i in dice[n].keys()]
	for count,min_ in enumerate(dice_keys):
		opposing = tuple([-i for i in min_])
		sides = list(set(dice_keys) - set([opposing,min_]))
		one = sides[0]
		two = cross(min_, one)
		three = cross(min_, two)
		four = cross(min_, three)
		varif_child[count] = min([1*dice[n][min_] + 10*dice[n][on] + 100*dice[n][tw] + 1000*dice[n][th] + 10000*dice[n][fo] + 100000*dice[n][opposing] for on,tw,th,fo in [[one,two,three,four],[four,one,two,three],[three,four,one,two],[two,three,four,one]]])
	varif[n] = min(varif_child)

if len(list(set(varif))) == num:
	print("Yes")
else:
	print('No')

Solution (Python):
nums = int(input())
dice = []
for _ in range(nums):
    dice.append(list(map(int, input().split())))


class die:
    face = [0, 0, 0, 0, 0, 0]

    def __init__(self, nums):
        self.face = [nums[f] for f in [0, 3, 1, 2, 4, 5]]

    def roll(self, dirs):

        for di in dirs:
            c_face = list(self.face)
            if di == 'S':
                self.face = [c_face[f] for f in [4, 1, 0, 3, 5, 2]]
            elif di == 'N':
                self.face = [c_face[f] for f in [2, 1, 5, 3, 0, 4]]
            elif di == 'W':
                self.face = [c_face[f] for f in [3, 0, 2, 5, 4, 1]]
            elif di == 'E':
                self.face = [c_face[f] for f in [1, 5, 2, 0, 4, 3]]
            

        return list(self.face)


def search():
    for i, d1 in enumerate(dice):
        dice_set_01 = set()
        for md in (' ', 'W', 'E', 'NW', 'NE', 'WW'):
            d_1 = die(d1)
            d_1.roll(md)
            for r in 'SSSS':
                dice_set_01.add(tuple(d_1.roll(r)))

        for j, d2 in enumerate(dice[i+1:], start=i+1):
            dice_set_02 = set()
            for md in (' ', 'W', 'E', 'NW', 'NE', 'WW'):
                d_2 = die(d2)
                d_2.roll(md)
                for r in 'SSSS':
                    dice_set_02.add(tuple(d_2.roll(r)))
            if dice_set_01 - dice_set_02 == set():
                return False
    return True


print(['No', 'Yes'][search()])

Solution (Python):
import math


class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def roll_east(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def roll_north(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def roll_south(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def roll_west(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def spin_left(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp

    def check(self, dice2):
        ans = False
        for x in range(4):
            if dice2.south == self.south:
                if dice2.east == self.east and dice2.west == self.west and \
                        dice2.north == self.north and dice2.bottom == self.bottom:
                    ans = True
            self.spin_left()
        return ans

    def top_check(self, dice2):
        ans = False
        if dice2.top == self.top:
            ans |= self.check(dice2)
        if dice2.top == self.south:
            self.roll_north()
            ans |= self.check(dice2)
        if dice2.top == self.east:
            self.roll_west()
            ans |= self.check(dice2)
        if dice2.top == self.west:
            self.roll_east()
            ans |= self.check(dice2)
        if dice2.top == self.north:
            self.roll_south()
            ans |= self.check(dice2)
        if dice2.top == self.bottom:
            self.roll_south()
            self.roll_south()
            ans |= self.check(dice2)
        return ans


num = int(input())
dices = []
ans = True
for x in range(num):
    a, b, c, d, e, f = map(int, input().split())
    dices.append(Dice(a, b, c, d, e, f))
for x in range(num):
    for y in range(x + 1, num):
        if dices[x].top_check(dices[y]):
            ans = False
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] 
        self.nowkey = 0
        self.c_key = 5
        self.nowval = li[0]
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 
    def operate(self, s):
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = self.c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = self.c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = self.c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = self.c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]
        self.c_key = abs(5 - self.nowkey)
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 

n = int(input())
flag = False
diceval = [[]] * n
for i in range(n):
    diceval[i] = list(map(int, input().split()))
s = 'NNNNWNNNNWNNNNWNNNN'+'NEEEENEEEENEEEENEEEE'+'ENWWWWNWWWWNWWWWNWWWWW'
for j in range(n - 1):
    if flag == True: break
    for k in range(j + 1, n):
        if flag == True: break
        diceA = DICE(li = diceval[j])
        diceB = DICE(li = diceval[k])
        for i in s:
            diceA.operate(i)
            if diceA.distvals == diceB.distvals:
                print('No')
                flag = True
                break
if flag == False:
    print('Yes')

Solution (Python):
class Dice:
        def __init__(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def reset(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def rollE(self):
                temp = self.label[3]
                self.label[3] = self.label[5]
                self.label[5] = self.label[2]
                self.label[2] = self.label[0]
                self.label[0] = temp
        def rollN(self):
                temp = self.label[0]
                self.label[0] = self.label[1]
                self.label[1] = self.label[5]
                self.label[5] = self.label[4]
                self.label[4] = temp
        def rollA(self):
                temp = self.label[3]
                self.label[3] = self.label[4]
                self.label[4] = self.label[2]
                self.label[2] = self.label[1]
                self.label[1] = temp
        def printDice(self):
                print(self.label)

def check(d1, d2):
        for i in range(6):
                if d1.label[i] != d2.label[i]:
                        return False
        return True
        
num = int(input())
diceList = []

for i in range(num):
        diceList.append(Dice(input().split()))

isSame = False

for a in range(num):
        for b in range(a + 1, num):
                for j in range(6):
                        for k in range(4):
                                diceList[a].rollA()
                                if check(diceList[a], diceList[b]):
                                        isSame = True
                                        break
                        if j % 2 == 0:
                                diceList[a].rollE()
                        else:
                                diceList[a].rollN()
                        if isSame:
                                break
                if isSame:
                        break
        if isSame:
                break

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

Solution (Python):
n = int(input())
a = [0] * n
b = 1
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(n - 1):
	for j in range(i + 1, n):
		for k in range(4):
			t = a[i][0]
			a[i][0] = a[i][1]
			a[i][1] = a[i][5]
			a[i][5] = a[i][4]
			a[i][4] = t
			for u in range(4):
				v = a[i][1]
				a[i][1] = a[i][2]
				a[i][2] = a[i][4]
				a[i][4] = a[i][3]
				a[i][3] = v
				if a[i] == a[j]:
					b = 0
		for k in range(4):
			t = a[i][0]
			a[i][0] = a[i][2]
			a[i][2] = a[i][5]
			a[i][5] = a[i][3]
			a[i][3] = t
			for u in range(4):
				v = a[i][1]
				a[i][1] = a[i][2]
				a[i][2] = a[i][4]
				a[i][4] = a[i][3]
				a[i][3] = v
				if a[i] == a[j]:
					b = 0
if b:
	print("Yes")
else:
	print("No")