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

namespace _1_11_D_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Dice dice1 = new Dice();
            int n = int.Parse(Console.ReadLine());
            string[,] dice = new string[n, 6];
            List<string> answerList = new List<string>();
            for (int i = 0; i < n; i++)
            {
                string[] diceLine = Console.ReadLine().Split();
                for (int j = 0; j < 6; j++)
                {
                    dice[i, j] = diceLine[j];
                }
            }
            for (int i = 0; i < n - 1; i++)
            {
                for (int g = i + 1; g < n; g++)
                {
                    dice1.IsAllCompare(dice, i, g, answerList);

                }
            }
            if (answerList.Contains("No") == true)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
    class Dice
    {
        //i番目のdiceとn番目のdiceの一致判定。一致したときanswerはNo
        internal void IsAllCompare(string[,] dice, int i, int n, List<string> answerList)
        {
            string[] order = { "S", "S", "S", "N", "S", "S", "S", "N", "S", "S", "S", "E","S","S","S"
            ,"E","S","S","S","N","S","S","S"};

            for(int j = 0; j < order.Length; j++)
            {
                Order(order, dice, j, n);
                answerList.Add(IsSame(dice, i, n));
            }
        }
        internal string IsSame(string[,] dice, int i, int n)
        {

            if (dice[i, 0] == dice[n, 0] && dice[i, 1] == dice[n, 1] && dice[i, 2] == dice[n, 2]
                && dice[i, 3] == dice[n, 3] && dice[i, 4] == dice[n, 4] && dice[i, 5] == dice[n, 5])
            {
                return "No";
            }
            else
            {
                return "Yes";
            }
        }
        //g番目の文字でi番目のdiceの転がす方向を決める
        internal void Order(string[] order, string[,] dice, int g, int i)
        {
            if (order[g] == "S") Roll_South(dice, i);
            if (order[g] == "N") Roll_Noth(dice, i);
            if (order[g] == "E") Roll_East(dice, i);
        }
        //サイコロを東西南北に転がす
        internal void Roll_South(string[,] dice, int i)
        {
            string str = dice[i, 0];
            dice[i, 0] = dice[i, 2];
            dice[i, 2] = dice[i, 5];
            dice[i, 5] = dice[i, 3];
            dice[i, 3] = str;
        }
        internal void Roll_Noth(string[,] dice, int i)
        {
            string str = dice[i, 0];
            dice[i, 0] = dice[i, 1];
            dice[i, 1] = dice[i, 5];
            dice[i, 5] = dice[i, 4];
            dice[i, 4] = str;
        }
        internal void Roll_East(string[,] dice, int i)
        {
            string str = dice[i, 0];
            dice[i, 0] = dice[i, 4];
            dice[i, 4] = dice[i, 5];
            dice[i, 5] = dice[i, 1];
            dice[i, 1] = str;
        }
    }
}