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;

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 Rotate(int a, int b, int c, int d)
        {
            int D1, D2, D3, D4;
            D1 = this.D[a];
            D2 = this.D[b];
            D3 = this.D[c];
            D4 = this.D[d];
            this.D[a] = D2;
            this.D[b] = D3;
            this.D[c] = D4;
            this.D[d] = D1;
        }
        public string Hantei(Dice saikoro)
        {
            const string Yes = "Yes";
            const string No = "No";
            string result = null;
            
            //上面と同じ面がなかった場合
            
            //上面合わせ
            if (saikoro.D[1] == this.D[0])
            {
                saikoro.Rotate(0,1,5,4);
            }
            else if (saikoro.D[2] == this.D[0])
            {
                saikoro.Rotate(0,2,5,3);
            }
            else if (saikoro.D[3] == this.D[0])
            {
                saikoro.Rotate(0,3,5,2);
            }
            else if (saikoro.D[4] == this.D[0])
            {
                saikoro.Rotate(0,4,5,1);
            }
            else if (saikoro.D[5] == this.D[0])
            {
                saikoro.Rotate(0,4,5,1);
                saikoro.Rotate(0,4,5,1);
            }
            else
            {
                result = Yes;
                return result;
            }
            //上面合わせここまで

            //下面チェック
            if (saikoro.D[5] != this.D[5])
            {
                result = Yes;
                return result;
            }

            //前面合わせ
            for (int i = 0; i < 4; i++)
            {
                if (saikoro.D[1] != this.D[1])
                    saikoro.Rotate(1,2,4,3);
                if (saikoro.D[1] == this.D[1])
                    break;
                if (i == 3)
                {
                    result = Yes;
                    return result;
                }
            }

            //前面合わせここまで
            //背面チェック
            if (saikoro.D[4] != this.D[4])
            {
                result = Yes;
                return result;
            }
            //右面チェック
            if (saikoro.D[2] != this.D[2])
            {
                result = Yes;
                return result;
            }
            else
                result = No;

            return result;
        }
    }
}