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: Runtime Error)

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        int diceCount = int.Parse(Reader.ReadLine());
        List<Dice> list = new List<Dice>();
        for (int i = 0; i < diceCount; i++) {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            list.Add(new Dice(inpt));
        }
        String ans = "Yes";
        for (int i = 0; i < diceCount - 1; i++) {
            for (int j = i + 1; j < diceCount; j++) {
                if(list[i].IsSame(list[j])) {
                    ans = "No";
                    break;
                }
            }
            if(ans.Equals("No")) {
                break;
            }
        }
        Console.WriteLine(ans);
    }

    private class Dice {
        DiceState state = new DiceState(1, 2, 3);
        public int[] Label;
        public Dice(int[] label) {
            this.Label = label;
        }
        public int GetTopNum() {
            return this.Label[this.state.Top - 1];
        }
        public void Move(String str) {
            foreach(char c in str) {
                if(c == 'N') {
                    this.state = this.Move(this.state, MoveDir.N);
                } else if(c == 'S') {
                    this.state = this.Move(this.state, MoveDir.S);
                } else if( c== 'E') {
                    this.state = this.Move(this.state, MoveDir.E);
                } else {
                    this.state = this.Move(this.state, MoveDir.W);
				}
            }
        }

        public int GetRightNum(int topNum, int frontNum) {
            int topIdx = this.Label.ToList().IndexOf(topNum) + 1;
            int frontIdx = this.Label.ToList().IndexOf(frontNum) + 1;
            int rightIdx = GetRight(topIdx, frontIdx);
            this.state = new DiceState(topIdx, frontIdx, rightIdx);
            return this.Label[rightIdx - 1];
        }

        public bool IsSame(Dice target) {
            if(!this.Label.All(a=>target.Label.Count(b=>b==a) == this.Label.Count(b=>b==a))) {
                return false;
            }
            if(this.Label.Distinct().Count()<=2) {
                return true;
            }
            int topNum = this.GetTopNum();
            int frontNum = this.Label[this.state.Front - 1];
            int rightNum = this.Label[this.state.Rigt - 1];

            if(rightNum != target.GetRightNum(topNum, frontNum)) {
                return false;
            }
            this.Move("NN");
            target.Move("NN");
            return this.GetTopNum() == target.GetTopNum() && this.Label[this.state.Front - 1] == target.Label[target.state.Front - 1]; 
		}

        public static int GetRight(int top, int front) {
            if((top == 1 && front == 2)||(top == 2 && front == 6) || (top == 6 && front == 5) || (top == 5 && front == 1)) {
                return 3;
            }
            if((top == 1 && front == 3) || (top == 3 && front == 6) || (top == 6 && front == 4) || (top == 4 && front == 1)) {
                return 5;
            }
            if((top == 4 && front == 2) || (top == 2 && front == 3) || (top == 3 && front == 5) || (top == 5 && front == 4)) {
                return 1;
            }
            return 7 - GetRight(front, top);
		}

		private DiceState Move(DiceState current, MoveDir md)
		{
			DiceState ret = new DiceState(current.Top, current.Front, current.Rigt);
			if (md == MoveDir.N)
			{
				ret.Top = current.Front;
				ret.Front = 7 - current.Top;
			}
			if (md == MoveDir.S)
			{
				ret.Top = 7 - current.Front;
				ret.Front = current.Top;
			}
			if (md == MoveDir.E)
			{
				ret.Top = 7 - current.Rigt;
				ret.Rigt = current.Top;
			}
            if (md == MoveDir.W)
			{
				ret.Top = current.Rigt;
				ret.Rigt = 7 - current.Top;
			}
			return ret;
		}


	}


    private struct DiceState {
        public int Top;
        public int Front;
        public int Rigt;
        public DiceState(int t, int f, int r) {
            this.Top = t;
            this.Front = f;
            this.Rigt = r;
        }
    }

    enum MoveDir {
        N,
        S,
        E,
        W
    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}