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)

def dice(d, i, n):
    if n == 1:
        return d[i][1] + d[i][2] + d[i][4] + d[i][3]
    if n == 2:
        return d[i][0] + d[i][3] + d[i][5] + d[i][2]
    if n == 3:
        return d[i][0] + d[i][1] + d[i][5] + d[i][4]
    if n == 4:
        return d[i][0] + d[i][4] + d[i][5] + d[i][1]
    if n == 5:
        return d[i][0] + d[i][2] + d[i][5] + d[i][3]
    if n == 6:
        return d[i][1] + d[i][3] + d[i][4] + d[i][2]

answer = 'Yes'
n = int(input())
d = [0]*n
for i in range(n):
    d[i] = input().split()
    
for j in range(n-1):
    for k in range(j+1, n):
        for l in range(6):
            if d[j][0]==d[k][l] and d[j][5]==d[k][5-l] and dice(d,k,l+1)in dice(d,j,1)*2:
                answer = 'No'
                
print(answer)