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):
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,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 'N':
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 'S':
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 'W':
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

n = int(input())
dice_list = []
d_list = []
for i in range(n):
    a,b,c,d,e,f = map(int,input().split())
    dice_list.append(Dice(a,b,c,d,e,f))
    d_list.append(Dice(a,b,c,d,e,f))

flag = True
for k in range(n - 1):
    for j in range(k + 1,n):
        for i in 'NNNNWNNNWNNNENNNENNNWNNN':
            d_list[j].roll(i)
            if dice_list[k].face1 == d_list[j].face1 and dice_list[k].face2 == d_list[j].face2 and \
                    dice_list[k].face3 == d_list[j].face3 and dice_list[k].face4 == d_list[j].face4 and \
                    dice_list[k].face5 == d_list[j].face5 and dice_list[k].face6 == d_list[j].face6:
                flag = False
                break
        else:
            continue
        break
    else:
        continue
    break

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

Solution (Python):
ptn=[
  [1,2,3,4,5,6],
  [2,6,3,4,1,5],
  [3,6,5,2,1,4],
  [4,6,2,5,1,3],
  [5,6,4,3,1,2],
  [6,2,4,3,5,1]
]

def diffDice(orgDice, newDice):
  flg = False   
  tmpDice = [0,0,0,0,0,0]
  for i in range(6):
    
    for idx, j in enumerate(ptn[i]):
      tmpDice[idx] = newDice[j-1]

    if orgDice[0] != tmpDice[0] and orgDice[5] != tmpDice[5]:
      continue
    
    if ((orgDice[0] == tmpDice[0] and orgDice[5] != tmpDice[5]) or
     (orgDice[0] != tmpDice[0] and orgDice[5] == tmpDice[5])):
      continue
      
    if (
    (orgDice[1:5] == [tmpDice[1],tmpDice[2],tmpDice[3],tmpDice[4]]) or 
    (orgDice[1:5] == [tmpDice[3],tmpDice[1],tmpDice[4],tmpDice[2]]) or 
    (orgDice[1:5] == [tmpDice[2],tmpDice[4],tmpDice[1],tmpDice[3]]) or 
    (orgDice[1:5] == [tmpDice[4],tmpDice[3],tmpDice[2],tmpDice[1]])): 
      flg = True
      break
  return flg
    

n = int(input())
dice1 = list(input().split(" "))
flg=False
for i in range(1,n):
  dice2 = list(input().split(" "))
  flg = diffDice(dice1,dice2)
  if flg == True:
    break

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

Solution (Python):
class Dice():

    def __init__(self, dice_list):
        self.state = [0 for _ in range(6)]
        self.state[0] = dice_list[0]
        self.state[1] = dice_list[1]
        self.state[2] = dice_list[2]
        self.state[3] = dice_list[3]
        self.state[4] = dice_list[4]
        self.state[5] = dice_list[5]

    def north(self):
        tmp = self.state[0]
        self.state[0] = self.state[1]
        self.state[1] = self.state[5]
        self.state[5] = self.state[4]
        self.state[4] = tmp

    def west(self):
        tmp = self.state[0]
        self.state[0] = self.state[2]
        self.state[2] = self.state[5]
        self.state[5] = self.state[3]
        self.state[3] = tmp

    def south(self):
        tmp = self.state[0]
        self.state[0] = self.state[4]
        self.state[4] = self.state[5]
        self.state[5] = self.state[1]
        self.state[1] = tmp


    def east(self):
        tmp = self.state[0]
        self.state[0] = self.state[3]
        self.state[3] = self.state[5]
        self.state[5] = self.state[2]
        self.state[2] = tmp

    
