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

<?php
  $count   = trim(fgets(STDIN));
  $dice_1  = explode(" ", trim(fgets(STDIN)));
  $a_dice  = array();
  $upper_1 = $dice_1[0];
  $side_1  = array($dice_1[2], $dice_1[1], $dice_1[3], $dice_1[4]);
  $bottom_1  = $dice_1[5];
  for($x=0;$x<($count-1);$x++) {
    $dice_2 = explode(" ", trim(fgets(STDIN)));
    array_push($a_dice, $dice_2);
  }
  for($x=0;$x<($count-1);$x++){
    $side_2  = array($a_dice[$x][2], $a_dice[$x][1], $a_dice[$x][3], $a_dice[$x][4]);
    $upper_2 = $a_dice[$x][0];
    $bottom_2  = $a_dice[$x][5];
    $n = 0;
    while (true) {
      for($i=0;$i<4;$i++) {
        if (($upper_1 == $upper_2) && ($bottom_1 == $bottom_2) && ($side_1[0] == $side_2[0]) && ($side_1[1] == $side_2[1]) && ($side_1[2] == $side_2[2]) && ($side_1[3] == $side_2[3])) {
          print "No\n";
          return;
        } else {
          $z = array_shift($side_2);
          array_push($side_2, $z);
        }
      }
      if ($n < 4) {
        $b = $bottom_2;
        $u = $upper_2;
        $upper_2 = $side_2[2];
        $bottom_2 = $side_2[0];
        $side_2[2] = $b;
        $side_2[0] = $u;
      } else if ($n < 10 && $n > 3) {
        $b = $bottom_2;
        $u = $upper_2;
        $upper_2 = $side_2[1];
        $bottom_2 = $side_2[3];
        $side_2[1] = $b;
        $side_2[3] = $u;
      } else if ($n > 10) {
        break 1;
      }
      $n++;
    }
  }
  print "Yes";
?>