#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

namespace {
    class Dice {
    private:
        int n1;
        int n2;
        int n3;
        int n4;
        int n5;
        int n6;
    public:
        Dice(int _n1, int _n2, int _n3, int _n4, int _n5, int _n6):
            n1(_n1), n2(_n2), n3(_n3), n4(_n4), n5(_n5), n6(_n6) {}
        ~Dice() = default;

        void set(int top, int front) {
            set_top(top);
            set_front(front);
        }

        bool identical(const Dice& other) {
            Dice tmp(other);
            tmp.set(n1, n2);
            return n1 == tmp.n1 &&
                   n2 == tmp.n2 &&
                   n3 == tmp.n3 &&
                   n4 == tmp.n4 &&
                   n5 == tmp.n5 &&
                   n6 == tmp.n6;
        }

        void move_n() {
            int tmp = n1;
            n1 = n2;
            n2 = n6;
            n6 = n5;
            n5 = tmp;
        }
        void move_e() {
            int tmp = n1;
            n1 = n4;
            n4 = n6;
            n6 = n3;
            n3 = tmp;
        }
        void move_s() {
            int tmp = n1;
            n1 = n5;
            n5 = n6;
            n6 = n2;
            n2 = tmp;
        }
        void move_w() {
            int tmp = n1;
            n1 = n3;
            n3 = n6;
            n6 = n4;
            n4 = tmp;
        }
        void rotate_clockwise() {
            int tmp = n2;
            n2 = n3;
            n3 = n5;
            n5 = n4;
            n4 = tmp;
        }
        void rotate_anticlockwise() {
            int tmp = n2;
            n2 = n4;
            n4 = n5;
            n5 = n3;
            n3 = tmp;
        }

        friend ostream& operator<<(ostream& os, const Dice& d);
    private:
        void set_top(int top) {
            if (n2 == top) { move_n(); }
            else if (n3 == top) { move_w(); }
            else if (n4 == top) { move_e(); }
            else if (n5 == top) { move_s(); }
            else if (n6 == top) {
                move_w();
                move_w();
            }
        }
        void set_front(int front) {
            if (n3 == front) { rotate_clockwise(); }
            else if (n4 == front) { rotate_anticlockwise(); }
            else if (n5 == front) {
                rotate_clockwise();
                rotate_clockwise();
            }
        }
    };

    std::ostream& operator<<(std::ostream &os, const Dice& d) {
        return os << "{" << d.n1  << "," <<
                            d.n2  << "," <<
                            d.n3  << "," <<
                            d.n4  << "," <<
                            d.n5  << "," <<
                            d.n6  << "}";
    }
}

int main() {
    int n;
    cin >> n;

    bool identical = false;
    vector<Dice> ds;

    for (int i = 0; i < n; i++) {
        int n1,n2,n3,n4,n5,n6;
        cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
        Dice d(n1,n2,n3,n4,n5,n6);

        for (auto& _d : ds) {
            if (_d.identical(d)) {
                identical = true;
            }
        }
        ds.push_back(d);
    }
    if (identical) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1196