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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		String x = "";
		try {
			x = in.readLine();
			int num = Integer.parseInt(x);
			
			Dice d[] = new Dice[num];
			for (int i = 0; i < num; i++) {
				d[i] = new Dice(in.readLine().split(" "));
			}
			
			boolean flag = false;
			for (int i = 0; i < num; i++) {
				for (int j = i + 1; j < num; j++) {
					flag = d[i].judge(d[j]);
					if (flag) {
						System.out.println("No");
						break;
					}
				}
			}
			if (flag == false) System.out.println("Yes");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class Dice {
	public int t, b, n, s, e, w;
	private int[][] list;
	
	public Dice(String[] num) {
		t = Integer.parseInt(num[0]);
		s = Integer.parseInt(num[1]);
		e = Integer.parseInt(num[2]);
		w = Integer.parseInt(num[3]);
		n = Integer.parseInt(num[4]);
		b = Integer.parseInt(num[5]);
		
		makeList();
	}
	
	public boolean judge(Dice d) {
		int at = d.t;
		int as = d.s;
		int ae = d.e;
		int aw = d.w;
		int an = d.n;
		int ab = d.b;
		
		for (int i = 0; i < 24; i++) {
			if ((list[i][0] == at) && (list[i][1] == as) && (list[i][2] == ae)
					&& (list[i][3] == aw) && (list[i][4] == an) && (list[i][5] == ab)){
				return true;
			}
		}
		return false;
	}
	
	public void makeList() {
		list = new int[24][6];

		int i = 0;
		for (int j = 0; j < 4; j++) {
			move('R');
			list[i * 4 + j][0] = t;
			list[i * 4 + j][1] = s;
			list[i * 4 + j][2] = e;
			list[i * 4 + j][3] = w;
			list[i * 4 + j][4] = n;
			list[i * 4 + j][5] = b;
		}
		
		i++;
		move('N');
		for (int j = 0; j < 4; j++) {
			move('R');
			list[i * 4 + j][0] = t;
			list[i * 4 + j][1] = s;
			list[i * 4 + j][2] = e;
			list[i * 4 + j][3] = w;
			list[i * 4 + j][4] = n;
			list[i * 4 + j][5] = b;
		}
		
		i++;
		move('W');
		for (int j = 0; j < 4; j++) {
			move('R');
			list[i * 4 + j][0] = t;
			list[i * 4 + j][1] = s;
			list[i * 4 + j][2] = e;
			list[i * 4 + j][3] = w;
			list[i * 4 + j][4] = n;
			list[i * 4 + j][5] = b;
		}
		
		i++;
		move('W');
		move('W');
		for (int j = 0; j < 4; j++) {
			move('R');
			list[i * 4 + j][0] = t;
			list[i * 4 + j][1] = s;
			list[i * 4 + j][2] = e;
			list[i * 4 + j][3] = w;
			list[i * 4 + j][4] = n;
			list[i * 4 + j][5] = b;
		}

		i++;
		move('E');
		for (int j = 0; j < 4; j++) {
			move('R');
			list[i * 4 + j][0] = t;
			list[i * 4 + j][1] = s;
			list[i * 4 + j][2] = e;
			list[i * 4 + j][3] = w;
			list[i * 4 + j][4] = n;
			list[i * 4 + j][5] = b;
		}
		
		i++;
		
		move('N');
		for (int j = 0; j < 4; j++) {
			move('R');
			list[i * 4 + j][0] = t;
			list[i * 4 + j][1] = s;
			list[i * 4 + j][2] = e;
			list[i * 4 + j][3] = w;
			list[i * 4 + j][4] = n;
			list[i * 4 + j][5] = b;
		}
	}
	
	public void move(char c) {
		int tmp = 0;
		
		switch (c) {
		case 'N' :
			tmp = t;
			t = s;
			s = b;
			b = n;
			n = tmp;
			break;
		case 'S' :
			tmp = t;
			t = n;
			n = b;
			b = s;
			s = tmp;
			break;
		case 'E' :
			tmp = t;
			t = w;
			w = b;
			b = e;
			e = tmp;
			break;
		case 'W' :
			tmp = t;
			t = e;
			e = b;
			b = w;
			w = tmp;
			break;
		case 'R' :
			tmp = n;
			n = w;
			w = s;
			s = e;
			e = tmp;
			break;
		}
	}

	public int getTop() {
		return t;
	}
}