#include<stdio.h>

int main()
{
   int n,T,F,j,i;
   int a[6];
   int count=0;
   int count_2=0;
   int count_3=0;
   scanf("%d",&n);
   char d[n][4]={0};
   int s[n][6];
   for(i=0;i<n;i++){
   scanf("%d %d %d %d %d %d",&s[i][0],&s[i][1],&s[i][2],&s[i][3],&s[i][4],&s[i][5]);
   }
   for(i=1;i<n;i++){
       T=s[i][0];
       F=s[i][1];
       j=0;
       if(T==s[0][0]){
          if(F==s[0][2]){
             d[i][j]='W';
             d[i][j+1]='S';
             d[i][j+2]='E';
          }else if(F==s[0][3]){
             d[i][j]='E';
             d[i][j+1]='S';
             d[i][j+2]='W';
          }else if(F==s[0][4]){
             d[i][j]='W';
             d[i][j+1]='S';
             d[i][j+2]='S';
             d[i][j+3]='E';
          }else{
             d[i][j]=0;
          }
      }else if(T==s[0][1]){
          if(F==s[0][0]){
             d[i][j]='S';
             d[i][j+1]='W';
             d[i][j+2]='W';
          }else if(F==s[0][2]){
             d[i][j]='E';
             d[i][j+1]='N';
          }else if(F==s[0][3]){
             d[i][j]='W';
             d[i][j+1]='N';
          }else{
             d[i][j]='N';
          }
      }else if(T==s[0][2]){
          if(F==s[0][0]){
             d[i][j]='S';
             d[i][j+1]='W';
          }else if(F==s[0][4]){
             d[i][j]='S';
             d[i][j+1]='S';
             d[i][j+2]='W';
          }else if(F==s[0][5]){
             d[i][j]='N';
             d[i][j+1]='W';
          }else{
             d[i][j]='W';
          }
      }else if(T==s[0][3]){
          if(F==s[0][0]){
             d[i][j]='S';
             d[i][j+1]='E';
          }else if(F==s[0][4]){
             d[i][j]='S';
             d[i][j+1]='S';
             d[i][j+2]='E';
          }else if(F==s[0][5]){
             d[i][j]='N';
             d[i][j+1]='E';
          }else{
             d[i][j]='E';
          }
      }else if(T==s[0][4]){
          if(F==s[0][2]){
             d[i][j]='W';
             d[i][j+1]='S';
          }else if(F==s[0][3]){
             d[i][j]='E';
             d[i][j+1]='S';
          }else if(F==s[0][5]){             
             d[i][j]='W';
             d[i][j+1]='W';
             d[i][j+2]='S';
          }else{
             d[i][j]='S';
          }
      }else{
          if(F==s[0][1]){
             d[i][j]='W';
             d[i][j+1]='W';
          }else if(F==s[0][2]){
             d[i][j]='W';
             d[i][j+1]='S';
             d[i][j+2]='W';
          }else if(F==s[0][3]){
             d[i][j]='E';
             d[i][j+1]='S';
             d[i][j+2]='E';
          }else{
             d[i][j]='N';
             d[i][j+1]='N';
          }
      }
          a[0]=s[0][0];
          a[1]=s[0][1];
          a[2]=s[0][2];
          a[3]=s[0][3];
          a[4]=s[0][4];
          a[5]=s[0][5];
          for(j=0;j<4;j++){
              int b;
              if(d[i][j]=='E'){
                  b=a[0];
                  a[0]=a[3];
                  a[3]=a[5];
                  a[5]=a[2];
                  a[2]=b;
             }else if(d[i][j]=='W'){
                  b=a[0];
                  a[0]=a[2];
                  a[2]=a[5];
                  a[5]=a[3];
                  a[3]=b;
             }else if(d[i][j]=='N'){
                  b=a[0];
                  a[0]=a[1];
                  a[1]=a[5];
                  a[5]=a[4];
                  a[4]=b;
             }else if(d[i][j]=='S'){
                   b=a[0];
                   a[0]=a[4];
                   a[4]=a[5];
                   a[5]=a[1];
                   a[1]=b;
            }
          }
          for(j=0;j<6;j++){
              if(s[0][0]==s[i][j]){
              count_2+=1;
              }
              if(s[0][1]==s[i][j]){
              count_3+=1;
              }
          }
          if(s[i][0]==a[0]&&s[i][1]==a[1]&&s[i][2]==a[2]&&s[i][3]==a[3]&&s[i][4]==a[4]&&s[i][5]==a[5]){
              count+=1;
          }else if(count_2==5){
              count+=1;
          }else if(count_2==1&&count_3==5){
              count+=1;
          }
          count_2=0;
          count_3=0;
      }
      if(count==0){
         printf("Yes\n");
      }else{
         printf("No\n");
      }
 return 0;
 }



Measured memory_bytes: 2704