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

function move(d1,d2,d3,d4,d5,d6){
   var x=this.toString();
   if(x=="N")return [d2,d6,d3,d4,d1,d5];
   if(x=="E")return [d4,d2,d1,d6,d5,d3];
}
function roll(d1,d2,d3,d4,d5,d6){
   return [d1,d3,d5,d2,d4,d6];
}
function rolls(arr){
   for(var i=0;i<4;i++){
      obj[arr.join(",")]=true;
      arr=roll.apply(null,arr);
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var OBJ={};
var result="Yes";
for(var i=0;i<n;i++){
   var obj={};
   var dice=Arr[i].split(" ").map(Number);
   for(var j=0;j<4;j++){
      rolls(dice);
      dice=move.apply("N",dice);
   }
   dice=move.apply("E",dice);
   rolls(dice);
   dice=move.apply("E",dice);
   dice=move.apply("E",dice);
   rolls(dice);
   for(var k in obj){
      if(OBJ.hasOwnProperty(k))result= "No";
      else OBJ[k]=true;
   }
   if(result=="No")break;
}
console.log(result);