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

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);

		//?????????????????°????????????
		int intNum = scan.nextInt();

		//???????????????ArrayList???????´?
		ArrayList<int[]> diceList = new ArrayList<int[]>();

		for(int j = 0; j < intNum; j++){

			//????????????????????????????????£??\
			int[] dice = new int[6];
			for(int i = 0; i < 6; i++){

				dice[i] = scan.nextInt();
			}
			//AryList??????????????????????´?
			diceList.add(dice);
		}

		//??????????????????????????\?????????????????°
		int[] dice1 = new int[6];
		int[] dice2 = new int[6];
		//?????????????????????????????´????????????boolean??§?????????
		boolean isSame = false;
		//?????????????????????true?????????????????????????¢???????
		int intCount = 0;

		for(int i = 0; i < intNum; i++){

			for(int j = 0; j < intNum; j++){

				dice1 = diceList.get(j);
				dice2 = diceList.get(i);

				//????????????????????????(dice?????????)
				Dice insDice = new Dice(dice1,dice2);

				//?????????????????????????????????????????\?????????????????\???
				if(i != j ){
					isSame = insDice.judgeCopy(dice1,dice2);
				}
				//isSame???true?????\?????°?????????????????¢??????
				//??????????????????????????????????????´?????????
				if(isSame){
					intCount++;
				}
			}

		}

		if(intCount == 0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}


	static class Dice {

		//?????£?????????
		//Dice?????????????´??????????????????°
		int[] aryDice = new int[6];
		int[] aryDice2 = new int[6];

		//?????????????????????
		public Dice(){
		}

		public Dice(int[] aryDice, int[] aryDice2){
			this.aryDice = aryDice;
			this.aryDice2 = aryDice2;
		}

		//?????´????????´???????????????????????????????????°
		boolean isSame = false;


		///Method???????????????????????´???????????? boolean??§??????
		public boolean judgeCopy(int[] aryDice, int[] aryDice2){
			int intCount = 0;

			//????????????????????????????????¢??????
			for(int l = 0; l < 4; l++){
				//???????????????????????????????????¢??????
				for(int k = 0; k < 4; k++){
					//????????????????¨?????????¢??????
					for(int j = 0; j < 4; j++){

						//??????????????¨??¢?????°???????????´???????????????
						intCount = 0;//?????????????????????
						for(int i =0; i < aryDice.length; i++){

							//System.out.print(aryDice[i] + " ");
							if(aryDice[i] == aryDice2[i]){
								//??¨??¢?????????????????????????????????
								intCount++;
							}
							if(intCount == 6){
								//??????????????´????????´??????true??¨??????
								isSame = true;
							}
						}
						//System.out.println();
						//System.out.println(" intCount:" + intCount);
						//if(intCount == 6){break;}
						//?¨??????¢?????¢??\?????????
						int temp = aryDice[1];
						aryDice[1] = aryDice[2];
						aryDice[2] = aryDice[4];
						aryDice[4] = aryDice[3];
						aryDice[3] = temp;

					}
					//if(intCount == 6){break;}
					//??£??¢???????????¢?????¢??\?????????
					roll("S");
				}
				//if(intCount == 6){break;}
				//?¨???\????????¢?????¢??\?????????
				roll("E");
			}
			//System.out.println(isSame);
			return isSame;
		}




		///Method Top????????´?????????????????????????????\????????????
		public void roll(String direction){

			int temp = 0;
			if("S".equals(direction)){

				 temp = aryDice[0];
				aryDice[0] = aryDice[4];
				aryDice[4] = aryDice[5];
				aryDice[5] = aryDice[1];
				aryDice[1] = temp;
			}else if("E".equals(direction)){

				 temp = aryDice[0];
				aryDice[0] = aryDice[3];
				aryDice[3] = aryDice[5];
				aryDice[5] = aryDice[2];
				aryDice[2] = temp;
			}else if("W".equals(direction)){

				temp = aryDice[0];
				aryDice[0] = aryDice[2];
				aryDice[2] = aryDice[5];
				aryDice[5] = aryDice[3];
				aryDice[3] = temp;
			}else if("N".equals(direction)){

				temp = aryDice[0];
				aryDice[0] = aryDice[1];
				aryDice[1] = aryDice[5];
				aryDice[5] = aryDice[4];
				aryDice[4] = temp;
			}

		}





	}//class Dice?????????
}