if __name__ == '__main__':
    def is_same(dice_num1, dice_num2):
        dice1 = Dice(dice_num1)

        flag = False
        dice2 = Dice(dice_num2)
        for i in range(4):
            for j in range(4):
                if dice1.state[1] == dice2.state[1]:
                    flag = True
                    break
                dice2.east()

            if dice1.state[1] == dice2.state[1]:
                flag = True
                break

            dice2.north()

        if flag == False:
            dice2 = Dice(dice_num2)
            dice2.west()
            dice2.south()
            for i in range(4):
                if dice1.state[1] == dice2.state[1]:
                    flag = True
                    break
                dice2.west()

        if flag == False:
            dice2 = Dice(dice_num2)
            dice2.east()
            dice2.south()
            for i in range(4):
                if dice1.state[1] == dice2.state[1]:
                    break
                dice2.west()

        ans = 'No'
        for i in range(4):
            if dice1.state == dice2.state:
                ans = 'Yes'
                break
            dice2.west()

        if ans == 'Yes':
            return True
        else:
            return False

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

    answer = 'Yes'
    for i in range(N):
        for j in range(N):
            if i != j:
                if is_same(L[i], L[j]):
                    answer = 'No'
        
        
    print(answer)

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])
        else:
            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])
            flag = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    flag = False
                    break
            if flag == True:
                return True
        
        return ret
          

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

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

flag = True

for i in range(n-1):
    for k in range(i+1, n):
        if DICE[i].equals(DICE[k]) ==True:
            flag = False
            break

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

Solution (Python):
import enum
class Direction(enum.Enum):
    N = "N"
    E = "E"
    W = "W"
    S = "S"

    @classmethod
    def value_of(cls, value):
        return [v for v in cls if v.value == value][0]


class Dice:
    def __init__(self, *value_list):
        self.__value_list = list(value_list)

    def rotate(self, direction):
        l = self.__value_list
        if  direction == Direction.N:
            l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0]
        elif  direction == Direction.E:
            l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5]
        elif  direction == Direction.W:
            l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0]
        elif  direction == Direction.S:
            l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5]

    def adjust_top_front(self, top_value, front_value):
        for _ in range(2):
            for _ in range(3):
                if self.front_value() == front_value:
                    break
                self.rotate(Direction.N)
            if self.front_value() == front_value:
                break
            self.rotate(Direction.E)
        
        for _ in range(3):
            if self.top_value() == top_value:
                break
            self.rotate(Direction.E)
    
    def is_same_dice(self, othere_dice):
        return (self.top_value() == othere_dice.top_value()
        and self.bottom_value() == othere_dice.bottom_value()
        and self.front_value() == othere_dice.front_value()
        and self.behind_value() == othere_dice.behind_value()
        and self.right_value() == othere_dice.right_value()
        and self.left_value() == othere_dice.left_value())

    def top_value(self):
        return self.__value_list[0]

    def bottom_value(self):
        return self.__value_list[5]

    def front_value(self):
        return self.__value_list[1]

    def behind_value(self):
        return self.__value_list[4]

    def right_value(self):
        return self.__value_list[2]

    def left_value(self):
        return self.__value_list[3]


is_all_different = True
for i in range(int(input())):
    dice_x = Dice(*input().split())
    if i == 0:
        dice1 = dice_x
    else:
        dice_x.adjust_top_front(dice1.top_value(), dice1.front_value())
        if dice1.is_same_dice(dice_x):
            is_all_different = False
            break

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

Solution (Python):
class dice():
    top = 1
    flont = 2
    right = 3
    def do_N(self):
        temp = self.flont
        self.flont = 7-self.top
        self.top = temp

    def do_S(self):
        temp = 7-self.flont
        self.flont = self.top
        self.top = temp

    def do_E(self):
        temp = self.top
        self.top = 7-self.right
        self.right = temp

    def do_W(self):
        temp = 7-self.top
        self.top = self.right
        self.right = temp
        
        
n = int(input())
num = [[0]*6 for i in range(n)]
dice_list = []*n
flag = [0]*n

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

