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.Generic;

namespace ConsoleApplication1
{
    class Dice
    {
        private int[] dicelabel = new int[6];
        private int temp = 0;

        public Dice(string num)//???????????????????????°?????\??????
        {
            var dicenum = num.Split(' ');
            for (int i = 0; i < 6; i++)
            {
                dicelabel[i] = int.Parse(dicenum[i]);
            }
        }

        public int[] getDiceLabel//???????????????????????????????????????????????£
        {
            get
            {
                return dicelabel;
            }
        }

        public void roll(string order)//?????????switch??§??????
        {
            switch (order[0])
            {
                case 'N':
                    temp = dicelabel[0];
                    dicelabel[0] = dicelabel[1];
                    dicelabel[1] = dicelabel[5];
                    dicelabel[5] = dicelabel[4];
                    dicelabel[4] = temp;

                    break;
                case 'S':
                    temp = dicelabel[0];
                    dicelabel[0] = dicelabel[4];
                    dicelabel[4] = dicelabel[5];
                    dicelabel[5] = dicelabel[1];
                    dicelabel[1] = temp;

                    break;
                case 'E':
                    temp = dicelabel[0];
                    dicelabel[0] = dicelabel[3];
                    dicelabel[3] = dicelabel[5];
                    dicelabel[5] = dicelabel[2];
                    dicelabel[2] = temp;

                    break;
                case 'W':
                    temp = dicelabel[0];
                    dicelabel[0] = dicelabel[2];
                    dicelabel[2] = dicelabel[5];
                    dicelabel[5] = dicelabel[3];
                    dicelabel[3] = temp;

                    break;
                case 'R':
                    temp = dicelabel[1];
                    dicelabel[1] = dicelabel[2];
                    dicelabel[2] = dicelabel[4];
                    dicelabel[4] = dicelabel[3];
                    dicelabel[3] = temp;

                    break;
            }

        }

        public int getRightSide(string topfront)
        {
            string[] temps = topfront.Split(' ');
            int top = int.Parse(temps[0]);//?????¢??????
            int front = int.Parse(temps[1]);//?????¢??????
            bool match = false;

            for (int i = 0; i < 4; i++)//N???????????¢???????????????????´¢
            {
                for (int j = 0; j < 4; j++)//????????¢?????¨????????¢?????????
                {
                    this.roll("R");
                    if (dicelabel[0] == top && dicelabel[1] == front)
                    {
                        match = true;
                        break;
                    }
                }
                if (match)
                    break;
                this.roll("N");
            }

            for (int i = 0; i < 4; i++)//E???????????¢???????????????????´¢
            {
                if (match)
                    break;
                for (int j = 0; j < 4; j++)//????????¢?????¨????????¢?????????
                {
                    this.roll("R");
                    if (dicelabel[0] == top && dicelabel[1] == front)
                    {
                        match = true;
                        break;
                    }
                }
                if (match)
                    break;
                this.roll("E");//
            }
            //?????¢??¨?????¢????????´?????????????´?2(?????´??¢)?????????
            return dicelabel[2];
        }

        public bool identity(int[] match)//????????????????????????????????????????????????
        {
            bool equal = false;
            int matchcnt = 0;

            //???????????¢???????????????
            for (int h = 0; h < 4; h++)
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)//?????¢??????????????§2????????????????????´?????????????????????
                    {
                        matchcnt = 0;
                        Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", dicelabel[0], dicelabel[1], dicelabel[2], dicelabel[3], dicelabel[4], dicelabel[5]));
                        for (int k = 0; k < match.Length; k++)
                        {
                            if (dicelabel[k] == match[k])
                            {
                                matchcnt++;
                            }
                        }
                        if (matchcnt == 6)//6????????£??????1~6???????´????????????´?????????????????§
                        {
                            equal = true;//equal???true????¨????
                            break;
                        }
                        this.roll("R");        
                    }
                    if (equal)
                        break;
                    this.roll("N");
                }
                if (equal)
                    break;
                this.roll("E");
            }

            return equal;
        }


        class Program
        {
            static void Main(string[] args)
            {
                int n = int.Parse(Console.ReadLine());
                Dice[] dicelist = new Dice[n];
                bool check = true;

                for (int i = 0; i < n; i++)//n???????????????????????????
                {
                    dicelist[i] = new Dice(Console.ReadLine());
                }


                for (int i = 0; i < n-1; i++)
                {
                    for (int j = 1; j < n; j++)
                    {
                        if (dicelist[i].identity(dicelist[j].getDiceLabel))
                        {
                            check = false;
                        }
                    }
                }

                if(check)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }
    }
}