Problem:
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I , and determines whether they are all different. For the determination, use the same way as Dice III . Input In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III . Output Print " Yes " if given dices are all different, otherwise " No " in a line. Constraints  $2 \leq n \leq 100$  $0 \leq $ the integer assigned to a face $ \leq 100$  Sample Input 1 3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1 Sample Output 1 No Sample Input 2 3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6 Sample Output 2 Yes

Solution (Python):
class Dice(object):
 
    def __init__(self, d):

        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]
 
    def move_next_rows(self):
        temp = self.rows.pop(0)
        self.rows.append(temp)
        self.__update(self.cols, self.rows)

    def move_prev_rows(self):
        temp = self.rows.pop(3)
        self.rows.insert(0, temp)
        self.__update(self.cols, self.rows)
    
    def move_next_cols(self):
        temp = self.cols.pop(0)
        self.cols.append(temp)
        self.__update(self.rows, self.cols)
 
    def move_prev_cols(self):
        temp = self.cols.pop(3)
        self.cols.insert(0, temp)
        self.__update(self.rows, self.cols)

    def __update(self, x, y):
        x[0] = y[0]
        x[2] = y[2]
 
class DiceChecker(object):

    def __init__(self, dice1, dice2):
        self.dice1 = dice1
        self.dice2 = dice2
        self.dice1_top = self.dice1.rows[0]
        self.dice1_front = self.dice1.rows[3]
        
    def check_same_dice(self):
        for _ in range(4):
            for _ in range(4):
                for _ in range(4):
                    is_same_element = self.dice1.rows == self.dice2.rows and self.dice1.cols == self.dice2.cols
                    if is_same_element: 
                        return True
                    self.__rot(self.dice2)
                self.dice2.move_next_rows()
            self.dice2.move_next_cols()
            
        return False
    
    def __rot(self, dice):
        temp = dice.rows[1]
        dice.rows[1] = dice.cols[3]
        dice.cols[3] = dice.rows[3]
        dice.rows[3] = dice.cols[1]
        dice.cols[1] = temp


j = int(input())
dice_list = []
src = []
for _ in range(j):
    d = list(map(int, input().split(" ")))
    dice_list.append(Dice(d))
    src.append(Dice(d))

is_diff = 0
for dice1 in dice_list:
    src.pop(0)
    for dice in src:
        dice_checker = DiceChecker(dice1, dice)
        if(dice_checker.check_same_dice()):
            is_diff += 1

if is_diff > 0:
    print("No")
else:
    print("Yes")

Solution (Python):
class Daise:
    def __init__(self, info_list):
        self.T = info_list[0]
        self.S = info_list[1]
        self.E = info_list[2]
        self.W = info_list[3]
        self.N = info_list[4]
        self.B = info_list[5]
    
    def change(self, axis):
        if axis == 'S':
            self.T, self.B, self.S, self.N = self.N, self.S, self.T, self.B
        
        elif axis == 'E':
            self.T, self.B, self.E, self.W = self.W, self.E, self.T, self.B
        
        elif axis == 'W':
            self.T, self.B, self.W, self.E = self.E, self.W, self.T, self.B
        
        elif axis == 'N':
            self.T, self.B, self.N, self.S = self.S, self.N, self.T, self.B
        
        elif axis == 'Turn':
            self.S, self.E, self.N, self.W = self.E, self.N, self.W, self.S
    

    def output(self):
        return [self.T, self.S, self.E, self.W, self.N, self.B]
    

    def set_info(self, top, front):
        if front in (self.T, self.B):
            self.change("S")

        while self.S != front:
            self.change('Turn')
 
        while self.T != top:
            self.change('E')


def compair(A, B):
    for _ in range(4):
        for _ in range(4):
            if A.output() == B.output():
                return 'Yes'
            for _ in range(4):
                if A.output() == B.output():
                    return 'Yes'
                B.change('Turn')
            B.change('S')
        B.change('W')
    return 'No'


if __name__ == '__main__':
    inputs = int(input())
    
    all_daise = [Daise(list(map(str, input().split()))) for _ in range(inputs)]
    result = [compair(all_daise[0], i) for i in all_daise[1:]]

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