for i in range(1, n):
    if num[0][dice_list[0].flont-1] == num[i][dice_list[i].flont-1] and num[0][dice_list[0].top-1] == num[i][dice_list[i].top-1] and num[0][dice_list[0].right-1] == num[i][dice_list[i].right-1] and num[0][7-dice_list[0].top-1] == num[i][7-dice_list[i].top-1] and num[0][7-dice_list[0].flont-1] == num[i][7-dice_list[i].flont-1] and num[0][7-dice_list[0].right-1] == num[i][7-dice_list[i].right-1]:
        flag[i] = 1
    for j in range(4):
        for k in range(4):
            dice_list[i].do_E()
            if num[0][dice_list[0].flont-1] == num[i][dice_list[i].flont-1] and num[0][dice_list[0].top-1] == num[i][dice_list[i].top-1] and num[0][dice_list[0].right-1] == num[i][dice_list[i].right-1] and num[0][7-dice_list[0].top-1] == num[i][7-dice_list[i].top-1] and num[0][7-dice_list[0].flont-1] == num[i][7-dice_list[i].flont-1] and num[0][7-dice_list[0].right-1] == num[i][7-dice_list[i].right-1]:
                flag[i] = 1
        dice_list[i].do_N()
        if num[0][dice_list[0].flont-1] == num[i][dice_list[i].flont-1] and num[0][dice_list[0].top-1] == num[i][dice_list[i].top-1] and num[0][dice_list[0].right-1] == num[i][dice_list[i].right-1] and num[0][7-dice_list[0].top-1] == num[i][7-dice_list[i].top-1] and num[0][7-dice_list[0].flont-1] == num[i][7-dice_list[i].flont-1] and num[0][7-dice_list[0].right-1] == num[i][7-dice_list[i].right-1]:
            flag[i] = 1    
    dice_list[i].do_S()
    dice_list[i].do_E()
    if num[0][dice_list[0].flont-1] == num[i][dice_list[i].flont-1] and num[0][dice_list[0].top-1] == num[i][dice_list[i].top-1] and num[0][dice_list[0].right-1] == num[i][dice_list[i].right-1] and num[0][7-dice_list[0].top-1] == num[i][7-dice_list[i].top-1] and num[0][7-dice_list[0].flont-1] == num[i][7-dice_list[i].flont-1] and num[0][7-dice_list[0].right-1] == num[i][7-dice_list[i].right-1]:
        flag[i] = 1
    for j in range(4):
        for k in range(4):
            dice_list[i].do_E()
            if num[0][dice_list[0].flont-1] == num[i][dice_list[i].flont-1] and num[0][dice_list[0].top-1] == num[i][dice_list[i].top-1] and num[0][dice_list[0].right-1] == num[i][dice_list[i].right-1] and num[0][7-dice_list[0].top-1] == num[i][7-dice_list[i].top-1] and num[0][7-dice_list[0].flont-1] == num[i][7-dice_list[i].flont-1] and num[0][7-dice_list[0].right-1] == num[i][7-dice_list[i].right-1]:
                flag[i] = 1
        dice_list[i].do_N()
        if num[0][dice_list[0].flont-1] == num[i][dice_list[i].flont-1] and num[0][dice_list[0].top-1] == num[i][dice_list[i].top-1] and num[0][dice_list[0].right-1] == num[i][dice_list[i].right-1] and num[0][7-dice_list[0].top-1] == num[i][7-dice_list[i].top-1] and num[0][7-dice_list[0].flont-1] == num[i][7-dice_list[i].flont-1] and num[0][7-dice_list[0].right-1] == num[i][7-dice_list[i].right-1]:
            flag[i] = 1

if max(flag) == 1:
    print("No")
else:
    print("Yes")

Solution (Python):

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

R1 = [
    [0, 1, 2, 3, 4, 5], 
    [3, 1, 0, 5, 4, 2], 
    [2, 1, 5, 0, 4, 3], 
    [4, 0, 2, 3, 5, 1], 
    [1, 5, 2, 3, 0, 4], 
    [5, 4, 2, 3, 1, 0]  
]

R2 = [0, 3, 1, 4, 2, 5] 

ans = 'Yes'

for i in range(N):
    for j in range(i + 1, N):
        for r1 in R1:
            dice = [dices[j][k] for k in r1]
            for _ in range(4):
                dice = [dice[l] for l in R2]
                if dices[i] == dice:
                    ans = 'No'

print(ans)

