#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
void S(vector<int>&in){
  int tmp=in[1];
  in[1]=in[0];
  in[0]=in[4];
  in[4]=in[5];
  in[5]=tmp;
}
void E(vector<int>&in){
  int tmp=in[2];
  in[2]=in[0];
  in[0]=in[3];
  in[3]=in[5];
  in[5]=tmp;
}
void T(vector<int>&in){
  int tmp=in[1];
  in[1]=in[2];
  in[2]=in[4];
  in[4]=in[3];
  in[3]=tmp;
}
bool isT(vector<int>&in,vector<int>&out){
  bool h=false;
  rep(i,5){
    S(in);
    if(in[0]==out[0]){h=true;break;}
  }
  if(!h){
    rep(i,5){
      E(in);
      if(in[0]==out[0])break;
    }
  }
  rep(i,5){
    T(in);
    if(in[1]==out[1])break;
  }
  h=true;
  rep(i,6)if(in[i]!=out[i])h=false;
  if(h)return 1;
  else return 0;
}
int main(){
  int n;
  cin>>n;
  vector<vector<int> >in(n);
  rep(i,n)rep(j,6){
    int tmp;cin>>tmp;
    in[i].pb(tmp);
  }
  bool h=false;
  rep(i,n)loop(j,i+1,n)if(isT(in[i],in[j]))h=true;
  if(h)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}