#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807

  vector<int> roll(char opp,vector<int>  DICE)
  {
    vector<int> rolled(6,0);

    if(opp =='W')
    {
      rolled[0] = DICE[2];
      rolled[1] = DICE[1];
      rolled[2] = DICE[5];
      rolled[3] = DICE[0];
      rolled[4] = DICE[4];
      rolled[5] = DICE[3];
    }
    else if( opp == 'S')
    {
      rolled[0] = DICE[4];
      rolled[1] = DICE[0];
      rolled[2] = DICE[2];
      rolled[3] = DICE[3];
      rolled[4] = DICE[5];
      rolled[5] = DICE[1];
    }
    else if(opp == 'N')
    {
      rolled[0] = DICE[1];
      rolled[1] = DICE[5];
      rolled[2] = DICE[2];
      rolled[3] = DICE[3];
      rolled[4] = DICE[0];
      rolled[5] = DICE[4];
    }

    else if(opp == 'E')
    {
      rolled[0] = DICE[3];
      rolled[1] = DICE[1];
      rolled[2] = DICE[0];
      rolled[3] = DICE[5];
      rolled[4] = DICE[4];
      rolled[5] = DICE[2];
    }
    else if(opp == 'R')
    {
      rolled[0] = DICE[0];
      rolled[1] = DICE[2];
      rolled[2] = DICE[4];
      rolled[3] = DICE[1];
      rolled[4] = DICE[3];
      rolled[5] = DICE[5];     
    }
    else
    {
      cout<<"XXX"<<endl;
    }
    

    return rolled;
    

  }

  bool Q_check(vector<int> DICE,int TOP,int FRONT)
  {
    if((DICE[0] == TOP)&&(DICE[1] ==FRONT))
    {
      cout<<DICE[2]<<endl;
      return 1;
    }

    return 0;
  }

  bool Q_check_2(vector<int> DICE,vector<int> DICE_2)
  {
    bool check = 1;

    for (int i = 0; i < 6; i++)
    {
      if(DICE[i] != DICE_2[i]) check = 0;
    }

    if(check == 1)
    {
      // cout<<"Yes"<<endl;
      return 1;
    }
    

    return 0;
  }


  void Q(vector<int> DICE,int TOP,int FRONT)
  {
    bool check = 0;

    for (int q = 0; q < 4; q++)
    {
     for (int i = 0; i < 4; i++)
    {
      DICE = roll('R',DICE);
      check = Q_check(DICE,TOP,FRONT);
      if(check == 1) return;
    }

    DICE = roll('N',DICE);     
    }
    
    for (int q = 0; q < 4; q++)
    {
     for (int i = 0; i < 4; i++)
    {
      DICE = roll('R',DICE);
      check = Q_check(DICE,TOP,FRONT);
      if(check == 1) return;
    }

    DICE = roll('E',DICE);     
    }

  
  }

  bool DICE_COMP(vector<int> DICE, vector<int> DICE_2)
  {
    bool check = 0;

    for (int q = 0; q < 4; q++)
    {
     for (int i = 0; i < 4; i++)
    {
      DICE = roll('R',DICE);
      check = Q_check_2(DICE,DICE_2);
      if(check == 1) return 1;
    }

    DICE = roll('N',DICE);     
    }
    
    for (int q = 0; q < 4; q++)
    {
     for (int i = 0; i < 4; i++)
    {
      DICE = roll('R',DICE);
      check = Q_check_2(DICE,DICE_2);
      if(check == 1) return 1;
    }

    DICE = roll('E',DICE);     
    }

    // cout<<"No"<<endl;
    return 0;
  }
void solve(void)
{ 

  int N;
  cin>>N;
  vector<vector<int> > dicemat(N,vector<int>(6,0));

  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 6; j++)
    {
      cin>>dicemat[i][j];
    }
  }

  bool check = 0;
  bool out;
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      out = DICE_COMP(dicemat[i],dicemat[j]);
      if(out == 1) check =1;
    }
  }

  if(check == 1) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  


  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3160