# Original solution
import sys
import copy
n = int(eval(input()))
inp = [[i for i in input().split()] for i in range(n)]
a = copy.deepcopy(inp)
number = 3
count = 0
fuck = 0
for i in range(n-3):
    number += 3+i
for i in range(number):
    for i3 in range(n-1):
        if i3 == 0:
            kais = n-1
            sika = kais
            continue
        kais += n-i3
        if i >= sika and i < kais:
            sika = kais
            count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][3])
                b.append(a[i4][1])
                b.append(a[i4][0])
                b.append(a[i4][5])
                b.append(a[i4][4])
                b.append(a[i4][2])
                for ks in range(6):
                    a[i4][ks] = b[ks]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    fuck = 0
                    for x2 in range(6):
                        if inp[count][x2] == a[x][x2]:
                            fuck += 1
                    if  fuck == 6:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][1])
                b.append(a[i4][5])
                b.append(a[i4][2])
                b.append(a[i4][3])
                b.append(a[i4][0])
                b.append(a[i4][4])
                for ks in range(6):
                    a[i4][ks] = b[ks]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    fuck = 0
                    for x2 in range(6):
                        if inp[count][x2] == a[x][x2]:
                            fuck += 1
                    if  fuck == 6:
                        print("No")
                        sys.exit()
print("Yes")

# Optimized solution
import sys
import copy
n = int(eval(input()))
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
for i in range(n-3):
    number += 3+i
for i in range(number):
    for i3 in range(n-1):
        if i3 == 0:
            kais = n-1
            sika = kais
            continue
        kais += n-i3
        if i >= sika and i < kais:
            sika = kais
            count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][3])
                b.append(a[i4][1])
                b.append(a[i4][0])
                b.append(a[i4][5])
                b.append(a[i4][4])
                b.append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][1])
                b.append(a[i4][5])
                b.append(a[i4][2])
                b.append(a[i4][3])
                b.append(a[i4][0])
                b.append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")