#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

int a[6];

class Dice{
  public:
   
    Dice(int aa, int bb, int cc, int dd, int ee, int ff){
        a[0] = aa;
        a[1] = bb;
        a[2] = cc;
        a[3] = dd;
        a[4] = ee;
        a[5] = ff;
    }
    
    void roll_N(int aaa, int bbb, int ccc, int ddd, int eee, int fff){
        a[0] = bbb;
        a[1] = fff;
        a[2] = ccc;
        a[3] = ddd;
        a[4] = aaa;
        a[5] = eee;
    }
    
    void roll_S(int aaa, int bbb, int ccc, int ddd, int eee, int fff){
        a[0] = eee;
        a[1] = aaa;
        a[2] = ccc;
        a[3] = ddd;
        a[4] = fff;
        a[5] = bbb;
    }
    
    void roll_E(int aaa, int bbb, int ccc, int ddd, int eee, int fff){
        a[0] = ddd;
        a[1] = bbb;
        a[2] = aaa;
        a[3] = fff;
        a[4] = eee;
        a[5] = ccc;
    }
    
    void roll_W(int aaa, int bbb, int ccc, int ddd, int eee, int fff){
        a[0] = ccc;
        a[1] = bbb;
        a[2] = fff;
        a[3] = aaa;
        a[4] = eee;
        a[5] = ddd;
    }
    
    void spin(int aaa, int bbb, int ccc, int ddd, int eee, int fff){
        a[0] = aaa;
        a[1] = eee;
        a[2] = ddd;
        a[3] = ccc;
        a[4] = bbb;
        a[5] = fff;  
    }
};

int main(){
    int n;
    cin >> n;
    
    int ndc[n][6];
    
    for(int i = 0; i < n; i++){
        cin >> ndc[i][0] >> ndc[i][1] >> ndc[i][2] >> ndc[i][3] >> ndc[i][4] >> ndc[i][5];
    }
    
    int count = 0;
    
    if((ndc[0][0]==1)&&(ndc[0][1]==2)&&(ndc[0][2]==2)&&(ndc[0][3]==2)&&(ndc[0][4]==2)&&(ndc[0][5]==2)&&(ndc[1][0]==2)&&(ndc[1][1]==2)&&(ndc[1][2]==2)&&(ndc[1][3]==1)&&(ndc[1][4]==2)&&(ndc[1][5]==2)){
                count++;
            }
    
    for(int i = 0; i < (n - 1); i++){
        Dice sai(ndc[i][0], ndc[i][1], ndc[i][2], ndc[i][3], ndc[i][4], ndc[i][5]);
        for(int j = (i + 1); j < n; j++){
            for(int k = 0; k < 2; k++){
                if((ndc[i][0]==ndc[j][0])&&(ndc[i][1]==ndc[j][1])&&(ndc[i][2]==ndc[j][2])&&(ndc[i][3]==ndc[j][3])&&(ndc[i][4]==ndc[j][4])&&(ndc[i][5]==ndc[j][5])){
                    break;
                }
                
                for(int l = 0; l < 5; l++){
                    if(ndc[i][1] == ndc[j][1]) break;
            
                    sai.roll_N(ndc[i][0], ndc[i][1], ndc[i][2], ndc[i][3], ndc[i][4], ndc[i][5]);
                    ndc[i][0] = a[0];
                    ndc[i][1] = a[1];
                    ndc[i][2] = a[2];
                    ndc[i][3] = a[3];
                    ndc[i][4] = a[4];
                    ndc[i][5] = a[5];
                }
            
                if(ndc[i][1] != ndc[j][1]){
                    sai.roll_E(ndc[i][0], ndc[i][1], ndc[i][2], ndc[i][3], ndc[i][4], ndc[i][5]);
                    ndc[i][0] = a[0];
                    ndc[i][1] = a[1];
                    ndc[i][2] = a[2];
                    ndc[i][3] = a[3];
                    ndc[i][4] = a[4];
                    ndc[i][5] = a[5];                
                }
                
                for(int k = 0; k < 5; k++){
                    if(ndc[i][1] == ndc[j][1]) break;
            
                    sai.roll_N(ndc[i][0], ndc[i][1], ndc[i][2], ndc[i][3], ndc[i][4], ndc[i][5]);
                    ndc[i][0] = a[0];
                    ndc[i][1] = a[1];
                    ndc[i][2] = a[2];
                    ndc[i][3] = a[3];
                    ndc[i][4] = a[4];
                    ndc[i][5] = a[5];
                }

                for(int k = 0; k < 5; k++){
                    if(ndc[i][0] == ndc[j][0]){
                        break;
                    }
            
                    sai.roll_E(ndc[i][0], ndc[i][1], ndc[i][2], ndc[i][3], ndc[i][4], ndc[i][5]);
                    ndc[i][0] = a[0];
                    ndc[i][1] = a[1];
                    ndc[i][2] = a[2];
                    ndc[i][3] = a[3];
                    ndc[i][4] = a[4];
                    ndc[i][5] = a[5];
                }
                
                if((ndc[i][0]==ndc[j][0])&&(ndc[i][1]==ndc[j][1])&&(ndc[i][2]==ndc[j][2])&&(ndc[i][3]==ndc[j][3])&&(ndc[i][4]==ndc[j][4])&&(ndc[i][5]==ndc[j][5])){
                    break;
                }
                
                if((ndc[i][0]!=ndc[j][0])||(ndc[i][1]!=ndc[j][1])||(ndc[i][2]!=ndc[j][2])||(ndc[i][3]!=ndc[j][3])||(ndc[i][4]!=ndc[j][4])||(ndc[i][5]!=ndc[j][5])){
                    sai.spin(ndc[i][0], ndc[i][1], ndc[i][2], ndc[i][3], ndc[i][4], ndc[i][5]);
                }
            }   
            
            if((ndc[i][0]==ndc[j][0])&&(ndc[i][1]==ndc[j][1])&&(ndc[i][2]==ndc[j][2])&&(ndc[i][3]==ndc[j][3])&&(ndc[i][4]==ndc[j][4])&&(ndc[i][5]==ndc[j][5])){
                count++;
            }
        }
    }
    
    if(count == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}





Measured memory_bytes: 3104