Solution (Python):
class Dice:
    def __init__(self, dice: list):
        self.top = dice[0]
        self.bottom = dice[5]
        self.front = dice[1]
        self.behind = dice[4]
        self.right = dice[2]
        self.left = dice[3]

    def __eq__(self, other):
        if not isinstance(other, Dice):
            return NotImplemented
        return self.top == other.top and self.bottom == other.bottom and self.front == other.front \
                and self.behind == other.behind and self.right == other.right and self.left == other.left

    def roll(self, direction: str):
        buffer = self.top
        if direction == 'E':
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = buffer
        elif direction == 'N':
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.behind
            self.behind = buffer
        elif direction == 'S':
            self.top = self.behind
            self.behind = self.bottom
            self.bottom = self.front
            self.front = buffer
        else:
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = buffer

    def turn(self):
        buffer = self.front
        self.front = self.right
        self.right = self.behind
        self.behind = self.left
        self.left = buffer


def main():
    dices = [Dice(list(map(int, input().split()))) for _ in range(int(input()))]
    for index, dice1 in enumerate(dices[:-1]):
        for dice2 in dices[index+1:]:
            for _ in range(2):
                for _ in range(4):
                    for _ in range(4):
                        if dice1 == dice2:
                            print('No')
                            return
                        dice2.turn()
                    dice2.roll('N')
                dice2.roll('E')
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
class Dice:

    def __init__(self):
        
        
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        

def main():
    import random

    n = int(input())
    diceList = [[0 for _ in range(6)] for _ in range(n)]
    for i in range(n):
        diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5] = map(int, input().split())

    flag = 0

    
    for i in range(1, n):
        if flag == 1:
            break
        else:
            dice_a = Dice(diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5])
            for j in range(i):
                dice_b = Dice(diceList[j][0],diceList[j][1],diceList[j][2],diceList[j][3],diceList[j][4],diceList[j][5])

                for _ in range(200):
                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (dice_b.t, dice_b.s, dice_b.e, dice_b.w, dice_b.n, dice_b.b):
                        flag = 1
                        break
                    else:
                        seed = random.randint(0, 3)
                        dice_a.rot(seed)

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



if __name__ == '__main__':
    main()

Solution (Python):
class Dice:

    def __init__(self):
        
        
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        

def main():
    import random

    n = int(input())
    diceList = [[0 for _ in range(6)] for _ in range(n)]
    for i in range(n):
        diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5] = map(int, input().split())

    flag = 0

    
    for i in range(1, n):
        if flag == 1:
            break
        else:
            dice_a = Dice(diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5])
            for j in range(i):
                dice_b = Dice(diceList[j][0],diceList[j][1],diceList[j][2],diceList[j][3],diceList[j][4],diceList[j][5])

                for _ in range(200):
                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (dice_b.t, dice_b.s, dice_b.e, dice_b.w, dice_b.n, dice_b.b):
                        flag = 1
                        break
                    else:
                        seed = random.randint(0, 3)
                        dice_a.rot(seed)

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



if __name__ == '__main__':
    main()

Solution (Python):
class Dice:

    def __init__(self):
        
        
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        

def main():
    import random

    n = int(input())
    diceList = [[0 for _ in range(6)] for _ in range(n)]
    for i in range(n):
        diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5] = map(int, input().split())

    flag = 0

    
    for i in range(1, n):
        if flag == 1:
            break
        else:
            dice_a = Dice(diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5])
            for j in range(i):
                dice_b = Dice(diceList[j][0],diceList[j][1],diceList[j][2],diceList[j][3],diceList[j][4],diceList[j][5])

                for _ in range(50):
                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (dice_b.t, dice_b.s, dice_b.e, dice_b.w, dice_b.n, dice_b.b):
                        flag = 1
                        break
                    else:
                        seed = random.randint(0, 3)
                        dice_a.rot(seed)

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



if __name__ == '__main__':
    main()

Solution (Python):
class Dice:

    def __init__(self):
        
        
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        

def main():
    import random

    n = int(input())
    diceList = [[0 for _ in range(6)] for _ in range(n)]
    for i in range(n):
        diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5] = map(int, input().split())

    flag = 0

    
    for i in range(1, n):
        if flag == 1:
            break
        else:
            dice_a = Dice(diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5])
            for j in range(i):
                dice_b = Dice(diceList[j][0],diceList[j][1],diceList[j][2],diceList[j][3],diceList[j][4],diceList[j][5])

                for _ in range(100):
                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (dice_b.t, dice_b.s, dice_b.e, dice_b.w, dice_b.n, dice_b.b):
                        flag = 1
                        break
                    else:
                        seed = random.randint(0, 3)
                        dice_a.rot(seed)

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



