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.Arrays;
import java.util.Scanner;
 
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = Integer.parseInt(scanner.nextLine());
 
        Dice[] dices = new Dice[num];
        boolean flag = true;
 
        loop: for (int i = 0; i < num; i++) {
            dices[i] = new Dice(scanner.nextLine());
            for (int j = 0; j < i; j++) {
                /*System.out.println(Arrays.toString(dices[i].a) + " -> "
                        + Arrays.toString(dices[j].a));*/
                if (dices[i].equals(dices[j])) {
                    flag = false;
                    break loop;
                }
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}
 
class Dice {
    int[] a = new int[6];
 
    Dice(String s) {
        String[] b = s.split(" ");
        for (int i = 0; i < 6; i++) {
            a[i] = Integer.parseInt(b[i]);
        }
    }
 
    public void roll(char c) {
        int temp;
        switch (c) {
        case 'E':
            temp = a[0];
            a[0] = a[3];
            a[3] = a[5];
            a[5] = a[2];
            a[2] = temp;
            break;
        case 'N':
            temp = a[0];
            a[0] = a[1];
            a[1] = a[5];
            a[5] = a[4];
            a[4] = temp;
            break;
        case 'W':
            temp = a[0];
            a[0] = a[2];
            a[2] = a[5];
            a[5] = a[3];
            a[3] = temp;
            break;
        default:
            temp = a[0];
            a[0] = a[4];
            a[4] = a[5];
            a[5] = a[1];
            a[1] = temp;
            break;
        }
    }
 
    public boolean equals(Dice d) {
        char[] c = { 'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S' };
        boolean flag = false;
        loop: for (int i = 0; i < 24; i++) {
            /*System.out.println(Arrays.toString(a) + "========"
                    + Arrays.toString(d.a));*/
            if (Arrays.equals(a, d.a)) {
                flag = true;
                break loop;
            }
            d.roll(c[i % 8]);
        }
        return flag;
    }
}