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: Time Limit Exceeded)

#include <stdio.h>
int main(void){
  int i,j,k;
  int l,m;
  int n;
  
  scanf("%d",&n);
  int dice[n][7];
  
  for(l=0;l<n;l++){
      for(m=1;m<=6;m++){
          scanf("%d",&dice[l][m]);
      }
  }
  
  for(l=0;l<n-1;l++){
      for(m=l+1;m<n;n++){
            for(i=1;i<=6;i++){
                 if(dice[l][1]==dice[m][1]) {
                   for(j=1;j<=4;j++){
                     for(k=1;k<=7;k++){
                        if(k==7){
                            printf("No\n");
                            return 0;
                        }
                     if(dice[l][k]!=dice[m][k]) break;
                     }
              
                     dice[m][0]=dice[m][2];
                     dice[m][2]=dice[m][3];
                     dice[m][3]=dice[m][5];
                     dice[m][5]=dice[m][4];
                     dice[m][4]=dice[m][0];
                   }
                 }
      
               dice[m][0]=dice[m][1];
               switch(i){
          
               case 3:
               dice[m][1]=dice[m][3];
               dice[m][3]=dice[m][6];
               dice[m][6]=dice[m][4];
               dice[m][4]=dice[m][0];
               break;
          
               default:
               dice[m][1]=dice[m][2];
               dice[m][2]=dice[m][6];
               dice[m][6]=dice[m][5];
               dice[m][5]=dice[m][0];
               break;
               }
            }
      }
  }
 
  printf("Yes\n");
  
  return 0;
}