Solution (Python):
class Dice:
    def __init__(self, num):
        self.num = num
    def roll(self, fn):
        if fn == "S":
            ue = self.num[4]
            self.num[4] = self.num[5]
            self.num[5] = self.num[1]
            self.num[1] = self.num[0]
            self.num[0] = ue
        elif fn == "W":
            ue = self.num[2]
            self.num[2] = self.num[5]
            self.num[5] = self.num[3]
            self.num[3] = self.num[0]
            self.num[0] = ue        
        elif fn == "N":
            ue = self.num[1]
            self.num[1] = self.num[5]
            self.num[5] = self.num[4]
            self.num[4] = self.num[0]
            self.num[0] = ue                
 
    def spin(self, fn):
        if fn == "migi":
            mae = self.num[3]
            self.num[3] = self.num[4]
            self.num[4] = self.num[2]
            self.num[2] = self.num[1]
            self.num[1] = mae

n = int(input())
dice = []
for i in range(n):
    num = list(map(int, input().split(" ")))
    dice.append(Dice(num))
for i in range(1, n):
    count = 0
    while dice[0].num[0] != dice[i].num[0] and count<5:
        dice[i].roll("S")
        count+=1
    count = 0
    while dice[0].num[0] != dice[i].num[0] and count<5:
        dice[i].roll("W")
        count+=1       
    count = 0
    while dice[0].num[1] != dice[i].num[1] and count<5:
        dice[i].spin("migi")
        count+= 1
count = 0
for i in range(0, len(dice)-1):
    for j in range(1, len(dice)):
        if dice[i].num == dice[j].num:
            count += 1
if count > n-2:
    print("No")
else:
    print("Yes")

Solution (Python):
def Roll(c, lst) :
    if c == 'N' :
        lst[0], lst[1], lst[5], lst[4] = lst[1], lst[5], lst[4], lst[0]
    elif c == 'S' :
        lst[0], lst[1], lst[5], lst[4] = lst[4], lst[0], lst[1], lst[5]
    elif c == 'E' :
        lst[0], lst[2], lst[5], lst[3] = lst[3], lst[0], lst[2], lst[5]
    elif c == 'W' :
        lst[0], lst[2], lst[5], lst[3] = lst[2], lst[5], lst[3], lst[0]
    return lst
    

def Comp_Dice(dice_A, dice_B) :
    for i in range(4) :
        if dice_B[1] == dice_A[1] :
            break
        else :
            Roll('S', dice_B)
    if dice_B[1] != dice_A[1] :
        Roll('E', dice_B)
        for i in range(4) :
            if dice_B[1] == dice_A[1] :
                break
            else :
                Roll('S', dice_B)
    for i in range(4) :
        if dice_B[0] == dice_A[0] :
            break
        else :
            Roll('E', dice_B)

    if dice_B[0] == dice_A[0] and dice_B[1] == dice_A[1] and dice_B[2] == dice_A[2] and dice_B[3] == dice_A[3] and dice_B[4] == dice_A[4] and dice_B[5] == dice_A[5] :
        return "Same"
    else :
        return "Different"
        
import copy
ans = "Yes"
N = int(input())
dice_X = list(map(int, input().split()))
for i in range(N-1) :
    dice_Y = list(map(int, input().split()))
    if Comp_Dice(dice_X, dice_Y) == "Same" :
        ans = "No"
        break

print(ans)

Solution (Python):
class Dice:
    def __init__(self, top: str, front: str, right: str, left: str, back: str, bottom: str) -> None:
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.back = back
        self.bottom = bottom

    def __eq__(self, other) -> bool:
        for directions in ['', 'N', 'SE', 'WW', 'ES', 'S']:
            for direction in directions:
                other.roll(direction)

            for _ in range(4):
                other.rotate_right()
                if (
                        self.top == other.top
                        and self.front == other.front
                        and self.back == other.back
                        and self.right == other.right
                        and self.left == other.left
                        and self.bottom == other.bottom
                ):
                    return True
        return False

    def print_top(self):
        print(self.top)

    def print_right(self):
        print(self.right)

    def roll(self, direction: str) -> None:
        if direction == 'S':
            self.south()
        elif direction == 'N':
            self.north()
        elif direction == 'E':
            self.east()
        elif direction == 'W':
            self.west()

    def north(self):
        [self.top, self.back, self.bottom, self.front] = [self.front, self.top, self.back, self.bottom]

    def south(self):
        [self.top, self.back, self.bottom, self.front] = [self.back, self.bottom, self.front, self.top]

    def east(self):
        [self.top, self.right, self.bottom, self.left] = [self.left, self.top, self.right, self.bottom]

    def west(self):
        [self.top, self.right, self.bottom, self.left] = [self.right, self.bottom, self.left, self.top]

    def rotate_right(self) -> None:
        for direction in 'SWN':
            self.roll(direction)


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

