#include <cstdio>
#include <iostream>
#include <algorithm>
    
using namespace std;
               
typedef struct dice{
  int up;
  int front;
  int right;
  int left;
  int back;
  int down;
} dice;
            
dice *rotate(dice *d,char c){
  int temp;
           
  if(c=='N'){
    temp=d->front;
    d->front=d->down;
    d->down=d->back;
    d->back=d->up;
    d->up=temp;
  } else if(c=='S') {
    temp=d->back;
    d->back=d->down;
    d->down=d->front;
    d->front=d->up;
    d->up=temp;
  } else if(c=='E') {
    temp=d->left;
    d->left=d->down;
    d->down=d->right;
    d->right=d->up;
    d->up=temp;
  } else if(c=='W') {
    temp=d->right;
    d->right=d->down;
    d->down=d->left;
    d->left=d->up;
    d->up=temp;
  }
            
  return d;
}
int dice_judge1(dice *d){
  int num=0;
   
  if(d->up==d->front)  num++;
  if(d->up==d->right)  num++;
  if(d->up==d->back)  num++;
  if(d->up==d->left)  num++;
  if(d->up==d->down)  num++;
  if(d->front==d->right)  num++;
  if(d->front==d->back)  num++;
  if(d->front==d->left)  num++;
  if(d->front==d->down)  num++;
  if(d->right==d->back)  num++;
  if(d->right==d->left)  num++;
  if(d->right==d->down)  num++;
  if(d->back==d->left)  num++;
  if(d->back==d->down)  num++;
  if(d->left==d->down)  num++;
   
  return num;
}
 
int dice_judge2(dice *d1,dice *d2){
  int i,array1[6],array2[6];
    
  array1[0]=d1->up;  array1[1]=d1->front;  array1[2]=d1->right;
  array1[3]=d1->back;  array1[4]=d1->left;  array1[5]=d1->down;
  array2[0]=d2->up;  array2[1]=d2->front;  array2[2]=d2->right;
  array2[3]=d2->back;  array2[4]=d2->left;  array2[5]=d2->down;
    
  sort(array1,array1+6);  sort(array2,array2+6);
  for(i=0;i<6;i++){
    if(array1[i]!=array2[i])  return 1;
  }
  return 0;
}
    
          
int main(void){
  dice array[100];
  dice *root;
  int i,j,num,temp1,temp2;
                
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d%d%d%d%d%d",&array[i].up,&array[i].front,&array[i].right,&array[i].left,&array[i].back,&array[i].down);
  }
       
  for(i=0;i<num-1;i++){
    for(j=i+1;j<num;j++){
      if(dice_judge2(&array[i],&array[j])==1)  continue;
 
      temp1=dice_judge1(&array[i]);  temp2=dice_judge1(&array[j]);
      if(temp1==temp2 && temp1>=10){
        printf("No\n");  return 0;
      }
 
      root=&array[j];
      if(array[i].up==array[j].up) ;
      else if(array[i].up==array[j].front)  root=rotate(root,'N');
      else if(array[i].up==array[j].right)  root=rotate(root,'W');
      else if(array[i].up==array[j].left)  root=rotate(root,'E');
      else if(array[i].up==array[j].back)  root=rotate(root,'S');
      else if(array[i].up==array[j].down){
        root=rotate(root,'N');  root=rotate(root,'N');
      }
            
      if(array[i].front==array[j].down) ;
      else if(array[i].front==array[j].front){
        if(array[i].right==array[j].right && array[i].back==array[j].back && array[i].left==array[j].left){
          printf("No\n");  return 0;
        }
      } else if (array[i].front==array[j].right) {
        if(array[i].right==array[j].back && array[i].back==array[j].left && array[i].left==array[j].front){
          printf("No\n");  return 0;
        }
      } else if(array[i].front==array[j].back) {
        if(array[i].right==array[j].left && array[i].back==array[j].front && array[i].left==array[j].right){
          printf("No\n");  return 0;
        }
      } else if(array[i].front==array[j].left) {
        if(array[i].right==array[j].front && array[i].back==array[j].right && array[i].left==array[j].back){
          printf("No\n");  return 0;
        }
      }
    }
  }
  printf("Yes\n");
         
  return 0;
}

Measured memory_bytes: 1188