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)

number = int(input())
dices = []
for i in range(number):
    dices.append(input().split())
    
tf = 0
for i in range(number - 1):
    for j in range(i + 1, number):
        
        dice_1 = dices[i]
        dice_2 = dices[j]
        rolls = {' ':[0, 1, 2, 3, 4, 5], 
                 'W':[2, 1, 5, 0, 4, 3], 
                 'N':[1, 5, 2, 3, 0, 4], 
                 'E':[3, 1, 0, 5, 4, 2], 
                 'S':[4, 0, 2, 3, 5, 1]
                }
        orders = [' ', 'N', 'W', 'E', 'S', 'NN']
        for order in orders:
            copy_2 = dice_2
            for d in order:
                roll = rolls[d]
                copy_2 = [copy_2[i] for i in roll]    
            l = [1, 2, 4, 3]
            a0 = copy_2[0] == dice_1[0]
            a1 = copy_2[5] == dice_1[5]
            a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
            if  a0 and a1 and a2:
                tf += 1
if tf > 0:
    print('No')
else:
    print('Yes')