dice1 = dices[0]
all_different = all(map(lambda dice: dice != dice1, dices[1:]))
if all_different:
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice():
    def __init__(self, a, b, c, d, e, f):
        """面の数字とindexを一致させるために0を挿入"""
        self.s = [0, a, b, c, d, e, f]

    def rotate(self, dir):
        if dir == "N":
            self.s[0] = self.s[1] 
            self.s[1] = self.s[2] 
            self.s[2] = self.s[6]
            self.s[6] = self.s[5]
            self.s[5] = self.s[0]
            return

        elif dir == "W":
            self.s[0] = self.s[1]
            self.s[1] = self.s[3] 
            self.s[3] = self.s[6]
            self.s[6] = self.s[4]
            self.s[4] = self.s[0]
            return

        elif dir == "S":
            self.s[0] = self.s[1]
            self.s[1] = self.s[5] 
            self.s[5] = self.s[6]
            self.s[6] = self.s[2]
            self.s[2] = self.s[0]
            return

        elif dir == "E":
            self.s[0] = self.s[1]
            self.s[1] = self.s[4] 
            self.s[4] = self.s[6]
            self.s[6] = self.s[3]
            self.s[3] = self.s[0]
            return
        
        elif dir == "R":
            self.s[0] = self.s[2]
            self.s[2] = self.s[3] 
            self.s[3] = self.s[5]
            self.s[5] = self.s[4]
            self.s[4] = self.s[0]
            return

        else:
            return

    def equal(self, dice2):
        FLG = False
        if set(self.s[1:]) != set(dice2.s[1:]):
            pass 

        elif self.s[1:] != dice2.s[1:]:
            for _ in range(3):
                if self.s[1:] != dice2.s[1:]:
                    for __ in range(4):
                        if self.s[1:] != dice2.s[1:]:
                            dice2.rotate("R")
                        else:
                            FLG = True
                            break
                    if FLG:
                        break

                    dice2.rotate("S")
                    for __ in range(4):
                        if self.s[1:] != dice2.s[1:]:
                            dice2.rotate("R")
                        else:
                            FLG = True
                            break
                    if FLG:
                        break
                    dice2.rotate("E")
                else:
                    FLG = True 
                if FLG:
                    break
        else:
            FLG = True

        return FLG

n = int(input())
*dices, = [Dice(*map(int, input().split())) for _ in range(n)]
FLG = True

for i in range(n):
    for j in range(i+1, n):
        if dices[i].equal(dices[j]):
            FLG = False
            break
    if not FLG:
        break

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

Solution (Python):
class Dice(object):
    def __init__(self, init_numbers: list):
        self.numbers = dict(zip(("T", "S", "E", "W", "N", "B"), init_numbers))

    def _roll(self, old_part: tuple):
        new_part = old_part[1:] + (old_part[0],)
        new_numbers = [self.numbers[face] for face in new_part]

        for old, new in zip(old_part, new_numbers):
            self.numbers[old] = new

    def vroll(self, reverse=False):
        """北方向に回転"""
        old_part = ("N", "T", "S", "B")
        self._roll(old_part if not reverse else old_part[::-1])

    def hroll(self, reverse=False):
        """時計回りに回転"""
        old_part = ("N", "W", "S", "E")
        self._roll(old_part if not reverse else old_part[::-1])

    def roll_to(self, direction: str):

        if direction == "N":
            self.vroll()
        elif direction == "S":
            self.vroll(reverse=True)
        elif direction == "E":
            self.hroll(reverse=True)
            self.vroll()
            self.hroll()
        elif direction == "W":
            self.hroll()
            self.vroll()
            self.hroll(reverse=True)
        else:
            raise AssertionError


