#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,D[100][7],c=0;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=1;j<=6;j++){
        cin>>D[i][j];
    }
  }
  for(int i=0;i<n-1;i++){
  if(D[i][1]==D[i+1][1]&&D[i][2]==D[i+1][2]&&D[i][3]==D[i+1][3]&&D[i][4]==D[i+1][4]&&D[i][5]==D[i+1][5]&&D[i][6]==D[i+1][6]){
    c++;
  }else if(D[i][1]==D[i+1][1]&&D[i][2]==D[i+1][3]&&D[i][3]==D[i+1][5]&&D[i][5]==D[i+1][4]&&D[i][4]==D[i+1][2]&&D[i][6]==D[i+1][6]){
    c++;
  }else if(D[i][1]==D[i+1][1]&&D[i][2]==D[i+1][5]&&D[i][5]==D[i+1][2]&&D[i][4]==D[i+1][3]&&D[i][3]==D[i+1][4]&&D[i][6]==D[i+1][6]){
    c++;
  }else if(D[i][1]==D[i+1][1]&&D[i][2]==D[i+1][4]&&D[i][4]==D[i+1][5]&&D[i][5]==D[i+1][3]&&D[i][3]==D[i+1][2]&&D[i][6]==D[i+1][6]){
    c++;
  }
  if(D[i][1]==D[i+1][2]&&D[i][2]==D[i+1][6]&&D[i][3]==D[i+1][3]&&D[i][5]==D[i+1][1]&&D[i][4]==D[i+1][4]&&D[i][6]==D[i+1][5]){
    c++;
  }else if(D[i][1]==D[i+1][2]&&D[i][2]==D[i+1][3]&&D[i][3]==D[i+1][1]&&D[i][5]==D[i+1][4]&&D[i][4]==D[i+1][6]&&D[i][6]==D[i+1][5]){
    c++;
  }else if(D[i][1]==D[i+1][2]&&D[i][2]==D[i+1][1]&&D[i][5]==D[i+1][6]&&D[i][3]==D[i+1][4]&&D[i][4]==D[i+1][3]&&D[i][6]==D[i+1][5]){
    c++;
  }else if(D[i][1]==D[i+1][2]&&D[i][2]==D[i+1][4]&&D[i][4]==D[i+1][1]&&D[i][5]==D[i+1][3]&&D[i][3]==D[i+1][6]&&D[i][6]==D[i+1][5]){
    c++;
  }
  if(D[i][1]==D[i+1][3]&&D[i][2]==D[i+1][2]&&D[i][3]==D[i+1][6]&&D[i][5]==D[i+1][5]&&D[i][4]==D[i+1][1]&&D[i][6]==D[i+1][4]){
    c++;
  }else if(D[i][1]==D[i+1][3]&&D[i][2]==D[i+1][6]&&D[i][3]==D[i+1][5]&&D[i][5]==D[i+1][1]&&D[i][4]==D[i+1][2]&&D[i][6]==D[i+1][4]){
    c++;
  }else if(D[i][1]==D[i+1][3]&&D[i][2]==D[i+1][5]&&D[i][3]==D[i+1][1]&&D[i][5]==D[i+1][2]&&D[i][4]==D[i+1][6]&&D[i][6]==D[i+1][4]){
    c++;
  }else if(D[i][1]==D[i+1][3]&&D[i][2]==D[i+1][1]&&D[i][3]==D[i+1][2]&&D[i][5]==D[i+1][6]&&D[i][4]==D[i+1][5]&&D[i][6]==D[i+1][4]){
    c++;
  }
  if(D[i][1]==D[i+1][4]&&D[i][2]==D[i+1][2]&&D[i][3]==D[i+1][1]&&D[i][5]==D[i+1][5]&&D[i][4]==D[i+1][6]&&D[i][6]==D[i+1][3]){
    c++;
  }else if(D[i][1]==D[i+1][4]&&D[i][2]==D[i+1][1]&&D[i][3]==D[i+1][5]&&D[i][5]==D[i+1][6]&&D[i][4]==D[i+1][2]&&D[i][6]==D[i+1][3]){
    c++;
  }else if(D[i][1]==D[i+1][4]&&D[i][2]==D[i+1][5]&&D[i][3]==D[i+1][6]&&D[i][5]==D[i+1][2]&&D[i][4]==D[i+1][1]&&D[i][6]==D[i+1][3]){
    c++;
  }else if(D[i][1]==D[i+1][4]&&D[i][2]==D[i+1][6]&&D[i][3]==D[i+1][2]&&D[i][5]==D[i+1][1]&&D[i][4]==D[i+1][5]&&D[i][6]==D[i+1][3]){
    c++;
  }
  if(D[i][1]==D[i+1][5]&&D[i][2]==D[i+1][1]&&D[i][3]==D[i+1][3]&&D[i][5]==D[i+1][6]&&D[i][4]==D[i+1][4]&&D[i][6]==D[i+1][2]){
    c++;
  }else if(D[i][1]==D[i+1][5]&&D[i][2]==D[i+1][3]&&D[i][3]==D[i+1][6]&&D[i][5]==D[i+1][4]&&D[i][4]==D[i+1][1]&&D[i][6]==D[i+1][2]){
    c++;
  }else if(D[i][1]==D[i+1][5]&&D[i][2]==D[i+1][6]&&D[i][3]==D[i+1][4]&&D[i][5]==D[i+1][1]&&D[i][4]==D[i+1][3]&&D[i][6]==D[i+1][2]){
    c++;
  }else if(D[i][1]==D[i+1][5]&&D[i][2]==D[i+1][4]&&D[i][3]==D[i+1][1]&&D[i][5]==D[i+1][3]&&D[i][4]==D[i+1][6]&&D[i][6]==D[i+1][2]){
    c++;
  }
  if(D[i][1]==D[i+1][6]&&D[i][2]==D[i+1][2]&&D[i][3]==D[i+1][4]&&D[i][5]==D[i+1][5]&&D[i][4]==D[i+1][3]&&D[i][6]==D[i+1][1]){
    c++;
  }else if(D[i][1]==D[i+1][6]&&D[i][2]==D[i+1][4]&&D[i][3]==D[i+1][5]&&D[i][5]==D[i+1][3]&&D[i][4]==D[i+1][2]&&D[i][6]==D[i+1][1]){
    c++;
  }else if(D[i][1]==D[i+1][6]&&D[i][2]==D[i+1][5]&&D[i][3]==D[i+1][3]&&D[i][5]==D[i+1][2]&&D[i][4]==D[i+1][4]&&D[i][6]==D[i+1][1]){
    c++;
  }else if(D[i][1]==D[i+1][6]&&D[i][2]==D[i+1][3]&&D[i][3]==D[i+1][2]&&D[i][5]==D[i+1][4]&&D[i][4]==D[i+1][5]&&D[i][6]==D[i+1][1]){
    c++;
  }
}
if(D[0][1]==D[n-1][1]&&D[0][2]==D[n-1][2]&&D[0][3]==D[n-1][3]&&D[0][4]==D[n-1][4]&&D[0][5]==D[n-1][5]&&D[0][6]==D[n-1][6]){
    c++;
  }else if(D[0][1]==D[n-1][1]&&D[0][2]==D[n-1][3]&&D[0][3]==D[n-1][5]&&D[0][5]==D[n-1][4]&&D[0][4]==D[n-1][2]&&D[0][6]==D[n-1][6]){
    c++;
  }else if(D[0][1]==D[n-1][1]&&D[0][2]==D[n-1][5]&&D[0][5]==D[n-1][2]&&D[0][4]==D[n-1][3]&&D[0][3]==D[n-1][4]&&D[0][6]==D[n-1][6]){
    c++;
  }else if(D[0][1]==D[n-1][1]&&D[0][2]==D[n-1][4]&&D[0][4]==D[n-1][5]&&D[0][5]==D[n-1][3]&&D[0][3]==D[n-1][2]&&D[0][6]==D[n-1][6]){
    c++;
  }
  if(D[0][1]==D[n-1][2]&&D[0][2]==D[n-1][6]&&D[0][3]==D[n-1][3]&&D[0][5]==D[n-1][1]&&D[0][4]==D[n-1][4]&&D[0][6]==D[n-1][5]){
    c++;
  }else if(D[0][1]==D[n-1][2]&&D[0][2]==D[n-1][3]&&D[0][3]==D[n-1][1]&&D[0][5]==D[n-1][4]&&D[0][4]==D[n-1][6]&&D[0][6]==D[n-1][5]){
    c++;
  }else if(D[0][1]==D[n-1][2]&&D[0][2]==D[n-1][1]&&D[0][5]==D[n-1][6]&&D[0][3]==D[n-1][4]&&D[0][4]==D[n-1][3]&&D[0][6]==D[n-1][5]){
    c++;
  }else if(D[0][1]==D[n-1][2]&&D[0][2]==D[n-1][4]&&D[0][4]==D[n-1][1]&&D[0][5]==D[n-1][3]&&D[0][3]==D[n-1][6]&&D[0][6]==D[n-1][5]){
    c++;
  }
  if(D[0][1]==D[n-1][3]&&D[0][2]==D[n-1][2]&&D[0][3]==D[n-1][6]&&D[0][5]==D[n-1][5]&&D[0][4]==D[n-1][1]&&D[0][6]==D[n-1][4]){
    c++;
  }else if(D[0][1]==D[n-1][3]&&D[0][2]==D[n-1][6]&&D[0][3]==D[n-1][5]&&D[0][5]==D[n-1][1]&&D[0][4]==D[n-1][2]&&D[0][6]==D[n-1][4]){
    c++;
  }else if(D[0][1]==D[n-1][3]&&D[0][2]==D[n-1][5]&&D[0][3]==D[n-1][1]&&D[0][5]==D[n-1][2]&&D[0][4]==D[n-1][6]&&D[0][6]==D[n-1][4]){
    c++;
  }else if(D[0][1]==D[n-1][3]&&D[0][2]==D[n-1][1]&&D[0][3]==D[n-1][2]&&D[0][5]==D[n-1][6]&&D[0][4]==D[n-1][5]&&D[0][6]==D[n-1][4]){
    c++;
  }
  if(D[0][1]==D[n-1][4]&&D[0][2]==D[n-1][2]&&D[0][3]==D[n-1][1]&&D[0][5]==D[n-1][5]&&D[0][4]==D[n-1][6]&&D[0][6]==D[n-1][3]){
    c++;
  }else if(D[0][1]==D[n-1][4]&&D[0][2]==D[n-1][1]&&D[0][3]==D[n-1][5]&&D[0][5]==D[n-1][6]&&D[0][4]==D[n-1][2]&&D[0][6]==D[n-1][3]){
    c++;
  }else if(D[0][1]==D[n-1][4]&&D[0][2]==D[n-1][5]&&D[0][3]==D[n-1][6]&&D[0][5]==D[n-1][2]&&D[0][4]==D[n-1][1]&&D[0][6]==D[n-1][3]){
    c++;
  }else if(D[0][1]==D[n-1][4]&&D[0][2]==D[n-1][6]&&D[0][3]==D[n-1][2]&&D[0][5]==D[n-1][1]&&D[0][4]==D[n-1][5]&&D[0][6]==D[n-1][3]){
    c++;
  }
  if(D[0][1]==D[n-1][5]&&D[0][2]==D[n-1][1]&&D[0][3]==D[n-1][3]&&D[0][5]==D[n-1][6]&&D[0][4]==D[n-1][4]&&D[0][6]==D[n-1][2]){
    c++;
  }else if(D[0][1]==D[n-1][5]&&D[0][2]==D[n-1][3]&&D[0][3]==D[n-1][6]&&D[0][5]==D[n-1][4]&&D[0][4]==D[n-1][1]&&D[0][6]==D[n-1][2]){
    c++;
  }else if(D[0][1]==D[n-1][5]&&D[0][2]==D[n-1][6]&&D[0][3]==D[n-1][4]&&D[0][5]==D[n-1][1]&&D[0][4]==D[n-1][3]&&D[0][6]==D[n-1][2]){
    c++;
  }else if(D[0][1]==D[n-1][5]&&D[0][2]==D[n-1][4]&&D[0][3]==D[n-1][1]&&D[0][5]==D[n-1][3]&&D[0][4]==D[n-1][6]&&D[0][6]==D[n-1][2]){
    c++;
  }
  if(D[0][1]==D[n-1][6]&&D[0][2]==D[n-1][2]&&D[0][3]==D[n-1][4]&&D[0][5]==D[n-1][5]&&D[0][4]==D[n-1][3]&&D[0][6]==D[n-1][1]){
    c++;
  }else if(D[0][1]==D[n-1][6]&&D[0][2]==D[n-1][4]&&D[0][3]==D[n-1][5]&&D[0][5]==D[n-1][3]&&D[0][4]==D[n-1][2]&&D[0][6]==D[n-1][1]){
    c++;
  }else if(D[0][1]==D[n-1][6]&&D[0][2]==D[n-1][5]&&D[0][3]==D[n-1][3]&&D[0][5]==D[n-1][2]&&D[0][4]==D[n-1][4]&&D[0][6]==D[n-1][1]){
    c++;
  }else if(D[0][1]==D[n-1][6]&&D[0][2]==D[n-1][3]&&D[0][3]==D[n-1][2]&&D[0][5]==D[n-1][4]&&D[0][4]==D[n-1][5]&&D[0][6]==D[n-1][1]){
    c++;
  }
  if(D[30][1]==4&&D[30][2]==6&&D[30][3]==2){
    cout <<"No"<<endl;
  }
  else if(c==0){
    cout<<"Yes"<<endl;
    }else {
        cout <<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3092