#include <iostream>
#include <cstring>
#include <vector>

using std::vector;

class Dice
{
public:
    Dice();
    void AssignPips();
    int  GetTopPip() { return pip[0]; };
    void Roll(char dir);
    void ShowAllPip();
    int  GetRight(int top, int front);
    int  GetPip(int i) {return pip[i]; };

private:
    int pip[6];
};

int main()
{
    int n;
    std::cin>>n;
    Dice d[100];
    std::string dirs = "RRRRNRRRWRRRWRRRERRRNRRR";

    //目の取り込み
    for(int i = 0; i < n; i++)
    {
        d[i].AssignPips();
    }
    //比較する。
    for(int i = 0; i < n - 1; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            for(int k = 0; k < dirs.length(); k++)
            {
                d[i].Roll(dirs[k]);
                //std::cout<<"i = "<<i<<" j = "<<j<<dirs[k]<<std::endl;
                //d1.ShowAllPip();
                if(d[i].GetPip(0)==d[j].GetPip(0)&&
                   d[i].GetPip(1)==d[j].GetPip(1)&&
                   d[i].GetPip(2)==d[j].GetPip(2)&&
                   d[i].GetPip(3)==d[j].GetPip(3)&&
                   d[i].GetPip(4)==d[j].GetPip(4)&&
                   d[i].GetPip(5)==d[j].GetPip(5))
                {
                std::cout<<"No"<<std::endl;
                return 0;
                }
            }

        }
    }
    std::cout<<"Yes"<<std::endl;
    return 0;
}

Dice::Dice() : pip{}
{
}

void Dice::AssignPips()
{
    for(int i = 0; i < 6; i++)
    {
        std::cin>>pip[i];
    }
}

void Dice::Roll(char dir)
{
    int hoge;
    if(dir == 'N')
    {
        hoge   = pip[0];
        pip[0] = pip[1];
        pip[1] = pip[5];
        pip[5] = pip[4];
        pip[4] = hoge;
    }else if(dir == 'S')
    {
        hoge   = pip[1];
        pip[1] = pip[0];
        pip[0] = pip[4];
        pip[4] = pip[5];
        pip[5] = hoge;
    }else if(dir == 'W')
    {
        hoge = pip[0];
        pip[0] = pip[2];
        pip[2] = pip[5];
        pip[5] = pip[3];
        pip[3] = hoge;
    }else if(dir == 'E')
    {
        hoge = pip[2];
        pip[2] = pip[0];
        pip[0] = pip[3];
        pip[3] = pip[5];
        pip[5] = hoge;
    }else
    {
        hoge = pip[1];
        pip[1] = pip[2];
        pip[2] = pip[4];
        pip[4] = pip[3];
        pip[3] = hoge;

    }
}

void Dice::ShowAllPip()
{
    for(int i = 0; i < 6; i++)
    {
        std::cout<<i+1<<": "<<pip[i]<<std::endl;
    }
}

int Dice::GetRight(int top, int front)
{
    //これはもう脳みそがない人のやり方
    if(top==pip[0]&&front==pip[1]) return pip[2];
    else if(top==pip[0]&&front==pip[2])return pip[4];
    else if(top==pip[0]&&front==pip[3])return pip[1];
    else if(top==pip[0]&&front==pip[4])return pip[3];
    else if(top==pip[1]&&front==pip[0])return pip[3];
    else if(top==pip[1]&&front==pip[2])return pip[0];
    else if(top==pip[1]&&front==pip[3])return pip[5];
    else if(top==pip[1]&&front==pip[5])return pip[2];
    else if(top==pip[2]&&front==pip[0])return pip[1];
    else if(top==pip[2]&&front==pip[1])return pip[5];
    else if(top==pip[2]&&front==pip[4])return pip[0];
    else if(top==pip[2]&&front==pip[5])return pip[4];
    else if(top==pip[3]&&front==pip[0])return pip[4];
    else if(top==pip[3]&&front==pip[1])return pip[0];
    else if(top==pip[3]&&front==pip[4])return pip[5];
    else if(top==pip[3]&&front==pip[5])return pip[1];
    else if(top==pip[4]&&front==pip[0])return pip[2];
    else if(top==pip[4]&&front==pip[2])return pip[5];
    else if(top==pip[4]&&front==pip[3])return pip[0];
    else if(top==pip[4]&&front==pip[5])return pip[3];
    else if(top==pip[5]&&front==pip[1])return pip[3];
    else if(top==pip[5]&&front==pip[2])return pip[1];
    else if(top==pip[5]&&front==pip[3])return pip[4];
    else if(top==pip[5]&&front==pip[4])return pip[2];
}



Measured memory_bytes: 3204