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;
using System.Collections.Generic;
using System.Text;

namespace ITP1_11_D
{
	class Program
	{
		// faces[] = { 0, 1, 2, 3, 4, 5, 6 };
		//   0
		// 3 1 2 4
		//   5
		static void Main(string[] args)
		{
			string s1 = Console.ReadLine();
			int count = int.Parse(s1);

			List<Dice> diceList = new List<Dice>();
			bool result = false;
			for (int k = 0; k < count; k++) {
				string s2 = Console.ReadLine();
				string[] faces = s2.Split();
				Dice dice = new Dice(faces);
				if (diceList.Contains(dice)) {
					result = true;
				}
				diceList.Add(dice);
			}

			if (result) {
				Console.WriteLine("No");
			} else {
				Console.WriteLine("Yes");
			}

			//Console.WriteLine("Hit Any Key");
			//Console.ReadLine();
		}
	}

	class Dice : IEquatable<Dice>
	{
		//   1
		// 4 2 3 5
		//   6
		public string Top { get; private set; }
		public string North { get; private set; }
		public string South { get; private set; }
		public string East { get; private set; }
		public string West { get; private set; }
		public string Bottom { get; private set; }
		public Dice(string[] faces)
		{
			Top = faces[0];
			North = faces[4];
			South = faces[1];
			East = faces[2];
			West = faces[3];
			Bottom = faces[5];
		}
		public Dice(Dice dice)
		{
			Top = dice.Top;
			North = dice.North;
			South = dice.South;
			East = dice.East;
			West = dice.West;
			Bottom = dice.Bottom;
		}
		public void MoveN()
		{
			// T<-S<-B<-N<-T
			string tmp = Top;
			Top = South;
			South = Bottom;
			Bottom = North;
			North = tmp;
		}
		public void MoveS()
		{
			// T<-N<-B<-S<-T
			string tmp = Top;
			Top = North;
			North = Bottom;
			Bottom = South;
			South = tmp;
		}
		public void MoveE()
		{
			// T<-W<-B<-E<-T
			string tmp = Top;
			Top = West;
			West = Bottom;
			Bottom = East;
			East = tmp;
		}
		public void MoveW()
		{
			// T<-E<-B<-W<-T
			string tmp = Top;
			Top = East;
			East = Bottom;
			Bottom = West;
			West = tmp;
		}
		public void MoveCW()
		{
			// N<-W<-S<-E<-N
			string tmp = North;
			North = West;
			West = South;
			South = East;
			East = tmp;
		}
		public void MoveCCW()
		{
			// N<-E<-S<-W<-N
			string tmp = North;
			North = East;
			East = South;
			South = West;
			West = tmp;
		}

		public bool Equals(Dice other)
		{
			for (int i = 0; i < 6; i++) {
				Dice dice2 = new Dice(other);
				switch (i) {
				case 0:
					break;
				case 1:
					dice2.MoveS();
					break;
				case 2:
					dice2.MoveN();
					break;
				case 3:
					dice2.MoveW();
					break;
				case 4:
					dice2.MoveE();
					break;
				case 5:
					dice2.MoveN();
					dice2.MoveN();
					break;
				}
				for (int j = 0; j < 4; j++) {
					if (Top == dice2.Top && Bottom == dice2.Bottom &&
						North == dice2.North && South == dice2.South &&
						East == dice2.East && West == dice2.West) {
						return true;
					}
					dice2.MoveCW();
				}
			}
			return false;
		}
	}
}