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 ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            //入力読取。
            string strDate = Console.ReadLine();
            int intDate = int.Parse(strDate);
            List<string> diceList = new List<string>();
            for(int date = 0; date < intDate; date++){
                string strDice = Console.ReadLine();
                diceList.Add(strDice);
            }
            
            //サイコロのクラスにて処理。
            string strAnsewr = "";
            for(int first = 0; first < intDate - 1; first++){
                for(int second = first + 1; second < intDate; second++){
                    Dice insD = new Dice(diceList[first], diceList[second]);
                    strAnsewr = insD.GetAnswer();
                    if(strAnsewr == "No"){
                        break;
                    }
                }
                if(strAnsewr == "No"){
                    break;
                }
            }
            
            //出力
            Console.WriteLine(strAnsewr);
            
        }
        
    }
    
    class Dice{
        
        private string strDice;
        private string strDice2;
        private int[] dice;
        private int[] dice2;
        private string strAnsewr;
        
        public Dice(string strDice, string strDice2){
            this.strDice = strDice;
            this.strDice2 = strDice2;
            SetDice();
        }
        
        private void SetDice(){
        
            //サイコロ生成。
            this.dice = MakeDice(strDice);
            this.dice2 = MakeDice(strDice2);
            
            //サイコロを転がす。
            string strOrder = "NNNNWNNNWNNNENNNENNNWNNN";
            char[] chOrder = strOrder.ToCharArray();
            this.strAnsewr = "Yes";
            for(int order = 0; order < chOrder.Length; order++){
                Roll(chOrder[order]);
                bool blEquals = dice.SequenceEqual(dice2);
                if(blEquals){
                    this.strAnsewr = "No";
                    break;
                }
            }
            
        }
        
        private int[] MakeDice(string strDiceTemp){
            
            string[] strDiceArray = strDiceTemp.Split(' ');
            int[] diceTemp = new int[6];
            for(int index = 0; index < 6; index++){
                diceTemp[index] = int.Parse(strDiceArray[index]);
            }
            return diceTemp;
            
        }
        
        private void Roll(char chDirection){
            if(chDirection == 'N'){
                int intTemp = dice[0];
                dice[0] = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[4];
                dice[4] = intTemp;
            }else if(chDirection == 'W'){
                int intTemp = dice[0];
                dice[0] = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[3];
                dice[3] = intTemp;
            }else if(chDirection == 'E'){
                int intTemp = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[5];
                dice[5] = dice[2];
                dice[2] = intTemp;
            }else{
                int intTemp = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[5];
                dice[5] = dice[1];
                dice[1] = intTemp;
            }
        }
        
        public string GetAnswer(){
            return strAnsewr;
        }
        
    }

}