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;

namespace ITP1_11_D
{
    class Dice
    {
        //static int count = 0;
        int[] srf_current = new int[6];
        int[] srf_first = new int[6];

        public Dice(int[] x)
        {
            for (int i = 0; i < 6; i++)
                srf_current[i] = srf_first[i] = x[i];
        }

        public int this[int index]
        {
            get { return srf_current[index]; }
            set { srf_current[index] = value; }
        }

        public void turn(char vct)
        {
            int[] sub = new int[6];

            for (int i = 0; i < 6; i++)
                sub[i] = srf_current[i];

            switch (vct)
            {
                case 'S':
                    srf_current[0] = sub[4];
                    srf_current[1] = sub[0];
                    srf_current[5] = sub[1];
                    srf_current[4] = sub[5];
                    break;
                case 'N':
                    srf_current[0] = sub[1];
                    srf_current[1] = sub[5];
                    srf_current[5] = sub[4];
                    srf_current[4] = sub[0];
                    break;
                case 'W':
                    srf_current[0] = sub[2];
                    srf_current[2] = sub[5];
                    srf_current[5] = sub[3];
                    srf_current[3] = sub[0];
                    break;
                case 'E':
                    srf_current[0] = sub[3];
                    srf_current[2] = sub[0];
                    srf_current[5] = sub[2];
                    srf_current[3] = sub[5];
                    break;
                default:
                    break;
            }
            //count++;
            //foreach (var s in srf_current)
            //    Console.Write(" " + s);
            //Console.WriteLine("  " + count + " " + vct);
        }

        public void reset()
        {
            //Console.WriteLine("reset");
            for (int i = 0; i < 6; i++)
            {
                srf_current[i] = srf_first[i];
                //Console.Write(" " + srf_current[i]);
            }
            //Console.WriteLine();      
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dice d1 = new Dice(Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
            var input = new List<Dice>();
            bool isEqual = true;

            for (int i = 0; i < n - 1; i++)
            {
                Dice d = new Dice(Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
                input.Add(d);
            }
            foreach (var i in input)
            {
                for (int j = 0; j < 4; j++)
                {
                    isEqual = checkD(i, d1);
                    if (isEqual || j == 3) break;
                    else
                    {
                        i.reset();
                        for (int l = 0; l <= j; l++) i.turn('S');
                    }
                }
                if (!isEqual)
                {
                    i.reset();
                    i.turn('E');
                    i.turn('N');
                    i.turn('W');
                    isEqual = checkD(i, d1);
                }
                if (!isEqual)
                {
                    i.reset();
                    i.turn('W');
                    i.turn('N');
                    i.turn('E');
                    isEqual = checkD(i, d1);
                }
                if (isEqual) break;
            }
            if (isEqual) Console.WriteLine("No");
            else Console.WriteLine("Yes");
        }
        static bool checkD(Dice x, Dice y)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; x[j] == y[j]; j++)
                    if (j == 5)
                        return true;

                if (i == 3) break;
                else x.turn('E');
            }
            return false;
        }
    } 
}