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: Wrong Answer)

using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var labels = new int[num][];
            for (int i = 0; i < labels.Length; i++)
            {
                labels[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            }

            const string Yes = "Yes";
            const string No = "No";
            for (int y = 0; y < labels.Length-1; y++)
            {
                var diceY = new Dice(labels[y]);
                for (int x = y+1; x < labels.Length - 1; x++)
                {
                    var diceX = new Dice(labels[x]);
                    if (DiceEquals(diceY, diceX))
                    {
                        Console.WriteLine(No);
                        return;
                    }
                }
            }
            Console.WriteLine(Yes);
            
        }

        private static bool DiceEquals(Dice diceA, Dice diceB)
        {
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    for (int z = 0; z < 4; z++)
                    {
                        if (Dice.ValueEquals(diceA, diceB))
                        {
                            return true;
                        }
                        diceB.RollZ(true);
                    }
                    diceB.RollY(true);
                }
                diceB.RollX(true);
            }
            return false;
        }
        
    }

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

        public Dice(int[] label)
        {
            Front = label[0];
            Bottom = label[1];
            Right = label[2];
            Left = label[3];
            Top = label[4];
            Rear = label[5];
        }

        public void RollX(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Left;
                Left = Rear;
                Rear = Right;
                Right = temp;
            }
            else
            {
                temp = Front;
                Front = Right;
                Right = Rear;
                Rear = Left;
                Left = temp;
            }
        }
        public void RollY(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Bottom;
                Bottom = Rear;
                Rear = Top;
                Top = temp;
            }
            else
            {
                temp = Front;
                Front = Top;
                Top = Rear;
                Rear = Bottom;
                Bottom = temp;
            }
        }
        public void RollZ(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Top;
                Top = Left;
                Left = Bottom;
                Bottom = Right;
                Right = temp;
            }
            else
            {
                temp = Top;
                Top = Right;
                Right = Bottom;
                Bottom = Left;
                Left = temp;
            }
        }
        static public bool ValueEquals(Dice a, Dice b)
        {
            if (a.Front != b.Front) return false;
            else if (a.Bottom != b.Bottom) return false;
            else if (a.Right != b.Right) return false;
            else if (a.Left != b.Left) return false;
            else if (a.Top != b.Top) return false;
            else if (a.Rear != b.Rear) return false;
            else return true;
        }
    }
}