class Dice:



    def __init__(self):

        # 初期値がない場合

        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定

        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(eval(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] = list(map(int, input().split()))



    flag = 0



    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。

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



def main():

    n = int(eval(input()))

    dices=[]

    same = 0

    for _ in range(n):

        dices.append(list(map(int, input().split())))



    for i in range(n-1):

        for j in range(i+1,n):

            same += check_dice(dices[i], dices[j])

        if same >= 1:

            print('No')

            break



    if same == 0:

        print('Yes')





def check_dice(f, s):

    yes = 0

    for _ in range(4):

        s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]

        for _ in range(4):

            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]

            if f == s:

                yes = 1



    for _ in range(4):

        s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]

        for _ in range(4):

            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]

            if f == s:

                yes = 1



    return yes



if __name__ == '__main__':

    main()

class Dice:
    def __init__(self):
        # 初期値がない場合
        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
        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(eval(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],
        ) = list(map(int, input().split()))
    flag = 0
    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。
    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()

def main():
    n = int(eval(input()))
    dices = []
    same = 0
    for _ in range(n):
        dices.append(list(map(int, input().split())))
    for i in range(n - 1):
        for j in range(i + 1, n):
            same += check_dice(dices[i], dices[j])
        if same >= 1:
            print("No")
            break
    if same == 0:
        print("Yes")


def check_dice(f, s):
    yes = 0
    for _ in range(4):
        s[0], s[2], s[5], s[3] = s[2], s[5], s[3], s[0]
        for _ in range(4):
            s[1], s[2], s[4], s[3] = s[2], s[4], s[3], s[1]
            if f == s:
                yes = 1
    for _ in range(4):
        s[0], s[1], s[5], s[4] = s[1], s[5], s[4], s[0]
        for _ in range(4):
            s[1], s[2], s[4], s[3] = s[2], s[4], s[3], s[1]
            if f == s:
                yes = 1
    return yes


if __name__ == "__main__":
    main()

-class Dice: -    def __init__(self): -        # 初期値がない場合 -        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定 -        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(): +    n = int(eval(input())) +    dices = [] +    same = 0 +    for _ in range(n): +        dices.append(list(map(int, input().split()))) +    for i in range(n - 1): +        for j in range(i + 1, n): +            same += check_dice(dices[i], dices[j]) +        if same >= 1: +            print("No") +            break +    if same == 0: +        print("Yes") -def main(): -    import random - -    n = int(eval(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], -        ) = list(map(int, input().split())) -    flag = 0 -    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。 -    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") +def check_dice(f, s): +    yes = 0 +    for _ in range(4): +        s[0], s[2], s[5], s[3] = s[2], s[5], s[3], s[0] +        for _ in range(4): +            s[1], s[2], s[4], s[3] = s[2], s[4], s[3], s[1] +            if f == s: +                yes = 1 +    for _ in range(4): +        s[0], s[1], s[5], s[4] = s[1], s[5], s[4], s[0] +        for _ in range(4): +            s[1], s[2], s[4], s[3] = s[2], s[4], s[3], s[1] +            if f == s: +                yes = 1 +    return yes