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.Linq;

namespace Structure_and_Class
{
    class Dice_IV
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dices = new Dice4[n];
            for (int i = 0; i < n; i++)
                dices[i] = new Dice4(Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray());

            for (int i = 0; i < n-1; i++)
                for (int j = i + 1; j < n; j++)
                    if (dices[i].IsEqual(dices[j]))
                    {
                        Console.WriteLine("No");
                        return;
                    }
            Console.WriteLine("Yes");
        }
    }

    public class Dice4
    {
        public int[] label = new int[6];

        public Dice4(int[] label)
        {
            this.label = label;
        }

        public bool IsEqual(Dice4 diceB)
        {
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('E');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;

            return false;
        }

        private bool RotaetCheck(Dice4 diceB)
        {
            for (int i = 0; i < 4; i++)
            {
                diceB.Rotate();
                if (label.SequenceEqual(diceB.label)) return true;
            }
            return false;
        }

        public void Move(char c)
        {
            int[] res = new int[6];
            switch (c)
            {
                case 'E':
                    res[0] = label[3];
                    res[1] = label[1];
                    res[2] = label[0];
                    res[3] = label[5];
                    res[4] = label[4];
                    res[5] = label[2];
                    label = res;
                    break;
                case 'N':
                    res[0] = label[1];
                    res[1] = label[5];
                    res[2] = label[2];
                    res[3] = label[3];
                    res[4] = label[0];
                    res[5] = label[4];
                    label = res;
                    break;
                case 'S':
                    Move('N');
                    Move('N');
                    Move('N');
                    break;
                case 'W':
                    Move('E');
                    Move('E');
                    Move('E');
                    break;
            }
        }

        public void Rotate()
        {
            int[] res = new int[6];
            res[0] = label[0];
            res[1] = label[3];
            res[2] = label[1];
            res[3] = label[4];
            res[4] = label[2];
            res[5] = label[5];
            label = res;
        }
    }
}