if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    def __init__(self,num):
        self.num = num.copy()
        
    def east(self):
        temp = self.num.copy()
        self.num[1-1] = temp[4-1]
        self.num[4-1] = temp[6-1]
        self.num[6-1] = temp[3-1]
        self.num[3-1] = temp[1-1]

    def north(self):
        temp = self.num.copy()
        self.num[1-1] = temp[2-1]
        self.num[2-1] = temp[6-1]
        self.num[6-1] = temp[5-1]
        self.num[5-1] = temp[1-1]

    def south(self):
        temp = self.num.copy()
        self.num[1-1] = temp[5-1]
        self.num[5-1] = temp[6-1]
        self.num[6-1] = temp[2-1]
        self.num[2-1] = temp[1-1]

    def west(self):
        temp = self.num.copy()
        self.num[1-1] = temp[3-1]
        self.num[3-1] = temp[6-1]
        self.num[6-1] = temp[4-1]
        self.num[4-1] = temp[1-1]

    def right(self):
        temp = self.num.copy()
        self.num[2-1] = temp[4-1]
        self.num[4-1] = temp[5-1]
        self.num[5-1] = temp[3-1]
        self.num[3-1] = temp[2-1]

    def same(self,dice):
        for _ in range(20):
            self.north()
            for _ in range(20):
                self.east()
                for _ in range(20):
                    self.right()
                    if self.num == dice: return True
        return False

diff = True
n = int(input())
dices = []
for _ in range(n):  dices.append(Dice(list(map(int,input().split()))))
for i in dices[1:]: diff = diff and not(dices[0].same(i.num))
if diff: print("Yes")
else: print("No")

Solution (Python):
d=[(0,0,1),(-1,0,0),(0,1,0),(0,-1,0),(1,0,0),(0,0,-1)]
def crosspro(y,x):
    return (y[1]*x[2]-y[2]*x[1],y[2]*x[0]-y[0]*x[2],y[0]*x[1]-y[1]*x[0])
def north(r):
    res=[]
    for p in r:
        res.append((p[2],p[1],-p[0]))
    return res
def south(r):
    res=[]
    for p in r:
        res.append((-p[2],p[1],p[0]))
    return res
def east(r):
    res=[]
    for p in r:
        res.append((p[0],p[2],-p[1]))
    return res
def west(r):
    res=[]
    for p in r:
        res.append((p[0],-p[2],p[1]))
    return res
def left(r):
    res=[]
    for p in r:
        res.append((p[1],-p[0],p[2]))
    return res
def right(r):
    res=[]
    for p in r:
        res.append((-p[1],p[0],p[2]))
    return res
T=["","N","E","W","S","NN"]
U=["","L","LL","LLL"]
def change(S):
    D=d
    for i in S:
        if i=="N":
            D=north(D)
        elif i=="E":
            D=east(D)
        elif i=="W":
            D=west(D)
        elif i=="S":
            D=south(D)
        elif i=="L":
            D=left(D)
        else:
            D=right(D)
    return D
def same(c1,c2):
    for i in T:
        for j in U:
            D=change(i+j)
            flag=0
            for x in range(6):
                for y in range(6):
                    if d[x]==D[y]:
                        if c1[x]!=c2[y]:
                            flag=1
            if flag==0:
                return True
    return False
N=int(input())
c=[[int(i) for i in input().split()] for j in range(N)]
for i in range(N):
    for j in range(N):
        if i<j:
            if same(c[i],c[j]):
                print("No")
                exit()
print("Yes")

Solution (Python):
number = int(input())
dices = []
for i in range(number):
    dices.append(input().split())
    
tf = 0
for i in range(number - 1):
    for j in range(i + 1, number):
        
        dice_1 = dices[i]
        dice_2 = dices[j]
        rolls = {' ':[0, 1, 2, 3, 4, 5], 
                 'W':[2, 1, 5, 0, 4, 3], 
                 'N':[1, 5, 2, 3, 0, 4], 
                 'E':[3, 1, 0, 5, 4, 2], 
                 'S':[4, 0, 2, 3, 5, 1]
                }
        orders = [' ', 'N', 'W', 'E', 'S', 'NN']
        for order in orders:
            copy_2 = dice_2
            for d in order:
                roll = rolls[d]
                copy_2 = [copy_2[i] for i in roll]    
            l = [1, 2, 4, 3]
            a0 = copy_2[0] == dice_1[0]
            a1 = copy_2[5] == dice_1[5]
            a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
            if  a0 and a1 and a2:
                tf += 1
