#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
*/

using namespace std;

class Dice
{
  public:
    int s[10];

    void roll(char dir)
    {
        int tmp[10];
        memcpy(tmp, s, sizeof(int) * 10);
        switch (dir)

        {
        case 'N':
            s[1] = tmp[2];
            s[2] = tmp[6];
            s[6] = tmp[5];
            s[5] = tmp[1];
            break;
        case 'E':
            s[1] = tmp[4];
            s[4] = tmp[6];
            s[6] = tmp[3];
            s[3] = tmp[1];
            break;
        case 'W':
            s[1] = tmp[3];
            s[3] = tmp[6];
            s[6] = tmp[4];
            s[4] = tmp[1];
            break;
        case 'S':
            s[1] = tmp[5];
            s[5] = tmp[6];
            s[6] = tmp[2];
            s[2] = tmp[1];
            break;
        case 'R':
            s[2] = tmp[3];
            s[3] = tmp[5];
            s[5] = tmp[4];
            s[4] = tmp[2];
            break;
        }
        return;
    }
    void roll(int x)
    {
        switch (x)
        {
        case 1:
            break;
        case 2:
            roll('N');
            break;
        case 3:
            roll('W');
            break;
        case 4:
            roll('E');
            break;
        case 5:
            roll('S');
            break;
        case 6:
            roll('N');
            roll('N');
            break;
        }
        return;
    }
    void print()
    {
        cout << "   " << s[1] << "    " << endl
             << " " << s[4] << " " << s[2] << " " << s[3] << " " << s[5] << endl
             << "   " << s[6] << "    " << endl
             << endl;
    }
};

bool equal(Dice d1, Dice d2)
{
    for (int i = 1; i <= 6; i++)
        if (d1.s[i] != d2.s[i])
            return false;
    return true;
}

bool same(Dice d1, Dice d2)
{
    Dice tmp = d1;

    for (int i = 1; i <= 6; i++)
    {
        d1 = tmp;
        d1.roll(i);
        for (int i = 0; i < 4; i++)
        {
            d1.roll('R');

            if (equal(d1, d2))
                return true;
        }
    }
    return false;
}

int main()
{
    bool ans = true;

    int n;
    cin >> n;

    Dice d[105];
    for (int i = 0; i < n;i++){
        for (int j = 1; j <= 6; j++)
            cin >> d[i].s[j];
    }

    for (int i = 0; i < n - 1 && ans; i++)
    {
        for (int j = i + 1; j < n && ans; j++)
        {
            if (same(d[i], d[j])){
                ans = false;
                //cout << "There is same " << i + 1 << " , " << j + 1 << endl;
            }
        }
    }

    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3072