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

//ITP1_11-D


namespace ConsoleApplication28
{
    class Dice
    {
        int[] dArray;

        public Dice(string[] a)
        {
            dArray = Parse(a);
        }

        public void RollToTop(int diceIndex)
        {
            switch (diceIndex)
            {
                case 0:
                    break;

                case 1:
                    RollNorth();
                    break;

                case 2:
                    RollWest();
                    break;

                case 3:
                    RollEast();
                    break;

                case 4:
                    RollSouth();
                    break;

                case 5:
                    RollNorth();
                    RollNorth();
                    break;
            }
               
        }

        void RollNorth()
        {
            int temp;
            temp = dArray[0];
            dArray[0] = dArray[1];
            dArray[1] = dArray[5];
            dArray[5] = dArray[4];
            dArray[4] = temp;
        }

        void RollEast()
        {
            int temp;
            temp = dArray[0];
            dArray[0] = dArray[3];
            dArray[3] = dArray[5];
            dArray[5] = dArray[2];
            dArray[2] = temp;
        }

        void RollSouth()
        {
            int temp;
            temp = dArray[0];
            dArray[0] = dArray[4];
            dArray[4] = dArray[5];
            dArray[5] = dArray[1];
            dArray[1] = temp;
        }

        void RollWest()
        {
            int temp;
            temp = dArray[0];
            dArray[0] = dArray[2];
            dArray[2] = dArray[5];
            dArray[5] = dArray[3];
            dArray[3] = temp;
        }

        public void RollSide()
        {
            int temp;
            temp = dArray[2];
            dArray[2] = dArray[1];
            dArray[1] = dArray[3];
            dArray[3] = dArray[4];
            dArray[4] = temp;
        }

        //?????¢????????´??????????????????
        public bool IsEqualToAllFaces(int[] d)
        {
            for (int i = 0; i < dArray.Length; ++i)
            {
                if (dArray[i] != d[i])
                {
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// ??????????????????????????????????????????
        /// </summary>
        /// <param name="d2">??????????????????????????????</param>
        /// <returns>??????????????????</returns>
        public bool IsSameAsDice(Dice d2)
        {
            for (int i = 0; i < d2.dArray.Length; ++i)
            {
                if (d2.dArray[0] == dArray[i])
                {
                    RollToTop(i);

                    for (int j = 0; j < 4; ++j)
                    {
                        if ( IsEqualToAllFaces(d2.dArray))
                        {
                            return true;
                        }
                        RollSide();
                    }

                }
            }
            return false;
        }
                

        public int[] Parse(string[] str)
        {
            int[] intArray = new int[str.Length];
            for (int i = 0; i < str.Length; ++i)
            {
                intArray[i] = int.Parse(str[i]);
            }
            return intArray;
        }

    }



    class Program
    {
        static void Main()
        {

            int n = int.Parse(Console.ReadLine());
            bool b = false;
            Dice[] dice = new Dice[n];
            string[] str = new string[n];

            for (int i = 0; i < n; ++i)
            {
                str[i] = Console.ReadLine();
                dice[i] = new Dice(str[i].Split(' '));
            }
            
            
               
            for (int i = 0; i < n; ++i)
            {
                if (b)
                {
                    break;
                }
                
                for (int j =(i + 1); j < n; ++j)
                {
                   
                    b = dice[i].IsSameAsDice(dice[j]);
                    if (b)
                    {
                        break;
                    }
                }  
            }
            
            if (b)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }

        }
    }
}