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 ITP1_11_D {
    class Dice {
        private int[] _dice;

        public Dice(int[] dice) {
            _dice = dice;
        }

        public bool IsSame(int[] arr) {
            string dir = "ENENEN";
            string turn = "RRRR";
            foreach (var d in dir) {
                foreach (var t in turn) {
                    if (_dice.SequenceEqual(arr))
                        return true;
                    Move(t);
                }
                Move(d);
            }
            return false;
        }

        public void Move(char dir) {
            switch (dir) {
                case 'E':
                    Replace(0, 3, 5, 2);
                    break;
                case 'W':
                    Replace(0, 2, 5, 3);
                    break;
                case 'N':
                    Replace(0, 1, 5, 4);
                    break;
                case 'S':
                    Replace(0, 4, 5, 1);
                    break;
                case 'R':
                    Replace(1, 3, 4, 2);
                    break;
            }
        }

        private void Replace(int a, int b, int c, int d) {
            int temp = _dice[a];
            _dice[a] = _dice[b];
            _dice[b] = _dice[c];
            _dice[c] = _dice[d];
            _dice[d] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[] source = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Dice dice = new Dice(source);
            bool isWrong = true;
            for(int i = 1; i < n; i++) {
                int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (dice.IsSame(input)) {
                    isWrong = false;
                    break;
                }
            }
            Console.WriteLine(isWrong ? "Yes" : "No");
        }
    }
}