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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		class qube{
			Scanner sc = new Scanner(System.in);
			Integer [] face = new Integer[6];
			ArrayList<Integer []> box = new ArrayList<Integer []>();
			Integer i,j,k,n=0,dump=0,check,st=101,nd=101;

			qube(){
				n = sc.nextInt();
			}
			void load(){
				this.box.add(this.box.size(), face);
			}

			void areg(){
				for(i=0;i<6;i++){
					face[i] = sc.nextInt();
				}

				this.judge();
				for(k=0;;k++){
					if(this.face[1]==this.nd){
						break;
					}
					this.move("N");
					if(this.k.equals(3)){
						this.move("E");
					}
				}
				while(true){
					if(this.face[0]==this.st){
						break;
					}
					this.move("E");
				}
			}

			void swap(int a,int b){
				dump = this.face[a];
				this.face[a] = this.face[b];
				this.face[b] = dump;

			}
			void judge(){
				for(i=0;i<6;i++){
					if(st>face[i]) st = face[i];
				}
				for(i=0;i<6;i++){
					if(face[i] != st && nd>face[i]) nd = face[i];
				}
			}

			void move(String es){
				if(es.equals("E")){
					swap(0,2);
					swap(0,5);
					swap(0,3);
				}
				else if(es.equals("N")){
					swap(4,5);
					swap(4,1);
					swap(4,0);
				}

			}
			boolean comp(){
				check = 0;
				for(i=0;i<3;i++){
					for(j=0;j<3;j++){
						if(this.box.get(0)[i]==face[j] && this.box.get(0)[5-i]==face[5-j]){
							check++;
							break;
						}
					}
				}
				if(check == 3){
					return true;
				}
				else{
					return false;
				}
			}
		}
		Integer i;

		qube q = new qube();
		q.areg();
		q.load();
		for(i=0;i<(q.n-1);i++){
			q.areg();
			if(q.comp() == true){
				System.out.println("No");
				break;
			}
			else{
				q.load();
			}

		}
		if(i.equals((q.n-1))){
			System.out.println("Yes");
		}
	}

}