class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ in range(6)]
		self.order = "NNNNWNNNWNNNENNNENNNWNNN"
	def setNumber(self,n0,n1,n2,n3,n4,n5):
		self.number[0] = n0
		self.number[1] = n1
		self.number[2] = n2
		self.number[3] = n3
		self.number[4] = n4
		self.number[5] = n5

	def roll(self,loc):
		for _ in range(6):
			self.work[_] = self.number[_]
		if loc == "E":
			self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
		elif loc == "N":
			self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
		elif loc == "S":
			self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
		elif loc == "W":
			self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
	def get_top(self):
		return self.number[0]
	def get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): return(self.number[2])
			elif(n2 == self.number[2]): return(self.number[4])
			elif(n2 == self.number[3]): return(self.number[1])
			elif(n2 == self.number[4]): return(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[0])
                        elif(n2 == self.number[3]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): return(self.number[1])
                        elif(n2 == self.number[1]): return(self.number[5])
                        elif(n2 == self.number[4]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): return(self.number[4])
                        elif(n2 == self.number[1]): return(self.number[0])
                        elif(n2 == self.number[4]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): return(self.number[2])
                        elif(n2 == self.number[2]): return(self.number[5])
                        elif(n2 == self.number[3]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[1])
                        elif(n2 == self.number[3]): return(self.number[4])
                        elif(n2 == self.number[4]): return(self.number[2])

	def equals(self,another):
		ret = False
		for i in range(len(self.order)):
			self.roll(self.order[i])
			flg = True
			for k in range(6):
				if self.number[k] != another.number[k]:
					flg = False
					break
			if flg == True:
				return True
		return ret

n = int(input())
dice = []
for _ in range(n):
	data = list(map(int,input().split()))
	dice.append(Dice())
	dice[_].setNumber(data[0],data[1],data[2],data[3],data[4],data[5])

flag = True
for _ in range(n-1):
	for i in range(i+1,n):
		if(dice[_].equals(dice[i])):
			flag = False
			break

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



### FIXED CODE ###

class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ in range(6)]
		self.order = "NNNNWNNNWNNNENNNENNNWNNN"
	def setNumber(self,n0,n1,n2,n3,n4,n5):
		self.number[0] = n0
		self.number[1] = n1
		self.number[2] = n2
		self.number[3] = n3
		self.number[4] = n4
		self.number[5] = n5

	def roll(self,loc):
		for _ in range(6):
			self.work[_] = self.number[_]
		if loc == "E":
			self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
		elif loc == "N":
			self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
		elif loc == "S":
			self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
		elif loc == "W":
			self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
	def get_top(self):
		return self.number[0]
	def get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): return(self.number[2])
			elif(n2 == self.number[2]): return(self.number[4])
			elif(n2 == self.number[3]): return(self.number[1])
			elif(n2 == self.number[4]): return(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[0])
                        elif(n2 == self.number[3]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): return(self.number[1])
                        elif(n2 == self.number[1]): return(self.number[5])
                        elif(n2 == self.number[4]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): return(self.number[4])
                        elif(n2 == self.number[1]): return(self.number[0])
                        elif(n2 == self.number[4]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): return(self.number[2])
                        elif(n2 == self.number[2]): return(self.number[5])
                        elif(n2 == self.number[3]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[1])
                        elif(n2 == self.number[3]): return(self.number[4])
                        elif(n2 == self.number[4]): return(self.number[2])

	def equals(self,another):
		ret = False
		for i in range(len(self.order)):
			self.roll(self.order[i])
			flg = True
			for k in range(6):
				if self.number[k] != another.number[k]:
					flg = False
					break
			if flg == True:
				return True
		return ret

n = int(input())
dice = []
for _ in range(n):
	data = list(map(int,input().split()))
	dice.append(Dice())
	dice[_].setNumber(data[0],data[1],data[2],data[3],data[4],data[5])

flag = True
for _ in range(n-1):
	for i in range(_+1,n):
		if(dice[_].equals(dice[i])):
			flag = False
			break

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