#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????? 4

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""

class Dice:
    T = 0
    S = 1
    E = 2
    W = 3
    N = 4
    B = 5

    """ ????????????????????? """
    def __init__(self):
        """ ????????????????????? """
        self.side = [1, 2, 3, 4, 5, 6]
        self.top = 0

    def setDice(self, arr):
        """ ??¢?????????????????? """
        self.side = arr[0:6]

    def Turn(self, dir):
        """ ?????????????????¢?????? """
        s = self.side

        if dir == "N":     # ????????¢??????
            #    Top 0     South 1   East 2    West 3    North 4   Bottom 5
            t = [s[Dice.S],s[Dice.B],s[Dice.E],s[Dice.W],s[Dice.T],s[Dice.N]]
        elif dir == "S": # ????????¢??????
            t = [s[Dice.N],s[Dice.T],s[Dice.E],s[Dice.W],s[Dice.B],s[Dice.S]]
        elif dir == "E": # ??±?????¢??????
            t = [s[Dice.W],s[Dice.S],s[Dice.T],s[Dice.B],s[Dice.N],s[Dice.E]]
        elif dir == "W": # ?\??????¢??????
            t = [s[Dice.E],s[Dice.S],s[Dice.B],s[Dice.T],s[Dice.N],s[Dice.W]]
        elif dir == "L": # ???????????¢
            t = [s[Dice.T],s[Dice.W],s[Dice.S],s[Dice.N],s[Dice.E],s[Dice.B]]
        elif dir == "R": # ???????????¢
            t = [s[Dice.T],s[Dice.E],s[Dice.N],s[Dice.S],s[Dice.W],s[Dice.B]]

        self.side = t
#        print("{0} T0:{1} S1:{2} W2:{3} E3:{4} N4:{5} B5:{6} ".format(dir, self.side[0],self.side[1], self.side[2],self.side[3], self.side[4],self.side[5]))

    def Search(self, tval, sval, dir):
    """ ?????¢??¨?????¢???????????????????????????????????¢??????????????? """
    
#        print("{0} T0:{1} S1:{2} W2:{3} E3:{4} N4:{5} B5:{6} ".format(dir, self.side[0],self.side[1], self.side[2],self.side[3], self.side[4],self.side[5]))
    
        if self.side[Dice.E] == tval:
            self.Turn("W")
        elif self.side[Dice.W] == tval:
            self.Turn("E")
        elif self.side[Dice.N] == tval:
            self.Turn("S")
        elif self.side[Dice.S] == tval:
            self.Turn("N")
        elif self.side[Dice.B] == tval:
            self.Turn("N")
            self.Turn("N")

        for i in range(3): # ?????¢?????????????????????????????§????????????
            if self.side[Dice.S] == sval:
                break
            self.Turn("L")
            
        return self.side[dir]

# ?????????
d = []
num = int(input().strip())

for i in range(num): # ??????????????????
    tmp = Dice()
    tmp.setDice(list(map(int,input().strip().split())))
    d.append(tmp)

ret = "Yes"

for i in range(num-1):
    for j in range(i + 1,num):
        v1 = d[i].Search(d[i].side[Dice.T], d[i].side[Dice.S], Dice.E)
        v2 = d[j].Search(d[i].side[Dice.T], d[i].side[Dice.S], Dice.E)
#        print("{0}/{1} V1={2} V2={3}".format(i,j,v1,v2))
        if v1 == v2:
            ret = "No"
            break
    if ret == "No":
        break

print(ret)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????? 4

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""

class Dice:
    T = 0
    S = 1
    E = 2
    W = 3
    N = 4
    B = 5

    """ ????????????????????? """
    def __init__(self):
        """ ????????????????????? """
        self.side = [1, 2, 3, 4, 5, 6]
        self.top = 0

    def setDice(self, arr):
        """ ??¢?????????????????? """
        self.side = arr[0:6]

    def Turn(self, dir):
        """ ?????????????????¢?????? """
        s = self.side

        if dir == "N":     # ????????¢??????
            #    Top 0     South 1   East 2    West 3    North 4   Bottom 5
            t = [s[Dice.S],s[Dice.B],s[Dice.E],s[Dice.W],s[Dice.T],s[Dice.N]]
        elif dir == "S": # ????????¢??????
            t = [s[Dice.N],s[Dice.T],s[Dice.E],s[Dice.W],s[Dice.B],s[Dice.S]]
        elif dir == "E": # ??±?????¢??????
            t = [s[Dice.W],s[Dice.S],s[Dice.T],s[Dice.B],s[Dice.N],s[Dice.E]]
        elif dir == "W": # ?\??????¢??????
            t = [s[Dice.E],s[Dice.S],s[Dice.B],s[Dice.T],s[Dice.N],s[Dice.W]]
        elif dir == "L": # ???????????¢
            t = [s[Dice.T],s[Dice.W],s[Dice.S],s[Dice.N],s[Dice.E],s[Dice.B]]
        elif dir == "R": # ???????????¢
            t = [s[Dice.T],s[Dice.E],s[Dice.N],s[Dice.S],s[Dice.W],s[Dice.B]]

        self.side = t
#        print("{0} {1}".format(dir, self.State()))

    def Uturns(self, tval, sval):
        """ ?????¢??¨?????¢???????????????????????????????????§?????¢ """
    
        if self.side[Dice.E] == tval:
            self.Turn("W")
        elif self.side[Dice.W] == tval:
            self.Turn("E")
        elif self.side[Dice.N] == tval:
            self.Turn("S")
        elif self.side[Dice.S] == tval:
            self.Turn("N")
        elif self.side[Dice.B] == tval:
            self.Turn("N")
            self.Turn("N")

        for i in range(3): # ?????¢?????????????????????????????§????????????
            if self.side[Dice.S] == sval:
                break
            self.Turn("L")
            

    def Search(self, tval, sval, dir):
        """ ?????¢??¨?????¢?????????????????????????????¢??????????????? """
        self.Uturns(tval,sval)
        return self.side[dir]

    def State(self):
            return "T0:{0} S1:{1} W2:{2} E3:{3} N4:{4} B5:{5}".format(self.side[0],self.side[1], self.side[2],self.side[3], self.side[4],self.side[5])

# ?????????
d = []
num = int(input().strip())

for i in range(num): # ??????????????????
    tmp = Dice()
    tmp.setDice(list(map(int,input().strip().split())))
    d.append(tmp)

ret = "Yes"

for i in range(num-1):
    for j in range(i + 1,num):
        # ??????????????¢?????°???????????????????¢??????????
        s1 = set(d[i].side)
        s2 = set(d[j].side)
        if (s1 ^ s2): # ??????????????????
            break;

        d[j].Uturns(d[i].side[Dice.T], d[i].side[Dice.S])
        s1 = d[i].State()
        s2 = d[j].State()
        if s1 == s2:
            ret = "No"
            break

    if ret == "No":
        break

print(ret)