#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <set>
#include <list>

using namespace std;

class Dice {
    int s1, s2, s3, s4, s5, s6;

public:
    Dice(int s1, int s2, int s3, int s4, int s5, int s6);

    void print();

    void relocate(int top, int front);

    void roll(char F);

    bool make_top(int top);

    bool make_front(int front);

    void print(int side);

    int get(int side);

    bool is_equal(Dice d);
};

bool Dice::make_top(int top) {
    bool res = true;
    if (s1 == top) {}
    else if (s2 == top) {
        roll('N');
    } else if (s3 == top) {
        roll('W');
    } else if (s4 == top) {
        roll('E');
    } else if (s5 == top) {
        roll('S');
    } else if (s6 == top) {
        roll('N');
        roll('N');
    } else {
        res = false;
    }
    return res;
}

bool Dice::make_front(int front) {
    if (front == s2) return true;
    else if (front == s6 || front == s1) return false;
    else roll('R');
    bool res = make_front(front);
    return res;
}

void Dice::relocate(int top, int front) {
    vector<int> S{s1, s2, s3, s4, s5, s6};
    int top_idx = distance(S.begin(), find(S.begin(), S.end(), top));
    int front_idx = distance(S.begin(), find(S.begin(), S.end(), front));

    int tmp_s1 = s1;
}

void Dice::roll(char F) {
    int tmp = s1;
    if (F == 'N') {
        s1 = s2;
        s2 = s6;
        s6 = s5;
        s5 = tmp;
    } else if (F == 'W') {
        s1 = s3;
        s3 = s6;
        s6 = s4;
        s4 = tmp;
    } else if (F == 'S') {
        s1 = s5;
        s5 = s6;
        s6 = s2;
        s2 = tmp;
    } else if (F == 'E') {
        s1 = s4;
        s4 = s6;
        s6 = s3;
        s3 = tmp;
    } else if (F == 'R') {
        tmp = s2;
        s2 = s3;
        s3 = s5;
        s5 = s4;
        s4 = tmp;
    } else {
        cout << "unknown command: " << F << endl;
    }
}

void Dice::print() {
    cout << s1 << endl;
}

void Dice::print(int side) {
    vector<int> S{s1, s2, s3, s4, s5, s6};
    cout << S[side - 1] << endl;
}

int Dice::get(int side) {
    vector<int> S{s1, s2, s3, s4, s5, s6};
    return S[side - 1];
}

bool Dice::is_equal(Dice d2) {
    bool ans = true;
    int front, top;

    set<int> s1, s2;
    for (int j = 1; j <= 6; j++) {
        s1.insert(get(j));
        s2.insert(d2.get(j));
    }
    if (s1 != s2)return false;

    for (int i = 1; i <= 6; i++) {
        top = d2.get(i);
        if (i == 6)front = d2.get(1);
        else front = d2.get(i + 1);

        ans = make_top(top);
        ans = ans && d2.make_top(top);

        if (ans) {
            make_front(front);
            d2.make_front(front);
        }


        for (int j = 1; j <= 6; j++) {
            ans = ans && get(j) == d2.get(j);
        }
        if (ans)break;
    }
    return ans;
}


Dice::Dice(int _s1, int _s2, int _s3, int _s4, int _s5, int _s6) {
    s1 = _s1;
    s2 = _s2;
    s3 = _s3;
    s4 = _s4;
    s5 = _s5;
    s6 = _s6;
}

int main() {
    int n;
    cin >> n;
    int S[6];

    list<Dice> dices;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 6; j++) {
            cin >> S[j];
        }
        Dice d = Dice(S[0], S[1], S[2], S[3], S[4], S[5]);
        dices.push_back(d);
    }

    // n_equal==n if all die are different
    int n_equal = 0;
    list<Dice>::iterator it1, it2;
    for (it1 = dices.begin(); it1 != dices.end(); it1++) {
        for (it2 = dices.begin(); it2 != dices.end(); it2++) {
            if (it1->is_equal(*it2))n_equal++;
        }
    }

    if (n_equal == n) cout << "Yes" << endl;
    else cout << "No" << endl;


}


Measured memory_bytes: 3112