# Original solution
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 22 11:38:11 2015

@author: hirose
"""

# -*- coding: utf-8 -*-

from random import *
import copy

def command(hougaku, label):
    temp = {}
    temp = copy.deepcopy(label)
    if(hougaku == 'E'):
        label[1] = temp[4]
        label[3] = temp[1]
        label[4] = temp[6]
        label[6] = temp[3]
    elif(hougaku == 'W'):
        label[1] = temp[3]
        label[3] = temp[6]
        label[4] = temp[1]
        label[6] = temp[4]
    elif(hougaku == 'N'):
        label[1] = temp[2]
        label[2] = temp[6]
        label[5] = temp[1]
        label[6] = temp[5]
    elif(hougaku == 'S'):
        label[1] = temp[5]
        label[2] = temp[1]
        label[5] = temp[6]
        label[6] = temp[2]

if __name__=="__main__":
    n = eval(input())
    label = {}
    for i in range(n):
        label[i] = {}
        temp = list(map(int, input().split()))
        for j in range(6):
            label[i][j+1] = temp[j]
        #print label[i]
    flag = 0
    for i in range(n-1):
        #print label[i]
        for j in range(i+1,n):
            count = 0
            #print label[j]
            while True:
                if(label[i] == label[j]):
                    flag = 1
                    break
                x = random()
                if(x < 0.25):
                    command('E', label[j])
                elif(x < 0.50):
                    command('W', label[j])
                elif(x < 0.75):
                    command('N', label[j])
                else:
                    command('S', label[j])
                count += 1
                if(count > 100):
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if(flag == 0):
        print('Yes')
    else:
        print('No')

# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 22 11:38:11 2015

@author: hirose
"""

# -*- coding: utf-8 -*-

from random import *
import copy

def command(hougaku, label):
    temp = {}
    temp = copy.deepcopy(label)
    if(hougaku == 'E'):
        label[1] = temp[4]
        label[3] = temp[1]
        label[4] = temp[6]
        label[6] = temp[3]
    elif(hougaku == 'W'):
        label[1] = temp[3]
        label[3] = temp[6]
        label[4] = temp[1]
        label[6] = temp[4]
    elif(hougaku == 'N'):
        label[1] = temp[2]
        label[2] = temp[6]
        label[5] = temp[1]
        label[6] = temp[5]
    elif(hougaku == 'S'):
        label[1] = temp[5]
        label[2] = temp[1]
        label[5] = temp[6]
        label[6] = temp[2]

if __name__=="__main__":
    n = eval(input())
    label = {}
    for i in range(n):
        label[i] = {}
        temp = list(map(int, input().split()))
        for j in range(6):
            label[i][j+1] = temp[j]
        #print label[i]
    flag = 0
    for i in range(n-1):
        #print label[i]
        for j in range(i+1,n):
            count = 0
            #print label[j]
            while True:
                if(label[i] == label[j]):
                    flag = 1
                    break
                x = random()
                if(x < 0.25):
                    command('E', label[j])
                elif(x < 0.50):
                    command('W', label[j])
                elif(x < 0.75):
                    command('N', label[j])
                else:
                    command('S', label[j])
                count += 1
                if(count > 50):
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if(flag == 0):
        print('Yes')
    else:
        print('No')