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: Wrong Answer)

function move(x,arr){
   var d1=arr[0];
   var d2=arr[1];
   var d3=arr[2];
   var d4=arr[3];
   var d5=arr[4];
   var d6=arr[5];
   var after=[];
   if(x=="N")after=[d2,d6,d3,d4,d1,d5];
   if(x=="S")after=[d5,d1,d3,d4,d6,d2];
   if(x=="E")after=[d4,d2,d1,d6,d5,d3];
   if(x=="W")after=[d3,d2,d6,d1,d5,d4];
   return after;
}

function roll(arr){
   var d1=arr[0];
   var d2=arr[1];
   var d3=arr[2];
   var d4=arr[3];
   var d5=arr[4];
   var d6=arr[5];
   var after=[];
   after=[d1,d3,d5,d2,d4,d6];
   return after;
}

function rolls(arr){
   var obj={};
   for(var i=0;i<4;i++){
      var str=arr.join(",");
      if(!obj.hasOwnProperty(str))obj[str]=true;
      arr=roll(arr);
   }
   for(var k in obj){
      if(OBJ.hasOwnProperty(k))result= "No";
      else OBJ[k]=true;
   }
}

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 dice=Arr[i].split(" ").map(Number);
   for(var j=0;j<4;j++){
      rolls(dice);
      dice=move("N",dice);
   }
   dice=move("E",dice);
   rolls(dice);
   dice=move("S",dice);
   dice=move("S",dice);
   rolls(dice);
   if(result=="No")break;
}
console.log(result);