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;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int dice_count = in.nextInt();

		int[][] dice_array = new int[dice_count][6];

		for(int dice_number = 0; dice_number < dice_count; dice_number++) {

			for(int side_number = 0; side_number < 6; side_number++) {

				dice_array[dice_number][side_number] = in.nextInt();

			}
		}

		// dice???????????????????????????
		dice4 dice = new dice4(dice_array);

		// ??????????????????????????????????????????
		boolean dice_match = dice.dice_match(dice_count, dice_array);

		// ???????????????1?????§????????´??????????????°"Yes"???????????°"No"?????¨???
		if(dice_match) {

			System.out.println("No");

		} else {

			System.out.println("Yes");

		}
	}
}


class dice4{

	int[][] dice_array;

	// ?????????????????????
	dice4(int[][] dice_array){

		this.dice_array = dice_array;

	}

	// ?????????????????¢??????????????????
	void roll(int dice_number, char roll_direction){

		int tmp;

		switch(roll_direction){

		// ?????????????????¢??????
		case 'S':

			tmp = dice_array[dice_number][0];
			dice_array[dice_number][0] = dice_array[dice_number][4];
			dice_array[dice_number][4] = dice_array[dice_number][5];
			dice_array[dice_number][5] = dice_array[dice_number][1];
			dice_array[dice_number][1] = tmp;

			break;

		// ?\\???????????¢??????
		case 'N':

			tmp = dice_array[dice_number][0];
			dice_array[dice_number][0] = dice_array[dice_number][1];
			dice_array[dice_number][1] = dice_array[dice_number][5];
			dice_array[dice_number][5] = dice_array[dice_number][4];
			dice_array[dice_number][4] = tmp;

			break;

		// ??????????????¢??????
		case 'W':

			tmp = dice_array[dice_number][0];
			dice_array[dice_number][0] = dice_array[dice_number][2];
			dice_array[dice_number][2] = dice_array[dice_number][5];
			dice_array[dice_number][5] = dice_array[dice_number][3];
			dice_array[dice_number][3] = tmp;

			break;

		// ??????????????¢??????

		case 'E':

			tmp = dice_array[dice_number][0];
			dice_array[dice_number][0] = dice_array[dice_number][3];
			dice_array[dice_number][3] = dice_array[dice_number][5];
			dice_array[dice_number][5] = dice_array[dice_number][2];
			dice_array[dice_number][2] = tmp;

			break;

		}
	}

	// ?????????????????????????????¢?????????????????????
	void turn(int dice_number, char turn_direction) {

		int tmp;

		switch(turn_direction) {

		// ????????¢
		case 'R':

			tmp = dice_array[dice_number][1];
			dice_array[dice_number][1] = dice_array[dice_number][3];
			dice_array[dice_number][3] = dice_array[dice_number][4];
			dice_array[dice_number][4] = dice_array[dice_number][2];
			dice_array[dice_number][2]= tmp;

			break;

		// ????????¢
		case 'L':

			tmp = dice_array[dice_number][1];
			dice_array[dice_number][1] = dice_array[dice_number][2];
			dice_array[dice_number][2] = dice_array[dice_number][4];
			dice_array[dice_number][4] = dice_array[dice_number][3];
			dice_array[dice_number][3] = tmp;

			break;

		}
	}

	// ?????????????????????????????????????????????????????????????????????
	boolean dice_match(int dice_count, int[][] dice_array) {

		for(int i= 0; i < dice_count - 1; i++) {

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

				if(j % 2 == 0) {

					roll(i, 'S');

				} else {

					roll(i, 'E');

				}

				for(int k = 0; k < 4; k++) {

					turn(i, 'R');

					for(int l = i + 1; l < dice_count; l++) {

						for(int m = 0; m < 6; m++) {

							if(dice_array[i][m] == dice_array[l][m]) {

								if(m == 5) {

									return true;

								}

							} else {

								break;

							}
						}
					}
				}
			}
		}

		// ??¨????????????????????§?????´??????????????°false?????????
		return false;

	}
}