#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
     
using namespace std;
 
//pay attention to relative position
class Dice
{
    public: 
    int temp1;
    int temp2;
    int a[100];
      
   // Dice(int top, int south, int east, int west, int north, int bottom)
    //{        
       // a[1] = top;
       // a[2] = south;
      //  a[3] = east;
      //  a[4] = west;
      //  a[5] = north;
     //   a[6] = bottom;
  //  }
      
    void RollS()
    {
            temp1 = a[1];
            temp2 = a[2];
            a[1] = a[5];
            a[2] = temp1;
            a[5] = a[6];
            a[6] = temp2;
    }
      
     void RollN()
    {
            temp1 = a[1];
            temp2 = a[5];
            a[1] = a[2];
            a[2] = a[6];
            a[5] = temp1;
            a[6] = temp2;   
    }
      
     void RollW()
    {
            temp1 = a[1];
            temp2 = a[4];
            a[1] = a[3];
            a[3] = a[6];
            a[4] = temp1;
            a[6] = temp2;
    }
      
     void RollE()
    {
            temp1 = a[1];
            temp2 = a[3];
            a[1] = a[4];
            a[3] = temp1;
            a[4] = a[6];
            a[6] = temp2;
    }
     
    void Spin()  //??¨?????????¬?????????????
    {
        temp1 = a[2];
        temp2 = a[4];
        a[2] = a[3]; 
        a[3] = a[5];
        a[4] = temp1;
        a[5] = temp2;
    }
};
  
void Solution()
{    
    int n;
    cin>>n;
    
    Dice p[n];
    
    for(int i = 0; i < n; i++)
    {
        cin>>p[i].a[1]>>p[i].a[2]>>p[i].a[3]>>p[i].a[4]>>p[i].a[5]>>p[i].a[6];
    }
       
      
    //Dice p1(a[1], a[2], a[3], a[4], a[5], a[6]); 
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if(p[i].a[4] == p[j].a[1] || p[i].a[3] == p[j].a[1]) {p[i].RollE();}
            for(int m = 0; m < 4; m++)
            {
                if(p[i].a[1] == p[j].a[1]) break;
                p[i].RollN(); // spin based on x axis
            }
        //after ensure the a[1] == b[1], there is a[2] left
            for(int n = 0; n < 4; n++)
            {
                if(p[i].a[2] == p[j].a[2]) break;
                p[i].Spin(); // spin based on y axis
            }
            for(int n = 0; n < 4; n++)
            {
                if(p[i].a[3] == p[j].a[3]) break;
                p[i].Spin(); // spin based on y axis
            }
             for(int n = 0; n < 4; n++)
            {
                if(p[i].a[4] == p[j].a[4]) break;
                p[i].Spin(); // spin based on y axis
            }
             if(p[i].a[1] == p[j].a[1] &&
                p[i].a[2] == p[j].a[2] &&
                p[i].a[3] == p[j].a[3] &&
                p[i].a[4] == p[j].a[4] &&
                p[i].a[5] == p[j].a[5] &&
                p[i].a[6] == p[j].a[6])
            {
                cout<<"No"<<endl;
                 return;
            }
        }
    }
    
    cout<<"Yes"<<endl;
}
     
int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1196