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)

class dice:
    def __init__(self,label):
        self.label = {i+1: l for i,l in enumerate(label)}
    def roll(self,op):
        l = self.label
        if   op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
        elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
        elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
        elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
    def yaw(self,op):
        l = self.label
        if   op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
        elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
    def get_label(self,i=0):
        if 1 <= i <= 6:
            return self.label[i]
        else:
            return [self.label[x] for x in range(1,7)] 

def cmp_dice(d0,d1):
    dc = dice(d0.get_label())
    d1_l = d1.get_label()
    result=False
    if set(dc.get_label())==set(d1_l):
        for i in range(6):
            for _ in range(4):
                if dc.get_label()==d1_l:
                    result=True
                    break
                dc.yaw('CW')
            if dc.get_label()==d1_l:
                break
            if i < 4:
                dc.roll('E')
            if i >= 3:
                dc.roll('N')
            if i >= 4:
                dc.roll('N')
    return result

if __name__ == '__main__':
    import itertools
    n=int(input())
    d_list = [dice(list(map(int, input().split()))) for _ in range(n)]
    result='Yes'
    for dx, dy in itertools.combinations(d_list,2):
        if cmp_dice(dx,dy):
            result='No'
            break
    print(result)