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: Wrong Answer)

using System;

namespace Project
{
	class Dice
	{
		public int face;
		public int N;
		public int E;
		public int S;
		public int W;
		public int back;

/*		public Dice(int a1, int a2, int a3, int a4, int a5, int a6)
		{
			face = a1;
			N = a5;
			E = a3;
			S = a2;
			W = a4;
			back = a6;
		}
*/		
		public void roll(char D)
		{
			int pface = face;
			int pN = N;
			int pE = E;
			int pW = W;
			int pS = S;
			int pback = back;
			switch (D)
			{
				case 'N':
					face = pS;
					N = pface;
					S = pback;
					back = pN;
					break;
				case 'E':
					face = pW;
					E = pface;
					W = pback;
					back = pE;
					break;
				case 'W':
					face = pE;
					E = pback;
					W = pface;
					back = pW;
					break;
				case 'S':
					face = pN;
					N = pback;
					S = pface;
					back = pS;
					break;
			}
		}
	}

	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			Dice[] dice = new Dice[n];
			for (int i = 0; i < n; i++)
			{
				string[] s = Console.ReadLine().Split(' ');
				int[] a = new int[6];
				for (int j = 0; j < 6; j++)
				{
					a[j] = int.Parse(s[j]);
				}
				dice[i] = new Dice();
				dice[i].face = a[0];
				dice[i].N = a[4];
				dice[i].E = a[2];
				dice[i].S = a[1];
				dice[i].W = a[3];
				dice[i].back = a[5];
			}
			int[] count = new int[n];

			for (int i = 1; i < n; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					count[i] = 0;
					while (count[i] < 10)
					{
						if (checkdice(dice[i], dice[j])) break;
						dice[i].roll('N');
						if (checkdice(dice[i], dice[j])) break;
						dice[i].roll('N');
						if (checkdice(dice[i], dice[j])) break;
						dice[i].roll('N');
						if (checkdice(dice[i], dice[j])) break;
						dice[i].roll('N');
						if (count[i] == 4) dice[i].roll('N');
						dice[i].roll('W');
						count[i]++;
						if (count[i] != 10)
						{
							break;
						}
					}
				}
			}
			bool b = true;
			foreach (var x in count)
			{
				b &= x == 10;
			}

			if(b) Console.WriteLine("Yes");
			else Console.WriteLine("No");


		}

		public static bool checkdice(Dice dice1, Dice dice2)
		{
			if (dice1.face == dice2.face && dice1.N == dice2.N && dice1.E == dice2.E && dice1.S == dice2.S && dice1.W == dice2.W && dice1.back == dice2.back) return true;
			else return false;
		}

	}
}