class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
        self.t = dice[0]
        self.s = dice[1]
        self.e = dice[2]
        self.w = dice[3]
        self.n = dice[4]
        self.b = dice[5]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]
    def spin(self):
        self.dice[1] = self.buff[3]
        self.dice[2] = self.buff[1]
        self.dice[4] = self.buff[2]
        self.dice[3] = self.buff[4]
        self.buff = [n for n in self.dice]
    def to_be_the_same_direction(self, anotherDice):
        if self.t == anotherDice.t:
            pass
        elif self.t == anotherDice.e:
            anotherDice.west()
        elif self.t == anotherDice.w:
            anotherDice.east()
        elif self.t == anotherDice.n:
            anotherDice.south()
        elif self.t == anotherDice.s:
            anotherDice.north()
        else:
            anotherDice.north()
            anotherDice.north()
    def isSameDice(self, anotherDice):
        if  self.dice[0] == anotherDice.dice[0] and \
            self.dice[1] == anotherDice.dice[1] and \
            self.dice[2] == anotherDice.dice[2] and \
            self.dice[3] == anotherDice.dice[3] and \
            self.dice[4] == anotherDice.dice[4] and \
            self.dice[5] == anotherDice.dice[5]:
                return True
        return False
    def compare(self, anotherDice):
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.west()
        self.west()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()
        return False

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

flag = True
for i in range(n):
    for j in range(i+1, n):
        if dices[i].compare(dices[j]):
            flag = False

if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5632