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 ConsoleApplication12
{
    class DICE
    {
        int kari = 0;
        public void S(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[4];
            sai2[4] = sai2[5];
            sai2[5] = sai2[1];
            sai2[1] = kari;
        }
        public void N(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[1];
            sai2[1] = sai2[5];
            sai2[5] = sai2[4];
            sai2[4] = kari;
        }
        public void W(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[2];
            sai2[2] = sai2[5];
            sai2[5] = sai2[3];
            sai2[3] = kari;
        }
        public void E(int[] sai2)
        {
            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)
        {
            int count = 0;
            int input3 = int.Parse(Console.ReadLine());
            int ans = 0;

            int[] diceA = new int[6];
            int[] diceB = new int[6];

            for (int kosuu = 0; kosuu < input3; kosuu++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int[] sai2 = new int[6];
                //???§???????????????????????????
                ArrayList data = new ArrayList();
                //???????????????????????????????????????
                DICE dice = new DICE();
                //?????????????????????
                for (int i = 0; i < input3; i++)
                {
                    sai2 = new int[6];

                    for (int h = 0; h < 6; h++)
                    {
                        sai2[h] = int.Parse(input[h]);
                    }
                    data.Add(sai2);
                }
                //??????????????????????????????????????????
                for (int v = 0; v < kosuu; v++)
                {
                    for (int t = 0; t < kosuu; t++)
                    {
                        if (v != t)
                        {
                            diceA = (int[])data[v];
                            diceB = (int[])data[t];
                            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;
                                                }
                                                if (count >= 6)
                                                {
                                                    ans = ans + 1;
                                                    break;
                                                }
                                            }
                                            dice.E(diceB);
                                        }
                                        dice.S((int[])data[kosuu]);
                                    }
                                    dice.W(diceB);
                                }
                                dice.N(diceB);
                            }

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