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;

namespace AizuOnlineJudge {
    class Program {
        static void Main() {
            var max = int.Parse(Console.ReadLine());
            var unique = true;
            var dice = new int[max][];

            for (var i = 0; i < max; ++i) {
                var line = Console.ReadLine();
                if (!unique) {
                    continue;
                }
                var die = line.Split().Select(int.Parse).ToArray();
                unique = dice.TakeWhile(q => q != null).All(d => !"RRRNRRRNRRRSRRRSRRRNRRR".SkipWhile(q => !die.Roll(q).SequenceEqual(d)).Any());
                dice[i] = die;
            }

            Console.WriteLine(unique ? "Yes" : "No");
        }
    }
    static class Ex {
        public static int[] Roll(this int[] dice, char c) {
            switch (c) {
                case 'N':
                    Move(dice, 0, 1, 5, 4);
                    break;

                case 'S':
                    Move(dice, 0, 4, 5, 1);
                    break;

                case 'E':
                    Move(dice, 0, 3, 5, 2);
                    break;

                case 'W':
                    Move(dice, 0, 2, 5, 3);
                    break;
                
                case 'R':
                    Move(dice, 1, 2, 4, 3);
                    break;

                case 'L':
                    Move(dice, 1, 3, 4, 2);
                    break;
            }

            return dice;
        }

        static void Move(int[] dice, int a, int b, int c, int d) {
            var tmp = dice[a];
            dice[a] = dice[b];
            dice[b] = dice[c];
            dice[c] = dice[d];
            dice[d] = tmp;
        }
    }
}