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())
dices = [list(map(int,input().split(" "))) for i in range(n)]
check = []
count = 0
eq = 0
for i in range(n):
    check.append(dices[i])
d= []

def move(x):
    # N
    if x == 0:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[1],d[5],d[2],d[3],d[0],d[4]
    # W
    elif x == 1:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[2],d[1],d[5],d[0],d[4],d[3]

    # E
    elif x == 2:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[3],d[1],d[0],d[5],d[4],d[2]
    # S
    elif x == 3:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[4],d[0],d[2],d[3],d[5],d[1]

# そのまま
    elif x == 4:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[1],d[2],d[3],d[4],d[5]
#ひっくり返し
    elif x == 5:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[5],d[4],d[2],d[3],d[1],d[0]


#頂点維持のまま回転
    elif x == 6:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[2],d[4],d[1],d[3],d[5]


for i in range(6):
    d.append(dices[0][i])

for i in range(n-1):
    del check[0]
    for j in range(6):
        d[0],d[1],d[2],d[3],d[4],d[5] = dices[i][0],dices[i][1],dices[i][2],dices[i][3],dices[i][4],dices[i][5]
        move(j)
        for k in range(4):
            count += 1
            move(6)
            if d in check:
                eq = 1

                # print(d)
            # print(count)




if eq == 1:
    print("No")
else:
    print("Yes")