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

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                for (int j = 0; j < 6; j++)
                    number[j] = int.Parse(input[j]);
                numbers[i] = new Dice(number);
            }
            string result = null;
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (i == j)
                        break;
                    result = numbers[i].Hantei(numbers[j]);
                    if (result == "yes")
                        break;
                }
                if (result == "yes")
                    break;
            }
            if(result=="Yes")
                Console.WriteLine("No");
            else
                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 string Hantei(Dice saikoro) 
        {

            string yes = "Yes";
            string no = "No";
            string result = null;

            int abc0 = saikoro.D[0]; //1
            int abc1 = saikoro.D[1]; //2
            int abc2 = saikoro.D[2]; //3
            int abc3 = saikoro.D[3]; //4
            int abc4 = saikoro.D[4]; //5
            int abc5 = saikoro.D[5]; //6

            if (this.D[0] == saikoro.D[0])
            {
                if (this.D[5] != saikoro.D[5])
                    result = no;
                if (this.D[5] == saikoro.D[5])
                {
                    while (true)
                    {
                        if (this.D[1] != saikoro.D[1])
                        {
                            saikoro.Kaiten();
                        }
                        if (this.D[1] == saikoro.D[1])
                            break;
                    }
                    if (this.D[4] != saikoro.D[4])
                        result = no;
                    if (this.D[4] == saikoro.D[4])
                    {
                        if (this.D[2] != saikoro.D[2])
                            result = no;
                        if (this.D[2] == saikoro.D[2])
                            result = yes;
                    }
                }
            }
            if (this.D[1] == saikoro.D[0])
            {
                if (this.D[4] != saikoro.D[5])
                    result = no;
                if (this.D[4] == saikoro.D[5])
                {
                    while (true)
                    {
                        if (this.D[5] != saikoro.D[1])
                        {
                            saikoro.Kaiten();
                        }
                        if (this.D[5] == saikoro.D[1])
                            break;
                    }
                    if (this.D[0] != saikoro.D[4])
                        result = no;
                    if (this.D[0] == saikoro.D[4])
                    {
                        if (this.D[2] != saikoro.D[2])
                            result = no;
                        if (this.D[2] == saikoro.D[2])
                            result = yes;
                    }
                }
            }
            if (this.D[2] == saikoro.D[0])
            {
                if (this.D[3] != saikoro.D[5])
                    result = no;
                if (this.D[3] == saikoro.D[5])
                {
                    while (true)
                    {
                        if (this.D[5] != saikoro.D[1])
                        {
                            saikoro.Kaiten();
                        }
                        if (this.D[5] == saikoro.D[1])
                            break;
                    }
                    if (this.D[0] != saikoro.D[4])
                        result = no;
                    if (this.D[0] == saikoro.D[4])
                    {
                        if (this.D[4] != saikoro.D[2])
                            result = no;
                        if (this.D[4] == saikoro.D[2])
                            result = yes;
                    }
                }
            }
            if (this.D[3] == saikoro.D[0])
            {
                if (this.D[2] != saikoro.D[5])
                    result = no;
                if (this.D[2] == saikoro.D[5])
                {
                    while (true)
                    {
                        if (this.D[5] != saikoro.D[1])
                        {
                            saikoro.Kaiten();
                        }
                        if (this.D[5] == saikoro.D[1])
                            break;
                    }
                    if (this.D[0] != saikoro.D[4])
                        result = no;
                    if (this.D[0] == saikoro.D[4])
                    {
                        if (this.D[1] != saikoro.D[2])
                            result = no;
                        if (this.D[1] == saikoro.D[2])
                            result = yes;
                    }
                }
            }
            if (this.D[4] == saikoro.D[0])
            {
                if (this.D[1] != saikoro.D[5])
                    result = no;
                if (this.D[1] == saikoro.D[5])
                {
                    while (true)
                    {
                        if (this.D[5] != saikoro.D[1])
                        {
                            saikoro.Kaiten();
                        }
                        if (this.D[5] == saikoro.D[1])
                            break;
                    }
                    if (this.D[0] != saikoro.D[4])
                        result = no;
                    if (this.D[0] == saikoro.D[4])
                    {
                        if (this.D[3] != saikoro.D[2])
                            result = no;
                        if (this.D[3] == saikoro.D[2])
                            result = yes;
                    }
                }
            }
            if (this.D[5] == saikoro.D[0])
            {
                if (this.D[0] != saikoro.D[5])
                    result = no;
                if (this.D[0] == saikoro.D[5])
                {
                    while (true)
                    {
                        if (this.D[1] != saikoro.D[1])
                        {
                            saikoro.Kaiten();
                        }
                        if (this.D[1] == saikoro.D[1])
                            break;
                    }
                    if (this.D[4] != saikoro.D[4])
                        result = no;
                    if (this.D[4] == saikoro.D[4])
                    {
                        if (this.D[3] != saikoro.D[2])
                            result = no;
                        if (this.D[3] == saikoro.D[2])
                            result = yes;
                    }
                }
            }
            return result;            
        }
    }
}