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;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputN = Console.ReadLine();
            int n = int.Parse(inputN);
            ArrayList ruikei = new ArrayList();
            string bn = null;
            int c = 0;
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                string[] saikoro = Console.ReadLine().Split(' ');
                int b0 = int.Parse(saikoro[0]);
                int b1 = int.Parse(saikoro[1]);
                int b2 = int.Parse(saikoro[2]);
                int b3 = int.Parse(saikoro[3]);
                int b4 = int.Parse(saikoro[4]);
                int b5 = int.Parse(saikoro[5]);

                if (i != 0)//?§??????????????????????
                {
                    for (int j = 0; j < i; j++) // ???????????????????????°???????????????????????????
                    {
                        string s = ruikei[j].ToString(); //???????????????????????°???????????£?????????
                        string s0 = s[0].ToString();
                        string s1 = s[1].ToString();
                        string s2 = s[2].ToString();
                        string s3 = s[3].ToString();
                        string s4 = s[4].ToString();
                        string s5 = s[5].ToString();

                        int a0 = int.Parse(s0);
                        int a1 = int.Parse(s1);
                        int a2 = int.Parse(s2);
                        int a3 = int.Parse(s3);
                        int a4 = int.Parse(s4);
                        int a5 = int.Parse(s5);


                        if ((a0 == b3 || a0 == b2) && (a5 == b3 || a5 == b2))//?????????????????????
                        {
                            c = b1;
                            b1 = b2;
                            b2 = b4;
                            b4 = b3;
                            b3 = c;
                        }
                        for (int k = 0; k < 3; k++)//?????????
                        {
                            if (a0 == b0 && a5 == b5)
                            {
                                break;
                            }
                            else
                            {
                                c = b0;
                                b0 = b1;
                                b1 = b5;
                                b5 = b4;
                                b4 = c;
                            }
                        }
                        for (int k = 0; k < 3; k++)//?¨???????
                        {
                            if (a1 == b1 && a4 == b4)
                            {
                                break;
                            }
                            else
                            {
                                c = b1;
                                b1 = b2;
                                b2 = b4;
                                b4 = b3;
                                b3 = c;
                            }
                        }
                        if (a0 == b0 && a0 == b0 && a1 == b1 && a2 == b2 && a3 == b3 && a4 == b4 && a5 == b5)
                             count += 1;
                    }
                }
                bn = b0.ToString() + b1.ToString() + b2.ToString() + b3.ToString() + b4.ToString() + b5.ToString();
                ruikei.Add(bn);
            }
            if (count == 0)
                Console.WriteLine("Yes");
            else if (count != 0)
                Console.WriteLine("No");
        }
    }
}