#include<iostream>
#include<string>
using namespace std;

class Dice{
public:
    int Now[7], Will[7];
    
    Dice(int N[]){
        for(int i=1; i<7; i++){
            Now[i]=N[i];
            Will[i]=N[i];
        }
    }
    
    void move_S(){
        Will[1] = Now[5];
        Will[2] = Now[1];
        Will[6] = Now[2];
        Will[5] = Now[6];
        
        for(int i=1; i<7; i++){
            Now[i] = Will[i];
        }
    }
    
    void move_E(){
        Will[1] = Now[4];
        Will[3] = Now[1];
        Will[6] = Now[3];
        Will[4] = Now[6];
        
        for(int i=1; i<7; i++){
            Now[i] = Will[i];
        }
    }
    
    void move_N(){
        Will[1] = Now[2];
        Will[5] = Now[1];
        Will[6] = Now[5];
        Will[2] = Now[6];
        
        for(int i=1; i<7; i++){
            Now[i] = Will[i];
        }
    }
    
    void move_W(){
        Will[1] = Now[3];
        Will[4] = Now[1];
        Will[6] = Now[4];
        Will[3] = Now[6];
        
        for(int i=1; i<7; i++){
            Now[i] = Will[i];
        }
    }

    void turn(){
        Will[2] = Now[4];
        Will[3] = Now[2];
        Will[5] = Now[3];
        Will[4] = Now[5];

        for(int i=1; i<7; i++){
            Now[i] = Will[i];
        }
    }
    
    int top(){
        return Now[1];
    }

    int front(){
        return Now[2];
    }

    int right(){
        return Now[3];
    }

    int left(){
        return Now[4];
    }

    int back(){
        return Now[5];
    }

    int bottom(){
        return Now[6];
    }
};


int main(){
    int dices[100][7];
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=1; j<7; j++){
            cin >> dices[i][j];
        }
    }

    int Face1[7];
    int Face2[7];
    int judge=0;

    for(int i=0; i<n; i++){
        for(int a=1; a<7;a++){
            Face1[a] = dices[i][a];
        }

        int J=0;
        for(int k=i+1; k<n; k++){
            for(int b=1; b<7; b++){
                Face2[b] = dices[k][b];
            }

            //比較
            Dice dice1(Face1);
            Dice dice2(Face2);

            
            if(dice1.top() != dice2.top() || dice1.bottom() != dice2.bottom()){
                dice1.move_N();
                if(dice1.top() != dice2.top() || dice1.bottom() != dice2.bottom()){
                    dice1.move_W();
                    if(dice1.top() != dice2.top() || dice1.bottom() != dice2.bottom()){
                        dice1.move_W();
                        if(dice1.top() != dice2.top() || dice1.bottom() != dice2.bottom()){
                            dice1.move_W();
                            if(dice1.top() != dice2.top() || dice1.bottom() != dice2.bottom()){
                                dice1.move_N();
                            }
                        }
                    }
                }
            }

            for(int i=0; i<3; i++){
                if(dice1.back() != dice2.back() || dice1.left() != dice2.left()||dice1.front() != dice2.front() || dice1.right() != dice2.right()){
                    dice1.turn();
                }
            }
//
            if(dice1.right() == dice2.right()){
                if(dice1.left() == dice2.left()){
                    if(dice1.back() == dice2.back()){
                        if(dice1.bottom() == dice2.bottom()){
                            J = 1;
                        }
                    }
                }
            }
            if (J == 1) judge=1;

        }
        if(judge == 1) break;
    }

    if(judge == 1){
        cout << "No" <<endl;
    } else {
        cout << "Yes" << endl;
    }


    return 0;
}


Measured memory_bytes: 3100