def is_same(dice1: Dice, dice2: Dice):

    result = False

    for direction in ["N", "E"] * 3:
        dice1.roll_to(direction)
        for _ in range(4):
            result |= dice1.numbers == dice2.numbers
            dice1.hroll()

    return result


if __name__ == "__main__":
    from itertools import combinations

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

    all_different = True
    for i, j in combinations(dices, r=2):
        all_different &= not is_same(i, j)

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

Solution (Python):
import copy


class Dice:
    def __init__(self, one: int, two: int, three: int, four: int, five: int, six: int) -> None:
        self.__one = one
        self.__two = two
        self.__three = three
        self.__four = four
        self.__five = five
        self.__six = six

    def roll(self, direction) -> None:
        if direction == "N":
            tmp = self.__one
            self.__one = self.__two
            self.__two = self.__six
            self.__six = self.__five
            self.__five = tmp

        if direction == "E":
            tmp = self.__one
            self.__one = self.__four
            self.__four = self.__six
            self.__six = self.__three
            self.__three = tmp

        if direction == "S":
            tmp = self.__one
            self.__one = self.__five
            self.__five = self.__six
            self.__six = self.__two
            self.__two = tmp

        if direction == "W":
            tmp = self.__one
            self.__one = self.__three
            self.__three = self.__six
            self.__six = self.__four
            self.__four = tmp

        if direction == "I":
            tmp = self.__one
            self.__one, self.__six = self.__six, self.__one
            self.__two, self.__five = self.__five, self.__two

    def set_top(self, top: int) -> bool:
        if self.__one != top:
            for i in range(3):
                self.roll("N")
                if (self.__one == top):
                    break
        if self.__one != top:
            for i in range(3):
                self.roll("E")
                if (self.__one == top):
                    break
        return self.__one == top

    def rotate(self) -> None:
        tmp = self.__two
        self.__two = self.__four
        self.__four = self.__five
        self.__five = self.__three
        self.__three = tmp

    def check(self, dice) -> bool:
        flag = True
        if self.__one != dice.__one:
            flag = False
        if self.__two != dice.__two:
            flag = False
        if self.__three != dice.__three:
            flag = False
        if self.__four != dice.__four:
            flag = False
        if self.__five != dice.__five:
            flag = False
        if self.__six != dice.__six:
            flag = False
        return flag

    @property
    def top(self) -> int:
        return self.__one

    @property
    def front(self) -> int:
        return self.__two

    @property
    def right(self) -> int:
        return self.__three

    @property
    def left(self) -> int:
        return self.__four

    @property
    def back(self) -> int:
        return self.__five

    @property
    def bottom(self) -> int:
        return self.__six


if __name__ == "__main__":
    n = int(input())
    dice_list = []
    for i in range(n):
        dice_item = list(map(int, input().split(' ')))
        dice_list.append(dice_item)

    for i in range(n-1):
        dice1_one, dice1_two, dice1_three, dice1_four, dice1_five, dice1_six = dice_list[i]
        for j in range(i+1, n):
            dice2_one, dice2_two, dice2_three, dice2_four, dice2_five, dice2_six = dice_list[
                j]

            dice1 = Dice(dice1_one, dice1_two, dice1_three,
                         dice1_four, dice1_five, dice1_six)
            dice2 = Dice(dice2_one, dice2_two, dice2_three,
                         dice2_four, dice2_five, dice2_six)

            directions = ["N", "E", "S", "W", "I"]
            for direction in directions:
                dice = copy.deepcopy(dice1)
                if not (dice1.top == dice2.top and dice1.bottom == dice2.bottom):
                    dice.roll(direction)
                if dice.top == dice2.top and dice.bottom == dice2.bottom:
                    if dice.front != dice2.front:
                        for k in range(3):
                            dice.rotate()
                            if dice.check(dice2):
                                print("No")
                                exit()
                    else:
                        if dice.check(dice2):
                            print("No")
                            exit()
    print("Yes")