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

//ITP1_11-D


namespace ConsoleApplication28
{
    class Dice
    {
        int[] DArray;

        public Dice(string[] a)
        {
            DArray = parse(a);
        }

        public bool DiceRoll(int roll)
        {
            if (FindIndex(roll))
            {
                switch (roll)
                {
                    case 0:
                        break;

                    case 1:
                        RollNorth();
                        break;

                    case 2:
                        RollWest();
                        break;

                    case 3:
                        RollEast();
                        break;

                    case 4:
                        RollSouth();
                        break;

                    case 5:
                        RollNorth();
                        RollNorth();
                        break;
                }
                return true;
            }
           
            return false;
        }

        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 bool DiceRoll2(int a)
        {
            int count = 0;
            while (a != DArray[1])
            {
                if (count == 4)
                {
                    return false;
                }
                int temp;
                temp = DArray[2];
                DArray[2] = DArray[1];
                DArray[1] = DArray[3];
                DArray[3] = DArray[4];
                DArray[4] = temp;
                ++count;
            }
            return true;

        }

        public bool FindIndex(int s)
        {
            for (int i = 0; i < DArray.Length; ++i)
            {
                if (DArray[i] == s)
                {
                    return true;
                }
            }
            return false;
        }


        public bool hantei1(int[] d)
        {
            for (int i = 0; i < DArray.Length; ++i)
            {
                if (DArray[i] != d[i])
                {
                    return false;
                }
            }
            return true;
        }

        public bool hantei2(Dice D2)
        {
            
            for (int i = 0; i < D2.DArray.Length; ++i)
            {
                if (D2.DArray[0] == DArray[i])
                {
                    bool bl;
                    DiceRoll(i);
                    bl = DiceRoll2(D2.DArray[1]);
                    bl = hantei1(D2.DArray);
                    if (bl)
                    {
                        return true;
                    }
                }
            }
           
            if (hantei3(D2))
            {
                return true;
            }

            return false;
        }

        public bool hantei3(Dice D2)
        {
            for (int i = 0; i < D2.DArray.Length; ++i)
            {
                for (int j = (i + 1); j < D2.DArray.Length; ++j)
                {
                    if (D2.DArray[i] == D2.DArray[j])       //???????????????????????°????????????????????????
                    {
                        int temp = D2.DArray[0];
                        D2.DArray[0] = D2.DArray[1];
                        D2.DArray[1] = D2.DArray[2];
                        D2.DArray[2] = D2.DArray[3];
                        D2.DArray[3] = D2.DArray[4];
                        D2.DArray[4] = D2.DArray[5];
                        D2.DArray[5] = temp;

                        if ( hantei2(D2))
                        {
                            return true;
                        }
                    }
                }
            }
            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].hantei2(dice[j]);

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

        }
    }
}