#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

class Dice
{
public:
    int number[6];
    void setLabel(int index, int num)
    {
        number[index] = num;
    };

    void roll(char dst)
    {
        switch (dst)
        {
        case 'E':
            setNumber(number[3], number[1], number[0], number[5], number[4], number[2]);
            break;
        case 'S':
            setNumber(number[4], number[0], number[2], number[3], number[5], number[1]);
            break;
        case 'W':
            setNumber(number[2], number[1], number[5], number[0], number[4], number[3]);
            break;
        case 'N':
            setNumber(number[1], number[5], number[2], number[3], number[0], number[4]);
            break;

        default:
            break;
        }
    };
    int showPeek()
    {
        return number[0];
    };
    int showRight()
    {
        return number[2];
    };
    int showFront()
    {
        return number[1];
    };
    int showleft()
    {
        return number[3];
    };
    int showBack()
    {
        return number[4];
    };
    int showBottom()
    {
        return number[5];
    }
    int searchRight(int front, int peek)
    {
        int Ans = -1;
        repi(i, 8, 0)
        {
            if (number[1] == front && number[0] == peek)
            {
                Ans = number[2];
            }
            else if (number[2] == front && number[0] == peek)
            {
                Ans = number[4];
            }
            else if (number[4] == front && number[0] == peek)
            {
                Ans = number[3];
            }
            else if (number[3] == front && number[0] == peek)
            {
                Ans = number[1];
            }
            if (i >= 4)
            {
                roll('E');
            }
            else
            {
                roll('N');
            }
        }
        return Ans;
    };
    bool compare(Dice dice)
    {
        bool state = false;
        string order = "NNNNWNNNWNNNENNNENNNWNNN";
        repi(j, order.length(), 0)
        {
            roll(order.at(j));
            ll front = dice.showFront(), peek = dice.showPeek(), right = dice.showRight(), left = dice.showleft(), back = dice.showBack(), bottom = dice.showBottom();
            if (front == showFront() &&
                peek == showPeek() &&
                right == showRight() &&
                left == showleft() &&
                back == showBack() &&
                bottom == showBottom())
            {
                state = true;
            }
        }
        return state;
    };

private:
    void setNumber(int n0, int n1, int n2, int n3, int n4, int n5)
    {
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    };
};

int main()
{
    ll n;
    cin >> n;
    Dice dices[n];
    repi(i, n, 0)
    {
        repi(j, 6, 0)
        {
            int tmp;
            cin >> tmp;
            dices[i].setLabel(j, tmp);
        }
    }
    bool state = true;
    repi(i, n, 0)
    {
        repi(j, n, i + 1)
        {
            if (i == j)
                continue;
            state = dices[i].compare(dices[j]);
            if (state)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3220