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 JAVA (judge verdict: Accepted)

import java.util.Scanner;

class Dice {
    int[] dn = new int[6];

    Dice(int[] d) {
        for (int i = 0; i < 6; i++) {
            dn[i] = d[i];
        }
    }

    void turnN() {
        int x = dn[0];
        dn[0] = dn[1];
        dn[1] = dn[5];
        dn[5] = dn[4];
        dn[4] = x;
    }

    void turnS() {
        int x = dn[0];
        dn[0] = dn[4];
        dn[4] = dn[5];
        dn[5] = dn[1];
        dn[1] = x;
    }

    void turnW() {
        int x = dn[0];
        dn[0] = dn[2];
        dn[2] = dn[5];
        dn[5] = dn[3];
        dn[3] = x;
    }

    void turnE() {
        int x = dn[0];
        dn[0] = dn[3];
        dn[3] = dn[5];
        dn[5] = dn[2];
        dn[2] = x;
    }

    void sideturn() {
        int x = dn[1];
        dn[1] = dn[2];
        dn[2] = dn[4];
        dn[4] = dn[3];
        dn[3] = x;
    }

    static boolean judge(Dice d1, Dice d2) {
        boolean a = false;

        a = a || check(d1, d2);
        d2.turnN();
        a = a || check(d1, d2);
        d2.turnE();
        a = a || check(d1, d2);
        d2.turnE();
        a = a || check(d1, d2);
        d2.turnE();
        a = a || check(d1, d2);
        d2.turnN();
        a = a || check(d1, d2);

        return a;
    }
    
    static boolean check(Dice d1, Dice d2) {
        boolean b = false;
        if (d1.dn[0] == d2.dn[0] && d1.dn[5] == d2.dn[5]) {
            for (int i = 0; i < 4; i++) {
                b = b || check2(d1, d2);
                d2.sideturn();
            }
        }
        return b;
    }
    
    static boolean check2(Dice d1, Dice d2) {
        boolean c = true;
        for (int i = 1; i < 5; i++) {
            c = c && d1.dn[i] == d2.dn[i];
        }
    
        return c;
    }
}

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[6];
        Dice[] dc = new Dice[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 6; j++) {
                num[j] = sc.nextInt();
            }
            dc[i] = new Dice(num);
        }

        boolean ans = false;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i > j) {
                    ans = ans || Dice.judge(dc[i], dc[j]);
                }
            }
        }

        if (ans) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}