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;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        Dice dice = new Dice(sc, x);
        if(check(dice)){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
    
    public static boolean check(Dice dice) {
        char[] pat = {'N','N','E','E','E','N'};
        for(int j = 0; j < dice.data.length; j++){
            for(int k = 0; k < dice.data.length; k++){
                if(j >= k){ continue; }
                for(char p:pat){
                    if(Arrays.equals(dice.data[j], dice.data[k])){
                        return true;
                    }
                    dice.roll(j, p);
                    for(int i = 0; i < 4; i++){
                        if(Arrays.equals(dice.data[j], dice.data[k])){
                            return true;
                        }
                        dice.roll(j, 'Z');
                    }
                }
            }
        }
        return false;
    }
}

class Dice {
    static int[][] data;

    public Dice(Scanner sc, int x){
        data = new int[x][6];
        for(int i = 0; i < data.length; i++){
            for(int j = 0; j < data[i].length; j++){
            data[i][j] = sc.nextInt();
            }
        }
    }

    public static void roll(int n, char p) {
        int temp = data[n][0];
        switch(p){
            case 'E':
                data[n][0] = data[n][2];
                data[n][2] = data[n][5];
                data[n][5] = data[n][3];
                data[n][3] = temp; break;
            case 'W':
                data[n][0] = data[n][3];
                data[n][3] = data[n][5];
                data[n][5] = data[n][2];
                data[n][2] = temp; break;
            case 'S':
                data[n][0] = data[n][1];
                data[n][1] = data[n][5];
                data[n][5] = data[n][4];
                data[n][4] = temp; break;
            case 'N':
                data[n][0] = data[n][4];
                data[n][4] = data[n][5];
                data[n][5] = data[n][1];
                data[n][1] = temp; break;
            case 'Z':
                temp = data[n][1];
                data[n][1] = data[n][2];
                data[n][2] = data[n][4];
                data[n][4] = data[n][3];
                data[n][3] = temp; break;
            default:
        }
    }
}