#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

class Sai {
    vector<int> m_s;
public:
    Sai(void) {}
    Sai(vector<int> s) {
        m_s = vector<int>(6);
        rep(i, 6) {
            m_s.at(i) = s.at(i);
        }
    }
    void set(vector<int> s) {
        m_s = vector<int>(6);
        rep(i, 6) {
            m_s.at(i) = s.at(i);
        }
    }
    void move(char ch) {
        switch(ch) {
        case 'E':
            swap(m_s.at(0), m_s.at(3));
            swap(m_s.at(2), m_s.at(3));
            swap(m_s.at(3), m_s.at(5));
            break;
        case 'N':
            swap(m_s.at(0), m_s.at(1));
            swap(m_s.at(4), m_s.at(1));
            swap(m_s.at(5), m_s.at(1));
            break;
        case 'S':
            swap(m_s.at(0), m_s.at(4));
            swap(m_s.at(1), m_s.at(4));
            swap(m_s.at(5), m_s.at(4));
            break;
        case 'W':
            swap(m_s.at(0), m_s.at(2));
            swap(m_s.at(3), m_s.at(2));
            swap(m_s.at(5), m_s.at(2));
            break;
        default:
            assert(false);
        }
    }
    int top(void) {
        return m_s.at(0);
    }
    int right(void) {
        return m_s.at(2);
    }
    void get_all(vector<int> &vec) {
        for (int i = 0; i < 6;i++ ) {
            vec.push_back(m_s.at(i));
        }
    }
    bool equal(vector<int> vec) {
        for (int i = 0; i < 6; i++) {
            if (m_s.at(i) != vec.at(i)) return false;
        }
        return true;
    }
    bool set_top_and_before(int top, int before) {
        for (int h=0; h < 4; h++) {
        for (int i=0; i < 4; i++) {
            move('S');
            //cout << "before:" << m_s.at(1) << endl;
            if (m_s.at(1) != before) continue;
            for (int j = 0; j < 4; j++) {
                move('E');
                //cout << "top:" << m_s.at(0) << endl;
                if (m_s.at(0) == top) return true;
            }
        }
        move('E');
        }
        return false;
    }
    bool equals(Sai sai2) {
        for (int i=1; i < 6;i++) {
            bool flg = sai2.set_top_and_before(m_s.at(i-1), m_s.at(i));
            if (flg == false) continue;

            vector<int> tmp;
            sai2.get_all(tmp);
            flg = equal(tmp);
            if (flg == true) {
                //puts("Yes");
                return true;
            }
        }
        return false;
    }
};

int main() {
    int num; cin >> num;
    vector<vector<int>> n(num, vector<int>(6));
    //vector<Sai*> sais;
    Sai sais[num];

    rep(i, num) {
        rep(j, 6) cin >> n.at(i).at(j);
        sais[i].set(n.at(i));
        //sai = new Sai(n.at(i));
        //sais.push_back(sai);
    }

    for (int i = 0; i < num-1;i++) {
        for (int j = i+1; j < num;j++) {
            bool flg;
            flg = sais[i].equals(sais[j]);
            if (flg == true) {
                //printf("i=%d, j=%d\n", i, j);
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
#if 0
    vector<int> n1(6);
    rep(i, 6) cin >> n1.at(i);
    Sai sai1(n1);

    vector<int> n2(6);
    rep(i, 6) cin >> n2.at(i);
    Sai sai2(n2);
    bool flg = sai1.equals(sai2);
    cout << (flg ? "Yes" : "No") << endl;
#endif
#if 0
    for (int i=1; i < 6;i++) {
        bool flg = sai2.set_top_and_before(n1.at(i-1), n1.at(i));
        if (flg == false) continue;

        vector<int> tmp;
        sai2.get_all(tmp);
        flg = sai1.equal(tmp);
        if (flg == true) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
#endif
}



Measured memory_bytes: 3148