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

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            //var oneLine = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            //var dice = new Dice(oneLine);

            //var twoLine = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            //var dice2 = new Dice(twoLine);

            var isDuplicate = false;
            var n = int.Parse(Console.ReadLine());
            var list = new List<Dice>();
            for (int i = 0; i < n; i++)
            {
                list.Add(new Dice(Console.ReadLine().Split(' ').Select(int.Parse).ToArray()));
            }

            for (int diceNum = 0; diceNum < n; diceNum++)
            {
                for (int anotherDiceNum = diceNum + 1; anotherDiceNum < n; anotherDiceNum++)
                {
                    var dice = list[diceNum];
                    var dice2 = list[anotherDiceNum];


                    if (dice.Right == dice2.Front || dice.Left == dice2.Back)
                    {
                        dice.RotateVertical(Direction.N);
                    }
                    else if (dice.Left == dice2.Front || dice.Right == dice2.Back)
                    {
                        dice.RotateVertical(Direction.S);
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        if (dice.Top == dice2.Top)
                        {
                            break;
                        }

                        dice.RotateHorizon(Direction.W);
                    }


                    for (int i = 0; i < 2; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            if (dice.Top == dice2.Top &&
                                dice.Front == dice2.Front &&
                                dice.Bottom == dice2.Bottom &&
                                dice.Back == dice2.Back)
                            {
                                goto RotateVertical;
                            }
                            dice.RotateHorizon(Direction.N);
                        }

                        if (dice.Top == dice2.Top &&
                            dice.Front == dice2.Front &&
                            dice.Bottom == dice2.Bottom &&
                            dice.Back == dice2.Back)
                        {
                            goto RotateVertical;
                        }

                        dice.RotateVertical(Direction.N);
                        dice.RotateVertical(Direction.N);
                    }

                    RotateVertical:

                    for (int i = 0; i < 4; i++)
                    {
                        if (dice.Right == dice2.Right &&
                            dice.Back == dice2.Back &&
                            dice.Left == dice2.Left &&
                            dice.Front == dice2.Front)
                        {
                            break;
                        }
                        dice.RotateVertical(Direction.N);
                    }

                    //Console.WriteLine(dice == dice2 ? "Yes" : "No");
                    if (dice == dice2)
                    {
                        isDuplicate = true;
                        goto Finish;
                    }
                }
            }
            Finish:
            Console.WriteLine(isDuplicate ? "No" : "Yes");
        }
    }

    public class Dice
    {
        public int Top { get; private set; }
        public int Right { get; private set; }
        public int Front { get; private set; }
        public int Left { get; private set; }
        public int Bottom { get; private set; }
        public int Back { get; private set; }


        public Dice(IList<int> numbers)
        {
            //this.Number = numbers.ToArray();
            this.Top = numbers[0];
            this.Back = numbers[1];
            this.Right = numbers[2];
            this.Left = numbers[3];
            this.Front = numbers[4];
            this.Bottom = numbers[5];
        }


        public void RotateHorizon(Direction direction)
        {
            var tmp = this.Top;
            switch (direction)
            {
                case Direction.N:
                    this.Top = this.Back;
                    this.Back = this.Bottom;
                    this.Bottom = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.E:
                    this.Top = this.Left;
                    this.Left = this.Bottom;
                    this.Bottom = this.Right;
                    this.Right = tmp;
                    break;
                case Direction.W:
                    this.Top = this.Right;
                    this.Right = this.Bottom;
                    this.Bottom = this.Left;
                    this.Left = tmp;
                    break;
                case Direction.S:
                    this.Top = this.Front;
                    this.Front = this.Bottom;
                    this.Bottom = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }

        public void RotateVertical(Direction direction)
        {
            var tmp = this.Right;
            switch (direction)
            {
                case Direction.N:
                    this.Right = this.Back;
                    this.Back = this.Left;
                    this.Left = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.S:
                    this.Right = this.Front;
                    this.Front = this.Left;
                    this.Left = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }

        public static bool operator ==(Dice d, Dice d2)
        {
            return d.Top == d2.Top &&
                   d.Right == d2.Right &&
                   d.Bottom == d2.Bottom &&
                   d.Left == d2.Left &&
                   d.Front == d2.Front &&
                   d.Back == d2.Back;
        }

        public static bool operator !=(Dice d, Dice d2)
        {
            return !(d == d2);
        }
    }

    /// <summary>
    /// ダイスを転がす方向
    /// </summary>
    public enum Direction
    {
        N,
        E,
        W,
        S
    }

}