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++11 (judge verdict: Accepted)

#include <bits/stdc++.h>

class Dice {
public:
  int u;
  int r;
  int l;
  int d;
  int b;
  int f;
  void S(void) {
    int temp;
    temp = u; u = b; b = d; d = f; f = temp;
  }
  void N(void) {
    int temp;
    temp = u; u = f; f = d; d = b; b = temp;
  }
  void E(void) {
    int temp;
    temp = u; u = l; l = d; d = r; r = temp;
  }
  void W(void) {
    int temp;
    temp = u; u = r; r = d; d = l; l = temp;
  }
  void T(void) {
    int temp;
    temp = f; f = r; r = b; b = l; l = temp;
  }
};

bool operator == (const Dice d1, const Dice d2) {
  return
    d1.u == d2.u &&
    d1.f == d2.f &&
    d1.r == d2.r &&
    d1.l == d2.l &&
    d1.b == d2.b &&
    d1.d == d2.d;
}

int main() {

  Dice dice[128];
  int N;
  bool b;

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> dice[i].u;
    std::cin >> dice[i].f;
    std::cin >> dice[i].r;
    std::cin >> dice[i].l;
    std::cin >> dice[i].b;
    std::cin >> dice[i].d;
  }

  srand(time(NULL));

  b = true;
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      for(int k = 0; k < 10000; ++k) {
	if( dice[i] == dice[j] ) {
	  b = false;
	  goto label_1;
	}
	switch( rand() % 4 ) {
	case 0:
	  dice[i].E();
	  break;
	case 1:
	  dice[i].N();
	  break;
	case 2:
	  dice[i].W();
	  break;
	case 3:
	  dice[i].S();
	  break;
	}
      }
    }
  }  

 label_1:
  
  if( b ) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
    
  
  return 0;
}