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;
using System.Collections.Generic;
 
class Program
{
    public class Dice
    {
        public int[] Face {get; set;}
        public Dice Nua(char dir)
        {
            int[] _f = Face.Clone() as int[];
            var f = Face;
            Face = _f;
            switch (dir)
            {
                case 'N':
                {
                    Face[0] = f[1];
                    Face[1] = f[5];
                    Face[5] = f[4];
                    Face[4] = f[0];
                }
                break;
                case 'E':
                {
                    Face[2] = f[0];
                    Face[0] = f[3];
                    Face[3] = f[5];
                    Face[5] = f[2];
                }
                break;
                case 'W':
                {
                    Face[3] = f[0];
                    Face[0] = f[2];
                    Face[2] = f[5];
                    Face[5] = f[3];
                }
                break;
                case 'S':
                {
                    Face[1] = f[0];
                    Face[5] = f[1];
                    Face[4] = f[5];
                    Face[0] = f[4];
                }
                break;
            }
            _f = Face;
            Face = f;
            return new Dice { Face = _f};
        }
        public override bool Equals(Object obj) 
        {
            var o = obj as Dice;
            if (o == null)
                return false;
            return Enumerable.SequenceEqual(Face, o.Face);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
    static void Main(string[] args)
    {
        List<Dice> diceList = new List<Dice>();
        var k = 1;
        int kc;
        var c = kc = int.Parse(Console.ReadLine());
        var aadc = 625;
        for (; c > 0; c--)
        for (int i = 0; i < k; i++)
        {
            var aif = new Dice { Face = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray()};
            //5^4 = 625
            foreach (var f0 in "_NSWE")
            {
                foreach (var f1 in "_NSWE")
                {
                    foreach (var f2 in "_NSWE")
                    {
                        foreach (var f3 in "_NSWE")
                        {
                            var rolled = aif.Nua(f0).Nua(f1).Nua(f2).Nua(f3);
                            diceList.Add(rolled);
                        }
                    }
                }
            }
        }
        var bf = false;
        for (int i = 0; i < kc; i++)
        {
            var j = aadc * i;
            for (int f = 0; f < kc; f++)
            {
                if (f == i)
                {
                    continue;
                }
                for (int l = aadc * f; l < aadc * f + aadc - 1; l++)
                {
                    if (bf)
                        break;
                    if (diceList[j].Equals(diceList[l]))
                    {
                        bf = true;
                    }
                }
            }
        }
        Console.WriteLine(bf ? "No" : "Yes");
    }
}