# coding: utf-8
import copy
class Dice:
    
    def __init__(self, d):
        self.data = {"bottom":d[5], "north":d[4], "west": d[3],
                    "east":d[2],"south":d[1],"top":d[0]}

    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self, directions):
        for direction in directions:
            self.moveOne(direction)
            
    def setDiceII(self, a, b):
        if self.data["east"] == a:
            self.moveOne("W")
        elif self.data["north"] == a:
            self.moveOne("S")
        elif self.data["west"] == a:
            self.moveOne("E")
        elif self.data["south"] == a:
            self.moveOne("N")
        elif self.data["bottom"] == a:
            self.movePart("WW")

        if self.data["north"] == b:
            self.rotateRight()
            self.rotateRight()
        elif self.data["east"] == b:
            self.rotateRight()
        elif self.data["west"] == b:
            self.rotateLeft()
            
        # self.printDice()
    
    def rotateRight(self):
        temp = self.data["east"]
        self.data["east"] = self.data["north"]
        self.data["north"] = self.data["west"]
        self.data["west"] = self.data["south"]
        self.data["south"] = temp
    
    def rotateLeft(self):
        temp = self.data["west"]
        self.data["west"] = self.data["north"]
        self.data["north"] = self.data["east"]
        self.data["east"] = self.data["south"]
        self.data["south"] = temp
      
    def getSurface(self):
        return self.data["top"]
    
    def getEast(self):
        return self.data["east"]
    
    def getData(self):
        return self.data
    
    def getPatterns(self):
        patterns = []
        temp0 = copy.copy(self.getData())
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.rotateRight()
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.data = temp0
        return patterns
                

    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])

n = int(input().rstrip())
num = []
dice = []
for i in range(n):
    num.append(list(map(int,input().rstrip().split())))
for i in range(n):
    dice.append(Dice(num[i]))

flag = True
for i in range(n-1):
    for j in range(i+1,n):
        for k in dice[j].getPatterns():
            if dice[i].getData() == k:
                flag = False
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 6376