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;

public class Program
{
	public static void Main()
	{
		int q = int.Parse(Console.ReadLine());
		
		Dice[] d = new Dice[q];
		
		for(int i = 0; i < q; i++ ) {
			d[i] = new Dice(Console.ReadLine().Split(' '));
		}
		
		bool result = true;
		for(int i = 1; i < q; i++ ) {
			result &= !d[i-1].IsEquals(d[i]);
		}
		
		if(result) Console.WriteLine("Yes");
		else	Console.WriteLine("No");
	}
}

public class Dice
{
	public string Left { get; private set; }
	public string Front { get; private set; }
	public string Right { get; private set; }
	public string Rear { get; private set; }
	public string Top { get; private set; }
	public string Bottom { get; private set; }

	//   4
	// 3 0 2 5
	//   1
	public Dice(string[] faces)
	{
		Front = faces[0];
		Bottom = faces[1];
		Right = faces[2];
		Left = faces[3];
		Top = faces[4];
		Rear = faces[5];
	}

	public void RollX(bool direction)
	{
		var tmp = "";
		if(direction) {
			tmp = Top;
			Top = Front;
			Front = Bottom;
			Bottom = Rear;
			Rear = tmp;
		} else {
			tmp = Top;
			Top = Rear;
			Rear = Bottom;
			Bottom = Front;
			Front = tmp;
		}
	}

	public void RollY(bool direction)
	{
		var tmp = "";
		if(direction) {
			tmp = Top;
			Top = Right;
			Right = Bottom;
			Bottom = Left;
			Left = tmp;
		} else {
			tmp = Top;
			Top = Left;
			Left = Bottom;
			Bottom = Right;
			Right = tmp;
		}
	}

	public void RollZ(bool direction)
	{
		var tmp = "";
		if(direction) {
			tmp = Front;
			Front = Right;
			Right = Rear;
			Rear = Left;
			Left = tmp;
		} else {
			tmp = Front;
			Front = Left;
			Left = Rear;
			Rear = Right;
			Right = tmp;
		}
	}

	public void Roll(char direction)
	{
		var c = char.ToUpper(direction);

		switch(c){
			case 'N':	RollX(true);	break;
			case 'S':	RollX(false);	break;
			case 'W':	RollY(true);	break;
			case 'E':	RollY(false);	break;
			case 'U':	RollZ(true);	break;
			case 'D':	RollZ(false);	break;
		}

		//Console.WriteLine(this.Left + this.Front + this.Right + this.Rear + this.Top + this.Bottom);
	}

	public bool IsEquals(Dice d)
	{
		foreach ( var c in "UUUUNUUUUNUUUUNUUUUEUUUUSSUUUU".ToCharArray()) {
			if(this.Bottom == d.Bottom &&
			   this.Front == d.Front &&
			   this.Left == d.Left &&
			   this.Rear == d.Rear &&
			   this.Right == d.Right &&
			   this.Top == d.Top){
				return true;
			}

			d.Roll(c);
		}

		return false;
	}
}