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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Dice : IEquatable<Dice>
    {
        protected string[] val = new string[6];

        public Dice(string[] str)
        {
            Array.Copy(val, str, 6);
        }

        public bool Equals(Dice dice2)
        {
            if ((val[0] == dice2.val[2] && val[5] == dice2.val[3]) || (val[0] == val[3] && val[5] == dice2.val[2]))
            {
                string tmp = dice2.val[1];
                dice2.val[1] = dice2.val[2];
                dice2.val[2] = dice2.val[4];
                dice2.val[4] = dice2.val[3];
                dice2.val[3] = tmp;
            }

            for (int i = 0; i < 3; i++)
            {
                if (val[0] == dice2.val[0] && val[5] == dice2.val[5])
                    break;
                string tmp = dice2.val[0];
                dice2.val[0] = dice2.val[1];
                dice2.val[1] = dice2.val[5];
                dice2.val[5] = dice2.val[4];
                dice2.val[4] = tmp;
            }

            for (int i = 0; i < 3; i++)
            {
                if (val[1] == dice2.val[1] && val[4] == dice2.val[4])
                    break;
                string tmp = dice2.val[1];
                dice2.val[1] = dice2.val[2];
                dice2.val[2] = dice2.val[4];
                dice2.val[4] = dice2.val[3];
                dice2.val[3] = tmp;
            }

            if (val[0] == dice2.val[0] && val[1] == dice2.val[1] && val[2] == dice2.val[2] && val[3] == dice2.val[3] && val[4] == dice2.val[4] && val[5] == dice2.val[5])
                return true;
            else return false;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            Dice[] dices = new Dice[num];

            for(int i=0;i<num;i++)
            {
                dices[i] = new Dice(Console.ReadLine().Split(' '));
            }

            bool res = true;
            for(int i=0;i<num;i++)
            {
                for(int j=i+1;j<num;j++)
                {
                    if (dices[i].Equals(dices[j])) { res = false;  break; }
                }
            }

            Console.WriteLine(res?"Yes":"No");
        }
    }
}