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;
class itp1_11_a{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String[] str1 = Console.ReadLine().Split(' ');
    Dice d1 = new Dice(str1[0], str1[1], str1[2], str1[3], str1[4], str1[5]);
    Dice d2;
    Rotate rtt = new Rotate();
    bool top_correct = false;
    bool allDiff = true;
    int[] count = new int[100];
    for(int i=0; i<6; i++){
      count[int.Parse(str1[i])-1]++;
    }
    int min = 6;
    int pos = 7;
    for(int i=0; i<6; i++){
      if(min > count[i] && count[i] != 0){
        min = count[i];
        pos = i+1;
      }
    }
    switch(pos){
      case 1:
        break;
      case 2:
        rtt.north(d1);
        break;
      case 3:
        rtt.west(d1);
        break;
      case 4:
        rtt.east(d1);
        break;
      case 5:
        rtt.south(d1);
        break;
      case 6:
        rtt.north(d1);
        rtt.north(d1);
        break;
      default:
        break;
    }
    for(int x=1; x<n&&allDiff; x++){
      String[] str2 = Console.ReadLine().Split(' ');
      d2 = new Dice(str2[0], str2[1], str2[2], str2[3], str2[4], str2[5]);
      for(int i=0; i<4; i++){
        if(d1.top == d2.top){
          top_correct = true;
          break;
        }
        rtt.north(d2);
      }
      if(!top_correct){
        for(int i=0; i<4; i++){
          if(d1.top == d2.top){
            top_correct = true;
            break;
          }
          rtt.east(d2);
        }
      }
      for(int i=0; i<4; i++){
        if(d1.front == d2.front){
          break;
        }
        rtt.turn_right(d2);
      }
      if(isSame(d1,d2)){
        allDiff = false;
      }
    }
    if(allDiff)
      Console.WriteLine("Yes");
    else
      Console.WriteLine("No");
  }
  public static bool isSame(Dice d1, Dice d2){
    return d1.top == d2.top && d1.front == d2.front && d1.right == d2.right
      && d1.left == d2.left && d1.behind == d2.behind && d1.bottom == d2.bottom;
  }
}


class Rotate{
  public void north(Dice d){
    int temp = d.top;
    d.top = d.front;
    d.front = d.bottom;
    d.bottom = d.behind;
    d.behind = temp;
  }
  public void south(Dice d){
    int temp = d.top;
    d.top = d.behind;
    d.behind = d.bottom;
    d.bottom = d.front;
    d.front = temp;
  }
  public void east(Dice d){
    int temp = d.top;
    d.top = d.left;
    d.left = d.bottom;
    d.bottom = d.right;
    d.right = temp;
  }
  public void west(Dice d){
    int temp = d.top;
    d.top = d.right;
    d.right = d.bottom;
    d.bottom = d.left;
    d.left = temp;
  }
  public void turn_right(Dice d){
    int temp = d.front;
    d.front = d.left;
    d.left = d.behind;
    d.behind = d.right;
    d.right = temp;
  }
  public void turn_left(Dice d){
    int temp = d.front;
    d.front = d.right;
    d.right = d.behind;
    d.behind = d.left;
    d.left = temp;
  }
}

class Dice{
  public int top { get; set; }
  public int front { get; set; }
  public int right { get; set; }
  public int left { get; set; }
  public int behind { get; set; }
  public int bottom { get; set; }
  public Dice(){
    top = 1;
    front = 2;
    right = 3;
    left = 4;
    behind = 5;
    bottom = 6;
  }
  public Dice(int t, int f, int r, int l, int be, int bo){
    top = t;
    front = f;
    bottom = bo;
    behind = be;
    right = r;
    left = l;
  }
  public Dice(String t, String f, String r, String l, String be, String bo){
    top = int.Parse(t);
    front = int.Parse(f);
    right = int.Parse(r);
    left = int.Parse(l);
    behind = int.Parse(be);
    bottom = int.Parse(bo);
  }
}