#include<iostream>
#include<string>

using namespace std;

class dice
{
public:
  int d[6];
  int t;
  int n;
  int e;
  int s;
  int w;
  int b;
  
  dice();
  int init();
  int move(char c);
  int runCmd(string cmd);
  int toTop(int x);
  int toFront(int x);
  int top();
  int right();
  int left();
  int back();
  int front();
  int bottom();
  bool equal(dice d);
};

dice::dice()
{
  t = 0;
  n = 4;
  e = 2;
  s = 1;
  w = 3;
  b = 5;
}

int dice::init()
{
  for(int i = 0; i < 6; i++ )
    {
      cin >> d[i];
    }
  return 0;
}

int dice::move(char c)
{
  int tmp;
  
  if ( c == 'E' )
    {
      tmp = t;
      t = w;
      w = b;
      b = e;
      e = tmp;
    }
  else if ( c == 'N' )
    {
      tmp = t;
      t = s;
      s = b;
      b = n;
      n = tmp;
    }
  else if ( c == 'S' )
    {
      tmp = t;
      t = n;
      n = b;
      b = s;
      s = tmp;
    }
  else if ( c == 'W' )
    {
      tmp = t;
      t = e;
      e = b;
      b = w;
      w = tmp;
    }

  return 0;
}

int dice::runCmd(string cmd)
{
  for ( int i = 0; i < (int)cmd.size(); i++ )
    move( cmd[i] );

  return 0;
}

int dice::toTop(int x)
{
  int pt;
  
  for ( int i = 0; i < 6; i++ )
    {
      if ( d[i] == x )
        {
          pt = i;
          break;
        }
    }
  
  if ( n == pt )
    {
      runCmd( "S" );
    }
  else if ( e == pt )
    {
      runCmd( "W" );
    }
  else if ( s == pt )
    {
      runCmd( "N" );
    }
  else if ( w == pt )
    {
      runCmd( "E" );
    }
  else if ( b == pt )
    {
      runCmd("NN");
    }

  return 0;
}

int dice::toFront(int x)
{
  int pt;
  
  for ( int i = 0; i < 6; i++ )
    {
      if ( d[i] == x )
        {
          pt = i;
          break;
        }
    }
  
  if ( n == pt )
    {
      runCmd( "ESWESW" );
    }
  else if ( e == pt )
    {
      runCmd( "NWS" );
    }
  else if ( w == pt )
    {
      runCmd( "ESW" );
    }
}

int dice::top()
{
  return d[t];
}

int dice::right()
{
  return d[e];
}

int dice::left()
{
  return d[w];
}

int dice::back()
{
  return d[n];
}

int dice::front()
{
  return d[s];
}

int dice::bottom()
{
  return d[b];
}

bool dice::equal(dice d)
{
  string cmd[] = { "ENW",
                   "ENW",
                   "ENW",
                   "ENW",
                   "S",
                   "ENW",
                   "ENW",
                   "ENW",
                   "ENWNN",
                   "ENW",
                   "ENW",
                   "ENW",
                   "ENWSE",
                   "ENW",
                   "ENW",
                   "ENW",
                   "ENWWW",
                   "ENW",
                   "ENW",
                   "ENW",
                   "ENWENN",
                   "ENW",
                   "ENW",
                   "ENW" };
  
  for ( int i = 0; i < 24; i++ )
    {
      d.runCmd( cmd[i] );
  
      if ( right() == d.right() &&
           left() == d.left() &&
           top() == d.top() &&
           front() == d.front() &&
           back() == d.back() &&
           bottom() == d.bottom() )
        {
          return true;
        }
    }
  
  return false;
  
}

int main()
{
  dice d[100];
  int n;

  cin >> n;

  for ( int i = 0; i < n; i++ )
    {
      d[i].init();
    }

  for ( int i = 0; i < n - 1; i++ )
    {
      for ( int j = i + 1; j < n; j++ )
        {
          if ( d[i].equal( d[j] ) )
            {
              cout << "No" << endl;
              return 0;
            }
        }
    }
  
  cout << "Yes" << endl;
      
  return 0;
}

Measured memory_bytes: 1208