#include <bits/stdc++.h>

using namespace std;

class Dice{

public:
    unique_ptr<vector<int>> nums;
    unique_ptr<vector<vector<int>>> all;

    Dice(){
        nums.reset(new vector<int>(6));
        all.reset(new vector<vector<int>>(24, vector<int>(6)));
    }

    void rotate(char dir){
        int a, b, c, d;
        switch(dir){
        case 'N':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = b;
            nums->at(1) = c;
            nums->at(5) = d;
            nums->at(4) = a;
            break;
        case 'E':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = d;
            nums->at(2) = a;
            nums->at(5) = b;
            nums->at(3) = c;
            break;
        case 'W':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = b;
            nums->at(2) = c;
            nums->at(5) = d;
            nums->at(3) = a;
            break;
        case 'S':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = d;
            nums->at(1) = a;
            nums->at(5) = b;
            nums->at(4) = c;
            break;
        }
    }

    void print_pattern(int i){
        for(int j = 0; j < 6; j++){ cout << " " << all->at(i).at(j); }
        cout << endl;
    }

    void rotate_all(){
        int i = 0;
        for(;i < 4; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');
        for(;i < 8; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');
        for(;i < 12; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');
        for(;i < 16; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');

        rotate('W');
        rotate('S');

        for(;i < 20; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }

        rotate('N');
        rotate('N');

        for(;i < 24; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
    }

    bool same(Dice &other){
        for(int j = 0; j < other.all->size(); j++){
            bool flag = true;
            for(int k = 0; k < 6; k++){
                flag &= nums->at(k) == other.all->at(j).at(k);
            }
            if(flag) return true;
        }
        return false;
    }

};

int main()
{
    int n;
    cin >> n;
    
    vector<Dice> d(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 6; j++){
            cin >> d.at(i).nums->at(j);
        }
        d.at(i).rotate_all();
    }

    bool flag = false;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            bool f = d.at(i).same(d.at(j));
            flag |= f;
        }
    }
    if(flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}


Measured memory_bytes: 3308