Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes

Solution in Python3 (judge verdict: Accepted)

class Dice:
	# Label: 1=Up, 2=South, 3=East, 4=West, 5=North, 6=Down
	def __init__(self, nums):
		self.nums = nums
		self.cU = nums[0]
		self.cS = nums[1]
		self.cE = nums[2]
		self.cW = nums[3]
		self.cN = nums[4]
		self.cD = nums[5]
	def goN(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pS,pD,pU,pN
	def goE(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pW,pU,pD,pE
	def goW(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pE,pD,pU,pW
	def goS(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pN,pU,pD,pS
	def toU(self, num):
		if self.cD == num:
			for _ in range(2): self.goN()
		elif self.cN == num: self.goS()
		elif self.cE == num: self.goW()
		elif self.cW == num: self.goE()
		elif self.cS == num: self.goN()
	def right(self, num):
		if self.cN == num: return self.cW
		elif self.cE == num: return self.cN
		elif self.cW == num: return self.cS
		elif self.cS == num: return self.cE
		else: raise # ????????????
	def equals(self, dice):
		"""?????????????????¨????????????????????¢????????????????????§??¨???"""
		for i in self.nums:
			if dice.nums.count(i) == 1:
				self.toU(i)
				dice.toU(i)
				break
		if self.cU == dice.cU and self.cD == dice.cD:
			nesw1 = ''.join(list(map(str, [self.cN,self.cE,self.cS,self.cW])))
			nesw1 += nesw1
			nesw2 = ''.join(list(map(str, [dice.cN,dice.cE,dice.cS,dice.cW])))
			if nesw1.count(nesw2) > 0: return True
			else: return False
		else: return False
dice = [Dice(list(map(int, input().split(' ')))) for _ in range(int(input()))]
pre = None
rslt = True
for die in dice:
	if pre == None: 
		pre = die
		continue
	if pre.equals(die):
		rslt = False
		break
if rslt: print('Yes')
else: print('No')