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


Measured memory_bytes: 5828