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)

n=int(input())
e=[[0 for i in range(6)]for j in range(n)]
for i in range(n):
	a=list(map(int,input().split()))
	e[i]=a	
for i in range(n-1):
	if e[0][0]==e[i+1][1]:
		e[i+1][0],e[i+1][1],e[i+1][4],e[i+1][5]=e[i+1][1],e[i+1][5],e[i+1][0],e[i+1][4]		
	elif e[0][0]==e[i+1][2]:
		e[i+1][0],e[i+1][2],e[i+1][3],e[i+1][5]=e[i+1][2],e[i+1][5],e[i+1][0],e[i+1][3]
	elif e[0][0]==e[i+1][3]:
		e[i+1][0],e[i+1][2],e[i+1][3],e[i+1][5]=e[i+1][3],e[i+1][0],e[i+1][5],e[i+1][2]	
	elif e[0][0]==e[i+1][4]:
		e[i+1][0],e[i+1][1],e[i+1][4],e[i+1][5]=e[i+1][4],e[i+1][0],e[i+1][5],e[i+1][1]		
	elif e[0][0]==e[i+1][5]:
		e[i+1][0],e[i+1][1],e[i+1][4],e[i+1][5]=e[i+1][5],e[i+1][4],e[i+1][1],e[i+1][0]
		
	for k in range(4):
		if 	e[0][1]!=e[i+1][1]:
			e[i+1][1],e[i+1][2],e[i+1][4],e[i+1][3]=e[i+1][3],e[i+1][1],e[i+1][2],e[i+1][4]
		else:
			break
count=0
for i in range(n):
	for j in range(n):
		if e[i]==e[j]:
			count=count+1
if count==n:
	print('Yes')
else:
	print('No')