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 m = 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++){
		    			int temp3 = dice[m-1].S[0];
		        		dice[m-1].S[0] = dice[m-1].S[1];
		        		dice[m-1].S[1] = dice[m-1].S[5];
		        		dice[m-1].S[5] = dice[m-1].S[4];
		        		dice[m-1].S[4] = temp3;
		        		if(dice[m-1].S[0] == dice[m].S[0] && dice[m-1].S[1] == dice[m].S[1] && dice[m-1].S[2] == dice[m].S[2] && dice[m-1].S[3] == dice[m].S[3] && dice[m-1].S[4] == dice[m].S[4] && dice[m-1].S[5] == dice[m].S[5]) {
		        			System.out.println("No");
		        		    return;
		        		}else{
		        			if(m > 3){
		        				for(int n = 0; n < m; n++){
		        					if(dice[m - n].S[0] == dice[m].S[0] && dice[m - n].S[1] == dice[m].S[1] && dice[m - n].S[2] == dice[m].S[2] && dice[m - n].S[3] == dice[m].S[3] && dice[m - n].S[4] == dice[m].S[4] && dice[m - n].S[5] == dice[m].S[5]) {
		        						System.out.println("No");
		        						return;
		        					}
				        		}
		        			}
		        		}
		    		}
		    		int temp2 = dice[m-1].S[0];
		    		dice[m-1].S[0] = dice[m-1].S[3];
		    		dice[m-1].S[3] = dice[m-1].S[5];
		    		dice[m-1].S[5] = dice[m-1].S[2];
		    		dice[m-1].S[2] = temp2;
				}
				int temp = dice[m-1].S[0];
				dice[m-1].S[0] = dice[m-1].S[1];
				dice[m-1].S[1] = dice[m-1].S[5];
				dice[m-1].S[5] = dice[m-1].S[4];
				dice[m-1].S[4] = temp;
			}
    	}
    	System.out.println("Yes");
     }
}


class Dice{
	int[] S = new int[6];
}