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 ITP1_11_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dice[] numbers = new Dice[n];
            string result = null;

            for (int i = 0; i < n; i++)
            {
                int[] number = new int[6];
                string[] input = Console.ReadLine().Split(' ');
                for (int j = 0; j < 6; j++)
                    number[j] = int.Parse(input[j]);  //intに変換

                Dice tmp = new Dice(number);
                numbers[i] = tmp;
            }
            
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    result = numbers[i].Hantei(numbers[j]);
                    if (result == "No")
                        break;
                }
                if (result == "No")
                    break;
            }
            if (result == "No")
                Console.WriteLine("No");
            if (result == "Yes")
                Console.WriteLine("Yes");
        }
    }

    class Dice
    {
        public int[] D;
        public Dice(int[] data)
        {
            D = data;
        }
        public void Kaiten()
        {
            int D1, D2, D4, D3;
            D1 = this.D[1];
            D2 = this.D[2];
            D3 = this.D[3];
            D4 = this.D[4];
            this.D[1] = D2;
            this.D[2] = D4;
            this.D[4] = D3;
            this.D[3] = D1;
        }
        public void ToE()
        {
            int D0, D2, D5, D3;
            D0 = this.D[0];
            D2 = this.D[2];
            D3 = this.D[3];
            D5 = this.D[5];
            this.D[0] = D3;
            this.D[2] = D0;
            this.D[3] = D5;
            this.D[5] = D2;
        }
        public void ToN()
        {
            int D1, D0, D4, D5;
            D1 = this.D[1];
            D0 = this.D[0];
            D5 = this.D[5];
            D4 = this.D[4];
            this.D[0] = D1;
            this.D[1] = D5;
            this.D[4] = D0;
            this.D[5] = D4;
        }
        public void ToS()
        {
            int D1, D0, D4, D5;
            D1 = this.D[1];
            D0 = this.D[0];
            D5 = this.D[5];
            D4 = this.D[4];
            this.D[0] = D4;
            this.D[1] = D0;
            this.D[4] = D5;
            this.D[5] = D1;
        }
        public void ToW()
        {
            int D0, D2, D5, D3;
            D0 = this.D[0];
            D2 = this.D[2];
            D3 = this.D[3];
            D5 = this.D[5];
            this.D[0] = D2;
            this.D[2] = D5;
            this.D[5] = D3;
            this.D[3] = D0;
        }

        public void Indata(int[] data)
        {
            this.D[0] = data[0];
            this.D[1] = data[1];
            this.D[2] = data[2];
            this.D[3] = data[3];
            this.D[4] = data[4];
            this.D[5] = data[5];
        }

        public string Hantei(Dice saikoro)
        {
            string yes = "Yes";
            string no = "No";
            string result = null;

            //上面合わせ
            if (saikoro.D[1] == this.D[0])
            {
                saikoro.ToN();
            }
            if (saikoro.D[2] == this.D[0])
            {
                saikoro.ToW();
            }
            if (saikoro.D[3] == this.D[0])
            {
                saikoro.ToE();
            }
            if (saikoro.D[4] == this.D[0])
            {
                saikoro.ToS();
            }
            if (saikoro.D[5] == this.D[0])
            {
                saikoro.ToN();
                saikoro.ToN();
            }
            //上面合わせここまで
            
            //下面チェック
            if (saikoro.D[5] != this.D[5])
                result = yes;

            //前面合わせ
            while (true)
            {
                if (saikoro.D[1] != this.D[1])
                    saikoro.Kaiten();
                if (saikoro.D[1] == this.D[1])
                    break;
            }
            
            //前面合わせここまで
            //背面チェック
            if (saikoro.D[4] != this.D[4])
                result = yes;
            //右面チェック
            if (saikoro.D[2] != this.D[2])
                result = yes;
            else
                result = no;

            return result;
        }
    }
}