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;

public class ITP1_11_D{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        
        var list_dice = new List<Dice>();
        var all_different = true;
        
        while (n-- > 0 && all_different)
        {
            var values = Console.ReadLine().Split(' ');
            Dice dice = new Dice
            {
                Top = values[0],
                South = values[1],
                East = values[2],
                West = values[3],
                North = values[4],
                Bottom = values[5]
            };
            
            foreach (Dice dice_i in list_dice)
            {
                if (dice.IsIdenticalTo(dice_i))
                {
                    all_different = false;
                    break;
                }
            }
            list_dice.Add(dice);
        }
        
        if (all_different)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
    
    class Dice
    {
        public string Top { get; set; }
        public string Bottom { get; set; }
        public string North { get; set; }
        public string South { get; set; }
        public string East { get; set; }
        public string West { get; set; }
        
        public void　RollToNorth()
        {
            string tmp = this.North;
            this.North = this.Top;
            this.Top = this.South;
            this.South = this.Bottom;
            this.Bottom = tmp;
        }
        
        public void　RollToSouth()
        {
            string tmp = this.South;
            this.South = this.Top;
            this.Top = this.North;
            this.North = this.Bottom;
            this.Bottom = tmp;
        }
        
        public void　RollToEast()
        {
            string tmp = this.East;
            this.East = this.Top;
            this.Top = this.West;
            this.West = this.Bottom;
            this.Bottom = tmp;
        }
        
        public void　RollToWest()
        {
            string tmp = this.West;
            this.West = this.Top;
            this.Top = this.East;
            this.East = this.Bottom;
            this.Bottom = tmp;
        }
        
        public void RotateToRight()
        {
            string tmp = this.North;
            this.North = this.West;
            this.West = this.South;
            this.South = this.East;
            this.East = tmp;
        }
        
        public void RotateToLeft()
        {
            string tmp = this.North;
            this.North = this.East;
            this.East = this.South;
            this.South = this.West;
            this.West = tmp;
        }
        
        public bool IsPerfectMatchWith(Dice dice)
        {
            return (this.Top == dice.Top && this.Bottom == dice.Bottom &&
                this.North == dice.North && this.East == dice.East &&
                this.South == dice.South && this.West == dice.West);
        }
        
        public bool IsIdenticalTo(Dice dice)
        {
            for (var i = 0; i < 6; i++)
            {
                if (i % 2 == 0)
                {
                    dice.RollToNorth();
                }
                else
                {
                    dice.RollToWest();
                }
                
                for (var j = 0; j < 4; j++)
                {
                    dice.RotateToRight();
                    if (this.IsPerfectMatchWith(dice))
                    {
                        return true;
                    }
                }
            }
            
            return false;
        }
    }
}