if tf > 0:
    print('No')
else:
    print('Yes')

Solution (Python):
import sys

from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def T(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_T(dice1, dice2) -> bool:
    """横回転させて一致したらTrueを返す."""
    for _i in range(4):
        dice1.T()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False


def is_same_dice(dice1, dice2) -> bool:
    for _i in range(4):
        dice1.S()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    for _i in range(4):
        dice1.E()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    return False



N = int(input())
dices = [Dice([int(j) for j in input().split()]) for i in range(N)]
























for i in range(len(dices) - 1):
    for j in range(i + 1, len(dices)):
        if is_same_dice(dices[i], dices[j]):
            print('No')
            sys.exit()
print('Yes')

Solution (Python):
import sys

from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def T(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_T(dice1, dice2) -> bool:
    """横回転させて一致したらTrueを返す."""
    for _i in range(4):
        dice1.T()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False


def is_same_dice(dice1, dice2) -> bool:
    for _i in range(4):
        dice1.S()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    for _i in range(4):
        dice1.E()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    return False



N = int(input())
dices = [Dice([int(j) for j in input().split()]) for i in range(N)]






for i in range(len(dices) - 1):
    for j in range(i + 1, len(dices)):
        if is_same_dice(dices[i], dices[j]):
            print('No')
            sys.exit()
print('Yes')

Solution (Python):
from copy import deepcopy
from itertools import groupby
import queue
import sys

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

    def isDiceSame(d1, d2):
        if not isinstance(d1, Dice) or not isinstance(d2, Dice):
            return False

        if set(d1.labels[1:]) != set(d2.labels[1:]):
            return False

        else:
            q = ["T", "S", "E", "N", "W", "B"]
            memo = [[False] * 7 for i in range(7)]
            memo[d1.pos["T"]][d1.pos["S"]] = ""
            res = {}
            for i in q[:3]:
                if d1.labels[d1.pos[i]] != d2.labels[d2.pos[i]]:
                    break
            else:
                res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

            def bfs_isDiceSame():
                que = queue.Queue()
                que.put(d1)

                while not que.empty():
                    d = que.get()
                    for i in q[1:5]:
                        d_next = Dice.rolled(d, i)
                        if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                            que.put(d_next)
                            memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                            for j in q[:3]:
                                if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                                    break
                            else:
                                res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next

            bfs_isDiceSame()
            if len(res) == 0:
                return False
            else:
                for k, v in res.items():
                    for i in q[3:]:
                        if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                            break
                    else:
                        return True
                else:
                    return False

n = int(sys.stdin.readline().rstrip())
d_nums = [tuple([int(x) for x in sys.stdin.readline().rstrip().split()]) for _ in range(n)]

if len(d_nums) != len(set(d_nums)):
    print("No")
else:
	
    def var(data):
        ava = sum(data)/len(data)
        return sum([(ava-data[i])**2 for i in range(len(data))])/len(data)

    d_nums.sort(key=lambda t: sum(t))
    d_nums.sort(key=lambda t: var(t))
    for (_, g) in groupby(d_nums, key=lambda t: var(t)):
        gl = list(g)
        if len(gl) == 1:
            continue
        else:
            for i in range(len(gl)):
                for j in range(i+1, len(gl)):
                    if Dice.isDiceSame(Dice(gl[i]), Dice(gl[j])):
                        print("No")
                        sys.exit()
    else:
        print("Yes")

Solution (Python):
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face
  def check_face(self, face1):
    for i in range(4):
      if face1 == self.face:
        return self.face
      else:
        self.face[1],self.face[2],self.face[4],self.face[3] = self.face[2],self.face[4],self.face[3],self.face[1]

def comp_dices(dice1,dice2,num):
  for i in range(6):
    dice2.make_dice(num)
    if i == 0:
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 1:
      dice2.move("N")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 2:
      dice2.move("E")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 3:
      dice2.move("S")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 4:
      dice2.move("W")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 5:
      dice2.move("N")
      dice2.move("N")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
      else:
        return False

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

for i in range(n):
  for j in range(i+1,n):
    flag = comp_dices(dice[i],dice[j],num[j])
    if flag:
      break
  if flag:
    break

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