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

public class Main {

	public static void main(String[] args) {
		int loop;
		String output = "Yes";
		Scanner sc = null;

		try {
			sc = new Scanner(System.in);

			String line = sc.next();
			loop = Integer.parseInt(line);
			line = sc.nextLine();

			//?????????????????????
			int[][] diceList = new int[loop][6];
			for (int i = 0; i < loop; i++) {
				line = sc.nextLine();
				Dice di = new Dice(line);
				diceList[i] = di.surface;
				}
			//?????????????????¨????????????
			for (int i = 0; i < diceList.length - 1; i++) {
				for (int j = i + 1; j < diceList.length; j++) {
					//??????????????§??????
					if (Dice.diceCheck(diceList[i], diceList[j])) {
						output = "No";
						break;
					}
				}
			}
			System.out.println(output);
		} finally {
			sc.close();
		}
	}

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

	int[] surface;

	public Dice(String s){

		String[] work;

		work = s.split(" ");

		surface = new int[work.length];

		for (int i = 0; i < work.length; i++) {
			surface[i] = Integer.parseInt(work[i]);
		}
	}

	///????????????????????????????????????
	public static int[] diceroll(int[] di , String com){
		int n = 0;
		int[] dice = di;

		//???????????????
			switch (com) {
			case "N":
				n = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = n;
				break;

			case "S":
				n = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = n;
				break;

			case "W":
				n = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = n;
				break;

			case "E":
				n = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = n;
				break;

			default:
				System.out.println("other");
				break;
			}
		return dice;

	}

	///?????????????????????
	public static boolean diceCheck(int[] diceOne , int[] diceTwo){

		String command;

		boolean anser = false;
		for (int j = 0; j < 4; j++) {

			for (int k = 0; k < 4; k++) {
				if (!Arrays.equals(diceOne, diceTwo)) {
					command = "N";
					diceOne = Dice.diceroll(diceOne, command);
					command = "W";

					for (int l = 0; l < 4; l++) {
						diceOne = Dice.diceroll(diceOne, command);
						if (Arrays.equals(diceOne, diceTwo)) {
							anser = true;
							break;
						}
					}

				}else{
					anser = true;
					break;
				}
			}
			//
			if (!Arrays.equals(diceOne, diceTwo)) {
				command = "W";
				diceOne = Dice.diceroll(diceOne, command);
			}else{
				anser = true;
				break;
			}
		}
		return anser;

	}
}