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;

namespace Dice
{   

    class Program
    {
        readonly static Dise[] dise = new Dise[100];

        static void Main(string[] args)
        {
            //サイコロ数
            short n;

            //サイコロ
            string result = "Yes";
            
            //サイコロ数
            n = short.Parse(Console.ReadLine());

            for(short i = 0; i < n; i++)
            {
                dise[i] = new Dise();
            }

            //指定サイコロ数入力
            for (short i = 0; i < n; i++)
            {
                //目を入力
                dise[i].InputNumber();
                //同じサイコロが存在するか
                if (result == "Yes" && IsDistance(i))
                {
                    result = "No";
                    break;
                }
            }

            Console.WriteLine(result);
        }

        static bool IsDistance(short i)
        {
            Dise copy = dise[i];
            short k, l, m;

            for (short j = 0; j < i; j++)
            {

                for (k = 0; k < 6; k++)
                {
                    //てっぺんと同じ数字
                    if (copy.num[k] == dise[j].num[0])
                    {
                        break;
                    }
                }
                //同じ数字がない
                if (k < 6)
                {
                    //てっぺん合わせ
                    copy.RotateTop(k);
                    for (l = 0; l < 6; l++)
                    {
                        //前面と同じ値
                        if (copy.num[l] == dise[j].num[1])
                        {
                            break;
                        }
                    }
                    //下面 同じ数字なし
                    if (l != 5)
                    {
                        //前面合わせ
                        copy.RotateFront(l);
                    }

                    //面調べる
                    for (m = 0; m < 6; m++)
                    {
                        //異なる
                        if (dise[j].num[m] != copy.num[m])
                        {
                            break;
                        }
                    }
                    //全て同じなら
                    if (m == 6)
                    {
                        return true;
                    }
                }
            }
            //全て異なる
            return false;
        }
    }

    class Dise
    {
        public short[] num = new short[6];

        public void InputNumber()
        {
            string[] str = Console.ReadLine().Split(' ');

            //計6マス入力
            for (short i = 0; i < 6; i++)
            {
                num[i] = short.Parse(str[i]);
            }
        }

        public void RotateTop(short pos)
        {
            //すでに上面
            if (pos == 0)
            {
                return;
            }

            if (pos == 5)
            {
                Swap(ref num[0],ref num[5]);
                Swap(ref num[1], ref num[4]);
                return;
            }

            //反対側以外
            Swap(ref num[pos],ref num[0]);
            Swap(ref num[pos], ref num[5 - pos]);
            Swap(ref num[pos], ref num[5]);
        }

        public void RotateFront(short pos)
        {
            //すでに前
            if (pos == 1)
            {
                return;
            }

            //後ろ面
            if (pos == 4)
            {
                Swap(ref num[1], ref num[4]);
                Swap(ref num[2], ref num[3]);
                return;
            }

            Swap(ref num[pos], ref num[1]);
            Swap(ref num[pos], ref num[5 - pos]);
            Swap(ref num[pos], ref num[4]);
        }

        public void Swap(ref short a,ref short b)
        {
            short c = a;
            a = b;
            b = c;
        }
    };
}