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 C# (judge verdict: Accepted)

using System;

public class Dice
{

	public static void Main(String[] args)
	{
		//?????????????????°????????????
		int diceCount=int.Parse(Console.ReadLine());
		//diceCount????????????????????????
		string[][] diceA=new string[diceCount][];
		
		for(int d=0;d<diceCount;d++)
		{   
			string data=Console.ReadLine();
			diceA[d]=data.Split();

		}
		string yesNo = "Yes";
		//??\??????????????????????????????????????°????????´??? "Yes"??????????????????????????\?????????????????´???
		//"No" ??¨???????????????
     	
		//???????????????????????????.??????????????????????????????
		
		for(int i=0;i<diceCount-1;i++)
		{
			for(int j=i+1;j<diceCount;j++)
			{
			    		
				yesNo=diceComparer(diceA[i] ,diceA[j]);
		       if(yesNo=="No")
		       {
		       
		       	break;
		       }
		       
			}
			if(yesNo=="No")
			{
				break;
			}
		}
		Console.WriteLine(yesNo);
	}
	//????????????????????¢??????????????±?\??????????90??????????????????

	public static void turn(int a, int b, int c, int d, string[] dice)
	{
		string temp = dice[a];
		dice[a] = dice[b];
		dice[b] = dice[c];
		dice[c] = dice[d];
		dice[d] = temp;
            
	}
	
	public static string diceComparer(string[] dice1,string[] dice2)
	{
		int i = 0;
		int j = 0;
		string yn="Yes";//????????????????????´??????????????§"No"????????????"No"????????´???????????????
		do {
			do {
                  
				for (int k = 0; k < dice1.Length; k++) {
					if (!dice1[k].Equals(dice2[k])) {
						yn = "Yes";
						break;
					}
					if (k == dice1.Length - 1) {
						yn = "No";//?????????????????´
					}
				}
				if (yn == "No") {
					break;
				}
				turn(3, 5, 2, 0, dice2); //??±??¨???                  
				j++;
			} while (j < 4);

			if (yn == "No") {
				break;
			}
				
			j = 0;
				
		
			
			 if (i == 3) {
                   
				turn(4, 5, 1, 0, dice2);//????????§?????????
				turn(2, 5, 3, 0, dice2);//?\???¨???
				
					
			} else if (i == 4)
			{
				//??????????????§diceB[1]=east
				//west ???south????????????????????????                   
				turn(4, 5, 1, 0, dice2);  
			
			}
			
			turn(4, 5, 1, 0, dice2);//?????¨???
			//?????????????????????????????????????????????????????????????????????????????¨??¨????????¢??????????????????????????????
			i++;
		} while (i < 6);
		return yn;
		//Console.WriteLine(yesNo);
	}
}