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;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            Dice sai = new Dice();
            bool flag = true;
            int num = int.Parse(Console.ReadLine());
            const int MAX_N = 100;
            int[][] die = new int[MAX_N][];
            int[][] auth = new int[MAX_N][];
            for (int i = 0; i < num; ++i)
            {
                die[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                auth[i] = die[i];
            }
            for (int i = 1; i < num; ++i)
            {
                for (int j = 1; j <= i; ++j)
                {
                    if (i < j)
                    {
                        break;
                    }
                    if (!sai.AreSame(die[i], auth[i - j]))
                    {
                        flag = false;
                        break;
                    }
                }
                if (!flag)
                {
                    break;
                }
            }
            Console.WriteLine(flag ? "Yes" : "No");
        }
    }

    internal class Dice
    {
        const int TIMES = 500;
        internal bool AreSame(int[] pips, int[] auth)
        {
            Random rnd = new Random();
            for (int i = 0; i < TIMES; ++i)
            {
                if (rnd.Next(2) == 1)
                {
                    GoNorth(pips);
                }
                else
                {
                    GoEast(pips);
                }
                if (auth[0] == pips[0] && auth[1] == pips[1] && auth[2] == pips[2] && auth[3] == pips[3] && auth[4] == pips[4] && auth[5] == pips[5])
                    return false;
            }
            return true;
        }
        private void GoNorth(int[] pips)
        {
            int tmp = pips[0];
            pips[0] = pips[1];
            pips[1] = pips[5];
            pips[5] = pips[4];
            pips[4] = tmp;

        }
        private void GoEast(int[] pips)
        {
            int tmp = pips[3];
            pips[3] = pips[5];
            pips[5] = pips[2];
            pips[2] = pips[0];
            pips[0] = tmp;
        }
    }
}