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>
#include<string.h>

int x[1000][1000];

int main(void){
int z=0,y=0;
int a=0,b=0;
int c=0;
int j=0,i=0;
scanf("%d",&z);
for(a=0;a<z;a++){
        for(b=0;b<6;b++){
            scanf("%d",&x[a][b]);
        }
    }
    for(a=1;a<z;a++){
        while(1){
            if(x[0][0]==x[z-a][0])break;
            c=x[z-a][0];
            x[z-a][0]=x[z-a][1];
            x[z-a][1]=x[z-a][5];
            x[z-a][5]=x[z-a][4];
            x[z-a][4]=c;
        }
        j=0;
        while(1){
            if(x[0][1]==x[z-a][1]&&x[0][2]==x[z-a][2])break;
            c=x[z-a][1];
            x[z-a][1]=x[z-a][2];
            x[z-a][2]=x[z-a][4];
            x[z-a][4]=x[z-a][3];
            x[z-a][3]=c;
            j++;
            if(j==7)break;
        }
    }
    for(a=0;a<z;a++){
            if(x[0][1]==x[z-a][1]&&
               x[0][2]==x[z-a][2]&&
               x[0][3]==x[z-a][3]&&
               x[0][4]==x[z-a][4]&&
               x[0][5]==x[z-a][5]&&
               x[0][0]==x[z-a][0]){
                i++;
               }

               }

    if(i==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}