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;

class Problem {
    public class Dice {
        public int Top    { get; private set; }
        public int South  { get; private set; }
        public int East   { get; private set; }
        public int West   { get; private set; }
        public int North  { get; private set; }
        public int Bottom { get; private set; }
        
        private int[] init;
        
        public void Init() {
            Top    = init[0];
            South  = init[1];
            East   = init[2];
            West   = init[3];
            North  = init[4];
            Bottom = init[5];
        }
        public Dice(int[] nums) {
            init = nums;
            Init();
        }
        public void Roll(string coms) {
            foreach (var com in coms) {
                var tmp = Top;
                switch (com) {
                    case 'E': Top = West;  West  = Bottom; Bottom = East;  East  = tmp; break;
                    case 'N': Top = South; South = Bottom; Bottom = North; North = tmp; break;
                    case 'S': Top = North; North = Bottom; Bottom = South; South = tmp; break;
                    case 'W': Top = East;  East  = Bottom; Bottom = West;  West  = tmp; break;
                }
            }
        }
        public void RollY(string coms) {
            foreach (var com in coms) {
                var tmp = South;
                switch (com) {
                    case 'R': South = West; West = North; North = East; East = tmp; break;
                    case 'L': South = East; East = North; North = West; West = tmp; break;
                }
            }
        }
        public char Position(int num) {
            return num == Top   ? 'T' :
                   num == South ? 'S' :
                   num == East  ? 'E' :
                   num == West  ? 'W' :
                   num == North ? 'N' : 'B';
        }
        public bool Equal(Dice d) {
            return Top    == d.Top   &&
                   South  == d.South &&
                   East   == d.East  &&
                   West   == d.West  &&
                   North  == d.North &&
                   Bottom == d.Bottom;
        }
    }
    
    public static bool Check(Dice d1, Dice d2) {
        var checkComs = new[] {"", "N", "W", "E", "S", "NN"};
        foreach (var com in checkComs) {
            d1.Roll(com);
            if (d1.Equal(d2)) return true;
            d1.RollY("R");
            if (d1.Equal(d2)) return true;
            d1.RollY("R");
            if (d1.Equal(d2)) return true;
            d1.RollY("R");
            if (d1.Equal(d2)) return true;
            d1.Init();
        }
        return false;
    }
    
    public static void Main() {
        var n = int.Parse(Console.ReadLine());
        var res = "Yes";
        var d = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
        for (var i = 1; i < n; i++) {
            var cd = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
            if (res == "Yes") res = Check(d, cd) ? "No" : res;
            else continue;
        }
        Console.WriteLine(res);
    }
}