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;

namespace ITP1_11_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);
            Dice[] dice = new Dice[n];

            for(int i = 0; i < n; ++i)
            {
                string[] str1 = Console.ReadLine().Split(' ');
                dice[i] = new Dice(int.Parse(str1[0]), int.Parse(str1[1]), int.Parse(str1[2]), int.Parse(str1[3]), int.Parse(str1[4]), int.Parse(str1[5]));
            }

            string Ans = "Yes";
            for(int i = 1; i<n;++i)
            {
                if (allCheckSame(dice[0], dice[i])) { Ans = "No"; }
            }

            Console.WriteLine(Ans); 
        }

        static bool checkSame(Dice dice1, Dice dice2)
        {
            return (true
                && dice1.TopPip == dice2.TopPip
                && dice1.NorthPip == dice2.NorthPip
                && dice1.SouthPip == dice2.SouthPip
                && dice1.WestPip == dice2.WestPip
                && dice1.EastPip == dice2.EastPip
                && dice1.BottomPip == dice2.BottomPip
                );
        }

        static bool revolveCheckSame(Dice dice1, Dice dice2)
        {
            for (int i = 0; i < 4; ++i)
            {
                if (checkSame(dice1, dice2)) { return true; }
                dice2.RevolveLeft();
            }
            return false;
        }

        static bool allCheckSame(Dice dice1, Dice dice2)
        {
            if (revolveCheckSame(dice1, dice2)) { return true; }

            dice2.MoveEast();
            if (revolveCheckSame(dice1, dice2)) { return true; }
            dice2.MoveWest();

            dice2.MoveNorth();
            if (revolveCheckSame(dice1, dice2)) { return true; }
            dice2.MoveSouth();

            dice2.MoveSouth();
            if (revolveCheckSame(dice1, dice2)) { return true; }
            dice2.MoveNorth();

            dice2.MoveWest();
            if (revolveCheckSame(dice1, dice2)) { return true; }

            dice2.MoveWest();
            if (revolveCheckSame(dice1, dice2)) { return true; }

            return false;
        }
    }

    class Dice
    {
        public int TopPip { get; private set; }
        public int SouthPip { get; private set; }
        public int EastPip { get; private set; }
        public int WestPip { get; private set; }
        public int NorthPip { get; private set; }
        public int BottomPip { get; private set; }

        public Dice(int topPip, int southPip, int eastPip, int westPip, int northPip, int bottomPip)
        {
            this.TopPip = topPip;
            this.SouthPip = southPip;
            this.EastPip = eastPip;
            this.WestPip = westPip;
            this.NorthPip = northPip;
            this.BottomPip = bottomPip;
        }

        public Dice(Dice dice)
        {
            this.TopPip = dice.TopPip;
            this.SouthPip = dice.SouthPip;
            this.EastPip = dice.EastPip;
            this.WestPip = dice.WestPip;
            this.NorthPip = dice.NorthPip;
            this.BottomPip = dice.BottomPip;
        }

        public void MoveNorth()
        {
            int temp = this.NorthPip;
            this.NorthPip = this.TopPip;
            this.TopPip = this.SouthPip;
            this.SouthPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void MoveSouth()
        {
            int temp = this.SouthPip;
            this.SouthPip = this.TopPip;
            this.TopPip = this.NorthPip;
            this.NorthPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void MoveWest()
        {
            int temp = this.WestPip;
            this.WestPip = this.TopPip;
            this.TopPip = this.EastPip;
            this.EastPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void MoveEast()
        {
            int temp = this.EastPip;
            this.EastPip = this.TopPip;
            this.TopPip = this.WestPip;
            this.WestPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void RevolveLeft()
        {
            int temp = this.SouthPip;
            this.SouthPip = this.EastPip;
            this.EastPip = this.NorthPip;
            this.NorthPip = this.WestPip;
            this.WestPip = temp;
        }
    }
}