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)

import random as ran
n = int(input())
A = [[int(x) for x in input().split()] for l in range(n)]


# for i in range(n):
#     if (A[i][0] + A[i][5] != 7):
#         del A[i]

oup = 0
oun = 0
ori = 0
ole = 0
ofr = 0
oba = 0

up = 0
un = 0
ri = 0
le = 0
fr = 0
ba = 0
tmp = 0
tmp2 = 0

count = 0
order = ["S","N","E","W"]

def diceorigin(num):
    global oup
    global oun
    global ori
    global ole
    global ofr
    global oba

    oup = A[num][0]
    oun = A[num][5]
    ori = A[num][2]
    ole = A[num][3]
    ofr = A[num][1]
    oba = A[num][4]

def dice(num):
    global up
    global un
    global ri
    global le
    global fr
    global ba
    global tmp2
    global tmp

    up = A[num][0]
    un = A[num][5]
    ri = A[num][2]
    le = A[num][3]
    fr = A[num][1]
    ba = A[num][4]
    tmp2 = 0
    tmp = 0

for x in range(0,len(A)):
    diceorigin(x)

    for y in range(x+1,len(A)):
        dice(y)


        for i in range(100)  :
            x = ran.choice(order)
            if (x == "S"):
                tmp = fr
                tmp2 = un
                fr = up
                up = ba
                un = tmp
                ba = tmp2

            elif (x == "N"):
                tmp = un
                tmp2 = up
                up = fr
                un = ba
                fr = tmp
                ba = tmp2

            elif (x == "E"):
                tmp = up
                tmp2 = un
                up = le
                un = ri
                ri = tmp
                le = tmp2

            elif (x == "W"):
                tmp = un
                tmp2 = up
                up = ri
                un = le
                ri = tmp
                le = tmp2

            if (up == oup and un == oun and ri == ori and le == ole and fr == ofr and ba == oba):
                print("No")
                exit()


            # print(up,un,ri,le,fr,ba,oup,oun,ori,ole,ofr,oba)
print("Yes")