class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def checksame(self, other_dice):
        self_opposite_face = dict(zip([self.number(i) for i in range(1, 7)],
                                      [self.number(i) for i in range(6, 0, -1)]))
        other_opposite_face = dict(zip([other_dice.number(i) for i in range(1, 7)],
                                       [other_dice.number(i) for i in range(6, 0, -1)]))
        if self_opposite_face != other_opposite_face:
            return False
        if self.number(2) in (other_dice.number(3), other_dice.number(4)):
            other_dice.roll_west()
        while self.number(2) != other_dice.number(2):
            other_dice.roll_north()
        while self.number(1) != other_dice.number(1):
            other_dice.roll_west()
        print(self.faces, other_dice.faces)
        return self.number(3) == other_dice.number(3)

n = int(input())
dice_list = [input().split() for i in range(n)]

for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].checksame(dice_list[j]):
            print("No")
            exit(0)
print("Yes")

### FIXED CODE ###

class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

dice_list = []
n = int(input())
for i in range(n):
    dice_list.append(Dice([int(a) for a in input().split()]))

res = "Yes"
for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].issame(dice_list[j]):
            res = "No"
            break
print(res)