#include <iostream>
using namespace std;
class Dice{
public:
    int n1,n2,n3,n4,n5,n6;
    
    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
    void Rotation(){
        int t=n2;
        n2 = n3;
        n3 = n5;
        n5 = n4;
        n4 = t;
    }
};

int main(){
    Dice d[100];
    int n;
    
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>d[i].n1>>d[i].n2>>d[i].n3>>d[i].n4>>d[i].n5>>d[i].n6;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j==i)continue;
            for(int k=0; k<6; k++){
                if(k==4){
                    d[i].East();
                }
                if(k==5){
                d[i].East();
                d[i].East();
                }
                for(int l=0; l<4; l++){
                    d[i].Rotation();
                    if(d[i].n1==d[j].n1 && d[i].n2==d[j].n2 && d[i].n3==d[j].n3 &&
                       d[i].n4==d[j].n4 && d[i].n5==d[j].n5 && d[i].n6==d[j].n6){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
            
        }
        
    }
    cout<<"Yes"<<endl;
    return 0;
}