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.*;

public class Main{
    private static final Scanner scan = new Scanner(System.in);
    static boolean flag = false;

    public static void main(String[] args){

        int n = scan.nextInt();
        Integer[] d = new Integer[6];
        Dice[] dices = new Dice[n];


        for(int i = 0; i < n ; i++){
            for(int j = 0; j < 6; j++){
                d[j] = scan.nextInt();
            }
            Object[] objs = (Object[]) d;
            dices[i] = new Dice((Object[]) objs);
        }

        boolean ans = true;
        for(int i = 0; ans && i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(dices[i].equals(dices[j])){
                    ans = false;
                    break;
                }
            }
        }
        System.out.println(ans? "Yes" : "No");
    }
}

class Dice{

    int[] _d = new int[6];
    public static final int
        TOP = 0, SOUTH = 1, EAST = 2,
        WEST = 3, NORTH = 4, BOTTOM = 5; // ?????°

    public Dice(Object... obj){ // ?????????????????????
Integer c[]=new Integer[6];
        for(int i = 0; i < 6; i++){

// System.out.println(obj.getClass());
            if(obj instanceof Integer[]){
// System.out.println("qwe");
                Integer[] d = (Integer[])obj;
                _d[i] = d[i];
            }
        }
    }

    public int[] showAll(){
        return _d;
    }

    @Override
    public boolean equals(Object obj){
        boolean result = false;
        Dice dice = (Dice) obj;
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                if(Arrays.equals(showAll(), dice.showAll())){
                    result = true;
                    break;
                }
                dice.rollEast();
            }
            for(int j = 0; j < 4; j++){
                if(Arrays.equals(showAll(), dice.showAll())){
                    result = true;
                    break;
                }
                dice.rollNorth();
            }
            if(Arrays.equals(showAll(), dice.showAll())){
                result = true;
                break;
            }
            dice.rollRight();
        }
        return result;
    }

    public void rollSouth(){
        int tmp = _d[TOP];
        _d[TOP] = _d[NORTH];
        _d[NORTH] = _d[BOTTOM];
        _d[BOTTOM] = _d[SOUTH];
        _d[SOUTH] = tmp;
    }

    public void rollNorth(){
        int tmp = _d[TOP];
        _d[TOP] = _d[SOUTH];
        _d[SOUTH] = _d[BOTTOM];
        _d[BOTTOM] = _d[NORTH];
        _d[NORTH] = tmp;
    }

    public void rollEast(){
        int tmp = _d[TOP];
        _d[TOP] = _d[WEST];
        _d[WEST] = _d[BOTTOM];
        _d[BOTTOM] = _d[EAST];
        _d[EAST] = tmp;
    }

    public void rollWest(){
        int tmp = _d[TOP];
        _d[TOP] = _d[EAST];
        _d[EAST] = _d[BOTTOM];
        _d[BOTTOM] = _d[WEST];
        _d[WEST] = tmp;
    }

    public void rollRight(){
        int tmp = _d[SOUTH];
        _d[SOUTH] = _d[WEST];
        _d[WEST] = _d[NORTH];
        _d[NORTH] = _d[EAST];
        _d[EAST] = tmp;
    }
}