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 Dice
{
    public int[] Number { get; set; }

    private int[] tmp = new int[6];

    public void SetNumber(int[] a)
    {
        for (int i = 0; i < 6; i++)
        {
            Number[i] = a[i];
        }
    }

    public void Rotate(char c)
    {

        switch (c)
        {
            case 'N':
                tmp[0] = Number[1];
                tmp[1] = Number[5];
                tmp[2] = Number[2];
                tmp[3] = Number[3];
                tmp[4] = Number[0];
                tmp[5] = Number[4];
                SetNumber(tmp);
                break;
            case 'E':
                tmp[0] = Number[3];
                tmp[1] = Number[1];
                tmp[2] = Number[0];
                tmp[3] = Number[5];
                tmp[4] = Number[4];
                tmp[5] = Number[2];
                SetNumber(tmp);
                break;
            case 'W':
                tmp[0] = Number[2];
                tmp[1] = Number[1];
                tmp[2] = Number[5];
                tmp[3] = Number[0];
                tmp[4] = Number[4];
                tmp[5] = Number[3];
                SetNumber(tmp);
                break;
            case 'S':
                tmp[0] = Number[4];
                tmp[1] = Number[0];
                tmp[2] = Number[2];
                tmp[3] = Number[3];
                tmp[4] = Number[5];
                tmp[5] = Number[1];
                SetNumber(tmp);
                break;
            default:
                break;
        }
    }

    public void Spin()
    {
        tmp[0] = Number[0];
        tmp[1] = Number[2];
        tmp[2] = Number[4];
        tmp[3] = Number[1];
        tmp[4] = Number[3];
        tmp[5] = Number[5];
        SetNumber(tmp);
    }

    public void SetTop(int a)
    {
        if (a == Number[0])
        {

        }
        else if (a == Number[1])
        {
            Rotate('N');
        }
        else if (a == Number[2])
        {
            Rotate('W');
        }
        else if (a == Number[3])
        {
            Rotate('E');
        }
        else if (a == Number[4])
        {
            Rotate('S');
        }
        else if (a == Number[5])
        {
            Rotate('N');
            Rotate('N');
        }
    }

    public void SetFront(int a)
    {
        if (a == Number[0])
        {
            Rotate('S');
        }
        else if (a == Number[1])
        {
        }
        else if (a == Number[2])
        {
            Spin();
        }
        else if (a == Number[3])
        {
            Spin();
            Spin();
            Spin();
        }
        else if (a == Number[4])
        {
            Spin();
            Spin();
        }
        else if (a == Number[5])
        {
            Rotate('N');
        }
    }

    public static bool Equals(Dice x, Dice y)
    {
        y.SetTop(x.Number[0]);
        y.SetFront(x.Number[1]);
        for (int i = 0; i < 6; i++)
        {
            if (x.Number[i] != y.Number[i])
            {
                return false;
            }
        }
        return true;
    }
}

class MyClass
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var dices = new Dice[n];
        for (int i = 0; i < n; i++)
        {
            var dice = new Dice()
            { Number = Console.ReadLine().Split().Select(int.Parse).ToArray() };
            dices[i] = dice;
        }
        var b = true;
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                if (Dice.Equals(dices[i],dices[j]))
                {
                    b = false;
                }
            }
        }
        Console.WriteLine(b ? "Yes" : "No");
    }
}