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: Wrong Answer)

import java.util.Scanner;

class Main{
      public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	Dice[] dice;

    	int dice_num = scan.nextInt();
    	dice = new Dice[dice_num];

    	for(int i = 0; i < dice_num; i++){
    		dice[i] = new Dice();
    	}

    	for(int i = 0; i < dice_num; i++){
    		for(int j = 0; j < 6; j++){
    			dice[i].S[j] = scan.nextInt();
    		}
    	}

    	for(int n = 0; n < dice_num - 1; n++){
    		for(int m = n + 1; m < dice_num; m++){
				for(int i = 0; i < 4; i++){
					for(int j = 0; j < 4; j++){
			    		for(int k = 0; k < 4; k++){
			    			dice[m].vRoll();
			    			if(dice[n].S[0] == dice[m].S[0] && dice[n].S[1] == dice[m].S[1] && dice[n].S[2] == dice[m].S[2] && dice[n].S[3] == dice[m].S[3] && dice[n].S[4] == dice[m].S[4] && dice[n].S[5] == dice[m].S[5]) {
			    				System.out.println("No");
			    				return;
			    			}
			        	}
			    		dice[m].yRoll();
		    		}
		    		
				}
				int temp = dice[m].S[0];
				dice[m].S[0] = dice[m].S[1];
				dice[m].S[1] = dice[m].S[5];
				dice[m].S[5] = dice[m].S[4];
				dice[m].S[4] = temp;
    		}
		}
    	System.out.println("Yes");
     }
}

class Dice{
	int[] S = new int[6];
	
	public void vRoll(){
		int temp3 = S[0];
		S[0] = S[1];
		S[1] = S[5];
		S[5] = S[4];
		S[4] = temp3;
		//System.out.println(String.format("n:%d m:%d i:%d j:%d k:%d", n, m, i, j, k));
		//System.out.println(String.format("dice[%d] = %d, %d, %d, %d, %d, %d", n, dice[n].S[0], dice[n].S[1], dice[n].S[2], dice[n].S[3], dice[n].S[4], dice[n].S[5]));
		//System.out.println(String.format("dice[%d] = %d, %d, %d, %d, %d, %d", m, dice[m].S[0], dice[m].S[1], dice[m].S[2], dice[m].S[3], dice[m].S[4], dice[m].S[5]));
	}
	
	public void yRoll(){
		int temp2 = S[0];
		S[0] = S[3];
		S[3] = S[5];
		S[5] = S[2];
		S[2] = temp2;
	}
}