#include<iostream>
#include<string>
using namespace std;

class dice
{
private:
    int asp[6];
    string order;
public:
    void setdice( int* j );                         //サイコロの値を格納
    void exchange( int& x, int& y );                //サイコロの場所を交換
    void orderX( string x );                        //転がす命令を行う
    void quetion( dice x );                         //2つのサイコロを可能な限り一致させる関数
    bool judge( dice a );                           //サイコロが一致しているか判定する関数

    int* d_asp(){ return asp; }                     //サイコロのアドレスを返す関数
};

void dice::setdice( int* j )
{
    for( int i = 0; i < 6; i++ )
        asp[i] = j[i];
}

void dice::exchange( int& x, int& y )
{
    int temp;
    temp = x;
    x = y;
    y = temp;
}

void dice::orderX( string x )
{

    for( int i = 0; i < x.size(); i++ )
    {

        if( x[i] == 'E' )
        {
            exchange( asp[0], asp[2] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[3] );
        }
        else if( x[i] == 'N' )
        {
            exchange( asp[0], asp[4] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[1] );
            
        }
        else if( x[i] == 'S' )
        {
            exchange( asp[0], asp[1] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[4] );
        }
        else if( x[i] == 'W' )
        {
            exchange( asp[0], asp[3] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[2] );
        }
        else if( x[i] == 'R' )
        {
            exchange( asp[1], asp[3] );
            exchange( asp[1], asp[4] );
            exchange( asp[1], asp[2] );
        }
        else{}
    }
}

void dice::quetion( dice x )
{
    int* j = x.d_asp();

    for( int i = 0; i < 3; i++ )
    {
        if( asp[0] == j[0] )
            break;
        else
            orderX("N");
    }

    for( int i = 0; i < 3; i++ )
    {
        if( asp[0] == j[0] )
            break;
        else
            orderX("E");
    }

    for( int i = 0; i < 3; i++ )
    {
        if( asp[1] == j[1] )
            break;
        else
            orderX("R");
    }

    for( int i = 0; i < 3; i++ )
    {
        if( asp[2] == j[2] )
            break;
        else
            orderX("E");
    }

    if( asp[0] != j[0] )
        return;

    for( int i = 0; i < 3; i++ )
    {
        if( asp[2] == j[2] )
            break;
        else
            orderX("R");
    }

    for( int i = 0; i < 3; i++ )
    {
        if( asp[3] == j[3] )
            break;
        else
            orderX("E");
    }

    for( int i = 0; i < 3; i++ )
    {
        if( asp[3] == j[3] )
            break;
        else
            orderX("R");
    }

    for( int i = 0; i < 3; i++ )
    {
        if( asp[4] == j[4] )
            break;
        else
            orderX("N");
    }
    for( int i = 0; i < 3; i++ )
    {
        if( asp[4] == j[4] )
            break;
        else
            orderX("R");
    }
    for( int i = 0; i < 3; i++ )
    {
        if( asp[5] == j[5] )
            break;
        else
            orderX("N");
    }
    for( int i = 0; i < 3; i++ )
    {
        if( asp[5] == j[5] )
            break;
        else
            orderX("E");
    }

}

bool dice::judge( dice a )
{
    bool flag = true;
    int* j = a.d_asp();                     //aのサイコロの配列を保持
 
    quetion( a );                           //dice aの向きに合わせて転がす

    for( int i = 0; i < 6; i++ )
    {
        if( asp[i] == j[i] )
            flag = true;
        else
        {
            flag = false;
            break;
        }
    }

    return flag;
}


int main()
{
    int n;
    bool judge;
    int d[6];

    cin >> n;

    dice dicex[n];

    for( int i = 0; i < n; i++ )                        //複数個のサイコロと面の値をセット
    {
        for( int j = 0; j < 6; j++ )       
            cin >> d[j];
        dicex[i].setdice( d );
    }

    for( int i = 0; i < n - 1; i++ )
    {
        for( int j = i + 1; j < n; j++ )
        {
            if( dicex[i].judge( dicex[j] ) )            //全てのサイコロが異なる時にYesだから
            {
                judge = false;                          //falseを入れる
                break;
            }
            else
                judge = true;
        }
        if( judge == false )
            break;
    }

    if( judge == true )                             //サイコロの一致判定
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3168