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;
using System.Collections;



namespace ConsoleApplication49
{
    class DICE
    {
        public void S(int[] sai2)
        {
            int kari = 0;
            kari = sai2[0];
            sai2[0] = sai2[4];
            sai2[4] = sai2[5];
            sai2[5] = sai2[1];
            sai2[1] = kari;
        }
        public void N(int[] sai2)
        {
            int kari = 0;
            kari = sai2[0];
            sai2[0] = sai2[1];
            sai2[1] = sai2[5];
            sai2[5] = sai2[4];
            sai2[4] = kari;
        }
        public void W(int[] sai2)
        {
            int kari = 0;
            kari = sai2[0];
            sai2[0] = sai2[2];
            sai2[2] = sai2[5];
            sai2[5] = sai2[3];
            sai2[3] = kari;
        }
        public void E(int[] sai2)
        {
            int kari = 0;
            kari = sai2[0];
            sai2[0] = sai2[3];
            sai2[3] = sai2[5];
            sai2[5] = sai2[2];
            sai2[2] = kari;
        }

    }



    class Program
    {
        static void Main(string[] args)
        {
            ArrayList data = new ArrayList();
            int count = 0;
            int input2 = int.Parse(Console.ReadLine());
            int ans = 0;
            int[] diceA = new int[6];
            int[] diceB = new int[6];
         
            for (int kosuu = 0; kosuu < input2; kosuu++)
            {
                DICE dice = new DICE();
                string[] input = Console.ReadLine().Split(' ');
                int[] sai2 = new int[6];
                //????????????????????????°????????\????????????
                for (int h = 0; h < 6; h++)
                {
                    sai2[h] = int.Parse(input[h]);
                }
                //????????????????????????´????????\??????
                data.Add(sai2);
                //????????????????????????¨??????????????????
                for (int sai_1 = 0; sai_1 < kosuu + 1; sai_1++)
                {
                        diceA = (int[])data[sai_1];
                        diceB = (int[])data[kosuu];
                        Console.WriteLine(diceA[sai_1]);
                        Console.WriteLine(diceB[kosuu]);
                        if (sai_1 != kosuu)
                        {
                            Console.WriteLine("aaaaa");
                            for (int n = 0; n < 4; n++)
                            {
                                //?\??????????
                                for (int w = 0; w < 4; w++)
                                {
                                    //?????????
                                    for (int s = 0; s < 4; s++)
                                    {
                                        //???±?????????
                                        for (int e2 = 0; e2 < 4; e2++)
                                        {
                                            count = 0;
                                            //???¢??????°??????????????????????????????
                                            for (int l = 0; l < 6; l++)
                                            {

                                                if (diceA[l] == diceB[l])
                                                {
                                                    count = count + 1;

                                                }
                                                //6????????????£??????????????????????????\??????
                                                if (count == 6)
                                                {
                                                    ans = ans + 1;
                                                    goto EXITLOOP;
                                                    //break;
                                                }
                                            }
                                            dice.E(diceB);
                                        }
                                        dice.S(diceB);
                                    }
                                    dice.W(diceB);
                                }
                                dice.N(diceB);

                            }
                        
                    }

                }
     

            }

        EXITLOOP: ;
            if (ans >= 1)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }

        }
    }
}