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

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
    
        int n = Integer.parseInt(br.readLine());
        String[] asaikoro = br.readLine().split(" ");
        int[][] as = new int[n][6];
        for (int i = 0; i < 6; i++)
        {
        	as[0][i] = Integer.parseInt(asaikoro[i]);
        }
        int count = 0;
        int[] bs = new int[6];
        
        for (int j = 0; j < n; j++)
        {
        	if (j != 0)
        	{
        		String[] bsaikoro = br.readLine().split(" ");
            	int a =  0;
            	for (int i = 0; i < 6; i++)
            	{
            		bs[i] = Integer.parseInt(bsaikoro[i]);
            	}
            	
            	for (int k = 0; k < j; k++)
            	{
            		if ((as[k][0] == bs[2] || as[k][0] == bs[3]) && (as[k][5] == bs[2] || as[k][5] == bs[3]))
                	{
                		a = bs[1];
            			bs[1] = bs[2];
            			bs[2] = bs[4];
            			bs[4] = bs[3];
            			bs[3] = a;
                	}
                	
                	for (int i = 0; i < 3; i++) //????????¢????????¢????????£???????????????
            		{
            			if (as[k][0] ==bs[0] && as[k][5] ==bs[5])
            				break;
            			a = bs[0];
            			bs[0] = bs[1];
            			bs[1] = bs[5];
            			bs[5] = bs[4];
            			bs[4] = a;
            		}
                	
                	for (int i = 0; i < 3; i++) //?¨??????¢????¨???¢????????£???????????????
            		{
            			if (as[k][1] ==bs[1] && as[k][4] ==bs[4])
            				break;
            			a = bs[1];
            			bs[1] = bs[2];
            			bs[2] = bs[4];
            			bs[4] = bs[3];
            			bs[3] = a;
            		}
                	if (as[k][0] == bs[0] && as[k][1] == bs[1] && as[k][2] == bs[2] && as[k][3] == bs[3] && as[k][4] == bs[4] && as[k][5] == bs[5])
                		count++;
            	}
            	for (int i = 0; i < 6; i++)
            	{
            		as[j][i] = bs[i];
            	}
        	}
        }
        if (count == 0)
        	System.out.println("Yes");
        else if (count >= 1)
        	System.out.println("No");
	}
}