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;

namespace Saikoro
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var list = new List<Saikoro>(n);

            for(int i = 0; i < n; i++)
            {
                list.Add(new Saikoro(Console.ReadLine().Split(' ').Select(int.Parse).ToArray()));
            }
            for(int i = 0; i < n - 1; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    if (list[i].Equal(list[j]))
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
            Console.WriteLine("Yes");
        }
    }
    class Saikoro
    {
        public int[] men { get; set; }

        public Saikoro(int[] men)
        {
            this.men = men;
        }
        public void  showTop()
        {
            Console.WriteLine(men[0]);
        }
        public bool Equal(Saikoro s)
        {
            //int frontId = SearchId(s.men[0]);
            //int topId;
            //if (s.men[0] == s.men[1])
            //{
            //    topId = SearchId(s.men[1], frontId);
            //}
            //else
            //{
            //    topId = SearchId(s.men[1]);
            //}
            
            //if (frontId == -1||topId==-1)
            //{
            //    return false;
            //}
            //int rightId = ShowRightSide(men[frontId], men[topId]);
            //if (rightId!=-1&&men[rightId] == s.men[3]&&men[5 - frontId] == s.men[5] && men[5 - topId] == s.men[4] && men[5-rightId] == s.men[2])
            //{
            //    return true;
            //}
            //return false;
            for(int frontId = 0; frontId < 6; frontId++)
            {
                if (!(men[frontId] == s.men[0] && men[5 - frontId] == s.men[5]))
                {
                    continue;
                }
                for(int topId = 0; topId < 6; topId++)
                {
                    int rightId = ReturnRightSide(frontId, topId);
                    if (rightId == -1)
                    {
                        continue;
                    }
                    if (men[topId]==s.men[1]&&men[5-topId]==s.men[4]&&men[rightId] == s.men[3] && men[5-rightId] == s.men[2])
                    {
                        return true;
                    }
                    
                }
                
            }
            return false;
        }

        public int ShowRightSide(int front,int top)
        {
            int frontId = SearchId(front);
            int topId = SearchId(top);
            return ReturnRightSide(frontId, topId);
            
        }
        private int ReturnRightSide(int frontId,int topId)
        {
            int[,] answer =
                        {
                {-1,3,1,4,2,-1 },
                { 2,-1,5,0,-1,3},
                {4,0,-1,-1,5,1 },
                {1,5,-1,-1,0,4 },
                { 3,-1,0,5,-1,2},
                { -1,2,4,1,3,-1},
            };
            return answer[frontId, topId];
        }
        private int SearchId(int num)
        {
            return SearchId(num, 0);
        }
        private int SearchId(int num,int startId)
        {
            for (int i = startId; i < men.Length; i++)
            {
                if (num == men[i])
                {
                    return i;
                }
            }
            return -1;
        }

        public void Move(char c)
        {
            switch (c)
            {
                case 'N':
                    N();
                    break;
                case 'S':
                    S();
                    break;
                case 'E':
                    E();
                    break;
                case 'W':
                    W();
                    break;
                default:
                    break;
            }
        }
        private void N()
        {
            var temp = (int[])men.Clone();
            men[0] = temp[1];
            men[1] = temp[5];
            men[5] = temp[4];
            men[4] = temp[0];
        }
        private void W()
        {
            var temp =(int[]) men.Clone();
            men[0] = temp[2];
            men[2] = temp[5];
            men[5] = temp[3];
            men[3] = temp[0];
        }
        private void E()
        {
            var temp = (int[])men.Clone();
            men[2] = temp[0];
            men[5] = temp[2];
            men[3] = temp[5];
            men[0] = temp[3];
        }
        private void S()
        {
            var temp = (int[])men.Clone();
            men[0] = temp[4];
            men[4] = temp[5];
            men[5] = temp[1];
            men[1] = temp[0];

        }
    }
}