#include <bits/stdc++.h>
using namespace std;

vector<int> rolledDice(char, vector<int>);

multiset<pair<int, int>> makeDistinctPairs(vector<int>);

bool isEquivalentTwoDices(vector<int>, vector<int>);

bool isEquivalentTwoDicesAsSets(vector<int>, vector<int>);

/* 0: t, 1: s, 2: e, 3: w, 4: n, 5: b */
int main()
{
    int n;
    cin >> n;

    vector<int> dice(6, 0);
    vector<vector<int>> dices(n, dice);

    for (int i = 0; i < n; i++)
    {
        for (int l = 0; l < 6; l++)
        {
            cin >> dices[i][l];
        }
    }

    vector<multiset<pair<int, int>>> distinctPairs; // 互いに等しいラベルの連中をゴソッと取り除いた集合
    for (int i = 0; i < n; i++)
    {
        distinctPairs.push_back(makeDistinctPairs(dices[i]));
    }

    // 色数分類
    // vector<bool> two_colors(n, false), three_colors(n, false);
    for (int i = 0; i < n; i++)
    {
        if (distinctPairs[i].size() > 9)
        {
            // three_colors[i] = true;
            if (dices[i][0] == dices[i][1] && dices[i][1] == dices[i][2])
            {
                dices[i] = rolledDice('N', dices[i]); // (0, 1, 2)面から一意に配位を確定させる
            }
        }
        else
        {
            // two_colors[i] = true;
        }
    }

    int equivs = n * (n - 1) / 2;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (isEquivalentTwoDicesAsSets(dices[i], dices[j]) == false)
            {
                equivs--;
            }
            else if (isEquivalentTwoDices(dices[i], dices[j]) == false)
            {
                equivs--;
            }
            else
            {
                break;
            }
        }
    }

    // cout << equivs << endl;
    // return 0;

    if (equivs == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

bool isEquivalentTwoDicesAsSets(vector<int> testingDice, vector<int> dice)
{
    multiset<int> a, b, res;

    for (int i = 0; i < 6; i++)
    {
        a.insert(testingDice[i]);
        b.insert(dice[i]);
    }

    set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(res, res.end()));

    return (a == res);
}

bool isEquivalentTwoDices(vector<int> testingDice, vector<int> dice)
{
    if (testingDice[2] == dice[1])
    {
        testingDice = rolledDice('W', testingDice);
        testingDice = rolledDice('S', testingDice);
    }
    else if (testingDice[3] == dice[1])
    {
        testingDice = rolledDice('E', testingDice);
        testingDice = rolledDice('S', testingDice);
    }
    else
    {
        while (testingDice[1] != dice[1])
        {
            testingDice = rolledDice('N', testingDice);
        }
    }

    if (testingDice[4] != dice[0])
    {
        while (testingDice[0] != dice[0])
        {
            testingDice = rolledDice('E', testingDice);
        }
    }

    return (testingDice == dice);
}

vector<int> rolledDice(char direction, vector<int> olddice)
{
    vector<int> newdice = olddice;
    if (direction == 'N')
    {
        // cout << "rolling to " << direction << endl;
        newdice[0] = olddice[1];
        newdice[1] = olddice[5];
        newdice[5] = olddice[4];
        newdice[4] = olddice[0];
    }
    else if (direction == 'S')
    {
        // cout << "rolling to " << direction << endl;
        newdice[0] = olddice[4];
        newdice[4] = olddice[5];
        newdice[5] = olddice[1];
        newdice[1] = olddice[0];
    }
    else if (direction == 'E')
    {
        // cout << "rolling to " << direction << endl;
        newdice[0] = olddice[3];
        newdice[3] = olddice[5];
        newdice[5] = olddice[2];
        newdice[2] = olddice[0];
    }
    else if (direction == 'W')
    {
        // cout << "rolling to " << direction << endl;
        newdice[0] = olddice[2];
        newdice[2] = olddice[5];
        newdice[5] = olddice[3];
        newdice[3] = olddice[0];
    }
    return newdice;
}

multiset<pair<int, int>> makeDistinctPairs(vector<int> dice)
{
    multiset<pair<int, int>> res; // 互いに等しいラベルの連中をゴソッと取り除いた集合
    for (int i = 0; i < 6; i++)
    {
        for (int j = i + 1; j < 6; j++)
        {
            res.insert(make_pair(dice[i], dice[j]));
        }
    }
    for (int i = 0; i < 6; i++)
    {
        for (int j = i + 1; j < 6; j++)
        {
            if (dice[i] == dice[j])
            {
                res.erase(make_pair(dice[i], dice[j]));
            }
        }
    }

    return res;
}


Measured memory_bytes: 3220