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 aoj11d
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());          //?????????????????°

            DICE[] dicecase = new DICE[n];                  //n??????????´??????????DICE?????????????????£?¨? ??????????????????????????????

            /*??????????´???????????????????????????????*/
            for(int i = 0; i < n; i++)
            {
                dicecase[i] = new DICE(Console.ReadLine());
            }

            for(int i = 0; i < n; i++)
            {
                for(int j = i+1; j < n; j++)
                {
                    if (compareDice(dicecase[i], dicecase[j]))//???????????????true?????£??????
                    {
                        Console.WriteLine("No");    //No?????????????????????
                        return;
                    }
                }
            }

            /*?????????????????????????????????????????????????????????????????£???*/
            Console.WriteLine("Yes");



        }//Main???????????§


        /*???????????????????????????????????????????¬?????????????????????????????????????*/
        private static bool compareDice(DICE diceA, DICE diceB)
        {
            /*?????????????????????*/

            for (int i = 1; i <= 4; i++)
            {
                if (rotateDice(diceA, diceB))
                {
                    return true;
                }

                diceA.rotateN();
            }
            /*???????????§??§true?????????????????´??????N?????¢???4?????????????????¶???????????£?????????*/

            diceA.rotateE();

            /*???????????????*/
            if (rotateDice(diceA, diceB))
            {
                return true;
            }

            diceA.rotateE();
            diceA.rotateE();

            /*???????????????*/
            if (rotateDice(diceA, diceB))
            {
                return true;
            }

            /*???????????§true?????????????????£?????´???false??§?¢????*/
            return false;
        }


 

        /*????¨????????????¢????????????match???????????????????????????
         * ?????????????????????diceA????????¢???????????????false???????????´??????
         * diceA?????¶????????????????????????????????¶????????????*/
        private static bool rotateDice(DICE diceA, DICE diceB)
        {
            for (int i = 1; i <= 4; i++)
            {
                if (matchDice(diceA, diceB))
                {
                    return true;
                }
                diceA.rotateCW();
            }
            return false;
        }

        /*?????????????????????????????¢?????°???????????¨?????´????????????????????????????????????*/
        private static bool matchDice(DICE diceA, DICE diceB)
        {
            if (diceA.TOP == diceB.TOP && diceA.FRONT == diceB.FRONT && diceA.RIGHT == diceB.RIGHT
                    && diceA.LEFT == diceB.LEFT && diceA.BACK == diceB.BACK && diceA.BOTTOM == diceB.BOTTOM)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


    }

    internal class DICE
    {
        #region ?????£?????????
        public int TOP { get; set; }
        public int FRONT { get; set; }
        public int RIGHT { get; set; }
        public int LEFT { get; set; }
        public int BACK { get; set; }
        public int BOTTOM { get; set; }
        #endregion

        public DICE(string str)

        {
            int[] label = new int[6];
            string[] line = str.Split(' ');
            for (int i = 0; i < 6; i++)
            {
                label[i] = int.Parse(line[i]);
            }

            TOP = label[0];
            FRONT = label[1];
            RIGHT = label[2];
            LEFT = label[3];
            BACK = label[4];
            BOTTOM = label[5];
        }

        public DICE()//?????°???????????´???

        {
            TOP = 1;
            FRONT = 2;
            RIGHT = 3;
            LEFT = 4;
            BACK = 5;
            BOTTOM = 6;
        }


        internal void show()
        {
            Console.WriteLine(TOP + " " + FRONT + " " + RIGHT + " " + LEFT + " " + BACK + " " + BOTTOM);
        }

        internal void rotateN()//N???????????¢
        {
            int tmp = TOP;
            TOP = FRONT;
            FRONT = BOTTOM;
            BOTTOM = BACK;
            BACK = tmp;
        }
        internal void rotateS()//S???????????¢
        {
            rotateN();
            rotateN();
            rotateN();
        }
        internal void rotateE()//E???????????¢
        {
            int tmp = TOP;
            TOP = LEFT;
            LEFT = BOTTOM;
            BOTTOM = RIGHT;
            RIGHT = tmp;
        }
        internal void rotateW()//W???????????¢
        {
            rotateE();
            rotateE();
            rotateE();
        }
        internal void rotateCW()//TOP-BOTTOM??????????¨???????
        {
            int tmp = FRONT;
            FRONT = RIGHT;
            RIGHT = BACK;
            BACK = LEFT;
            LEFT = tmp;
        }
    }
}