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

class dice {
    private:
    
    public:
    //dice(int a[6]);
    int surf[6];
    void move_N();
    void move_S();
    void move_E();
    void move_W();
    void show_top();
    bool issame(int b[6],char str[]);
    void move(char str);
    void setnum(int a[6]);
};
/*
dice::dice(int a[6]){
    for(int i = 0; i < 6; i++){
        surf[i] = a[i];
    }
}
*/
void dice::setnum(int a[6]){
    for(int i = 0; i < 6; i++){
        surf[i] = a[i];
    }
}

void dice::move_S(){
    int buf[6];
    for(int i = 0; i < 6; i++){
        buf[i] = surf[i];
    }
    surf[0] = buf[4];
    surf[1] = buf[0];
    surf[4] = buf[5];
    surf[5] = buf[1];

}

void dice::move_N(){
    int buf[6];
    for(int i = 0; i < 6; i++){
        buf[i] = surf[i];
    }
    surf[0] = buf[1];
    surf[1] = buf[5];
    surf[4] = buf[0];
    surf[5] = buf[4];

}

void dice::move_W(){
    int buf[6];
    for(int i = 0; i < 6; i++){
        buf[i] = surf[i];
    }
    surf[0] = buf[2];
    surf[2] = buf[5];
    surf[3] = buf[0];
    surf[5] = buf[3];

}

void dice::move_E(){
    int buf[6];
    for(int i = 0; i < 6; i++){
        buf[i] = surf[i];
    }
    surf[0] = buf[3];
    surf[2] = buf[0];
    surf[3] = buf[5];
    surf[5] = buf[2];

}

void dice::show_top(){
    cout << surf[0] << endl;
}

bool dice::issame(int b[6],char str[25]){
    int flag = 0;
    for(int i = 0; i < 24; i++){
        move(str[i]);
        for(int i = 0; i < 6; i++){
            if(surf[i] == b[i]){
                flag++;
            }
        }
        if(flag == 6) return true;
        flag = 0;
    }
    return false;
}

void dice::move(char str){
    switch(str){
        case 'N':
            move_N();
        break;
        case 'W':
            move_W();

        break;
        case 'E':
            move_E();
        break;
        case 'S':
            move_S();
        break;
        default:
        break;
    }
}
int main(){
    int a[6];
    //int **b;

    bool ans = false;
    char dir[] = "NNNNWNNNWNNNENNNENNNWNNN";
    //int flag = 0;
    int num = 0;
    cin  >> num;
    dice array[100];
    for(int i = 0; i < num; i++){
        for(int j = 0; j < 6; j++){
            cin >> a[j];
        }
        array[i].setnum(a);
    }
    /*
    for(int i = 0; i < num; i++){
        for (int j = 0; j < 6; j++){
            cout << array[i].surf[j] << " ";
        }
        cout << endl;
    }
    
   dice test;
   int x[6] = {1,2,3,4,5,6};
   test.setnum(x);
   int b[6] = {6,2,4,3,5,1};
    ans = test.issame(b,dir);
    cout << ans;
    */
    
    for(int i = 0; i < num - 1; i++){
        for(int j = i + 1; j < num; j++){
            /*
            for(int k = 0; k < 6; k++){
                cout << array[i].surf[k] << " "; 
            }
            cout << endl;
            for(int k = 0; k < 6; k++){
                cout << array[j].surf[k] << " "; 
            }
            cout << endl;
            */

            ans = array[i].issame(array[j].surf,dir);
            if(ans == true) {
                //cout << i << " " << j << endl;
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
    



}





Measured memory_bytes: 3100