using System;
using System.Collections.Generic;
using System.Globalization;

enum direction { north, east, west, south }
class dice{
    public int[] number;

    public int me;
    public dice[] east;
    public dice[] north;
    public dice[] south;
    public dice[] west;
    public int[,] direction;
};




class Program
 {
    static public bool match(int dice1, int dice2, dice[] face,int dice3,int dice4 )
    {
        int[] opsit = new int[7];
        opsit[1] = 6;
        opsit[2] = 5;
        opsit[3] = 4;
        opsit[4] = 3;
        opsit[5] = 2;
        opsit[6] = 1;
        if ((face[dice1].north[0].number[dice3] == face[dice2].north[0].number[dice4] &
            face[dice1].east[0].number[dice3] == face[dice2].east[0].number[dice4] &
            face[dice1].west[0].number[dice3] == face[dice2].west[0].number[dice4] &
            face[dice1].south[0].number[dice3] == face[dice2].south[0].number[dice4] &
            face[opsit[dice1]].number[dice3] == face[opsit[dice2]].number[dice4] ) |
            (face[dice1].north[0].number[dice3] == face[dice2].north[1].number[dice4] &
            face[dice1].east[0].number[dice3] == face[dice2].east[1].number[dice4] &
            face[dice1].west[0].number[dice3] == face[dice2].west[1].number[dice4] &
            face[dice1].south[0].number[dice3] == face[dice2].south[1].number[dice4] &
            face[opsit[dice1]].number[dice3] == face[opsit[dice2]].number[dice4]) |
            (face[dice1].north[0].number[dice3] == face[dice2].north[2].number[dice4] &
            face[dice1].east[0].number[dice3] == face[dice2].east[2].number[dice4] &
            face[dice1].west[0].number[dice3] == face[dice2].west[2].number[dice4] &
            face[dice1].south[0].number[dice3] == face[dice2].south[2].number[dice4] &
            face[opsit[dice1]].number[dice3] == face[opsit[dice2]].number[dice4]) |
            (face[dice1].north[0].number[dice3] == face[dice2].north[3].number[dice4] &
            face[dice1].east[0].number[dice3] == face[dice2].east[3].number[dice4] &
            face[dice1].west[0].number[dice3] == face[dice2].west[3].number[dice4] &
            face[dice1].south[0].number[dice3] == face[dice2].south[3].number[dice4] &
            face[opsit[dice1]].number[dice3] == face[opsit[dice2]].number[dice4])

            ) return true;
        else return false;
    }

    static void Main(string[] args)
    {
        string nyuryoku;
        dice[] face = new dice[7];
        string [] temp = new string[6];
        for (int i = 1; i < 7; i++)
        {
            face[i] = new dice();
            face[i].east = new dice[4];
            face[i].west = new dice[4];
            face[i].north = new dice[4];
            face[i].south = new dice[4];
            face[i].direction = new int[4,4];
            face[i].me = i;
        }

        face[1].east[0] = face[4];
        face[1].direction[0, 1] = 1;
        face[1].north[0] = face[2];
        face[1].direction[0, 0] = 0;
        face[1].west[0] = face[3];
        face[1].direction[0, 3] = 3;
        face[1].south[0] = face[5];
        face[1].direction[0, 2] = 2;

        face[1].east[1] = face[2];
        face[1].direction[1, 1] = 1;
        face[1].north[1] = face[3];
        face[1].direction[1, 0] = 0;
        face[1].west[1] = face[5];
        face[1].direction[1, 3] = 3;
        face[1].south[1] = face[4];
        face[1].direction[1, 2] = 2;

        face[1].east[2] = face[3];
        face[1].direction[2, 1] = 1;
        face[1].north[2] = face[5];
        face[1].direction[2, 0] = 0;
        face[1].west[2] = face[4];
        face[1].direction[2, 3] = 3;
        face[1].south[2] = face[2];
        face[1].direction[2, 2] = 2;

        face[1].east[3] = face[5];
        face[1].direction[3, 1] = 1;
        face[1].north[3] = face[4];
        face[1].direction[3, 0] = 0;
        face[1].west[3] = face[2];
        face[1].direction[3, 3] = 3;
        face[1].south[3] = face[3];
        face[1].direction[3, 2] = 2;
//--------------------------------------
        face[2].east[0] = face[4];
        face[2].direction[0, 1] = 0;
        face[2].north[0] = face[6];
        face[2].direction[0, 0] = 0;
        face[2].west[0] = face[3];
        face[2].direction[0, 3] = 0;
        face[2].south[0] = face[1];
        face[2].direction[0, 2] = 0;

        face[2].east[1] = face[6];
        face[2].direction[1, 1] = 1;
        face[2].north[1] = face[3];
        face[2].direction[1, 0] = 1;
        face[2].west[1] = face[1];
        face[2].direction[1, 3] = 1;
        face[2].south[1] = face[4];
        face[2].direction[1, 2] = 1;

        face[2].east[2] = face[3];
        face[2].direction[2, 1] = 2;
        face[2].north[2] = face[1];
        face[2].direction[2, 0] = 2;
        face[2].west[2] = face[4];
        face[2].direction[2, 3] = 2;
        face[2].south[2] = face[6];
        face[2].direction[2, 2] = 2;

        face[2].east[3] = face[1];
        face[2].direction[3, 1] = 3;
        face[2].north[3] = face[4];
        face[2].direction[3, 0] = 3;
        face[2].west[3] = face[6];
        face[2].direction[3, 3] = 3;
        face[2].south[3] = face[3];
        face[2].direction[3, 2] = 3;
//--------------------------------------
        face[3].east[0] = face[2];
        face[3].direction[0, 1] = 0;
        face[3].north[0] = face[6];
        face[3].direction[0, 0] = 3;
        face[3].west[0] = face[5];
        face[3].direction[0, 3] = 0;
        face[3].south[0] = face[1];
        face[3].direction[0, 2] = 1;

        face[3].east[1] = face[6];
        face[3].direction[1, 1] = 0;
        face[3].north[1] = face[5];
        face[3].direction[1, 0] = 1;
        face[3].west[1] = face[1];
        face[3].direction[1, 3] = 2;
        face[3].south[1] = face[2];
        face[3].direction[1, 2] = 1;

        face[3].east[2] = face[5];
        face[3].direction[2, 1] = 2;
        face[3].north[2] = face[1];
        face[3].direction[2, 0] = 3;
        face[3].west[2] = face[2];
        face[3].direction[2, 3] = 2;
        face[3].south[2] = face[6];
        face[3].direction[2, 2] = 1;

        face[3].east[3] = face[1];
        face[3].direction[3, 1] = 0;
        face[3].north[3] = face[2];
        face[3].direction[3, 0] = 3;
        face[3].west[3] = face[6];
        face[3].direction[3, 3] = 2;
        face[3].south[3] = face[5];
        face[3].direction[3, 2] = 3;
//-------------------------------------
        face[4].east[0] = face[5];
        face[4].direction[0, 1] = 0;
        face[4].north[0] = face[6];
        face[4].direction[0, 0] = 1;
        face[4].west[0] = face[2];
        face[4].direction[0, 3] = 0;
        face[4].south[0] = face[1];
        face[4].direction[0, 2] = 3;

        face[4].east[1] = face[6];
        face[4].direction[1, 1] = 2;
        face[4].north[1] = face[2];
        face[4].direction[1, 0] = 1;
        face[4].west[1] = face[1];
        face[4].direction[1, 3] = 0;
        face[4].south[1] = face[5];
        face[4].direction[1, 2] = 1;

        face[4].east[2] = face[2];
        face[4].direction[2, 1] = 2;
        face[4].north[2] = face[1];
        face[4].direction[2, 0] = 1;
        face[4].west[2] = face[5];
        face[4].direction[2, 3] = 2;
        face[4].south[2] = face[6];
        face[4].direction[2, 2] = 3;

        face[4].east[3] = face[1];
        face[4].direction[3, 1] = 2;
        face[4].north[3] = face[5];
        face[4].direction[3, 0] = 3;
        face[4].west[3] = face[6];
        face[4].direction[3, 3] = 0;
        face[4].south[3] = face[2];
        face[4].direction[3, 2] = 3;
//------------------------------------
        face[5].east[0] = face[3];
        face[5].direction[0, 1] = 0;
        face[5].north[0] = face[6];
        face[5].direction[0, 0] = 2;
        face[5].west[0] = face[4];
        face[5].direction[0, 3] = 0;
        face[5].south[0] = face[1];
        face[5].direction[0, 2] = 2;

        face[5].east[1] = face[6];
        face[5].direction[1, 1] = 3;
        face[5].north[1] = face[4];
        face[5].direction[1, 0] = 1;
        face[5].west[1] = face[1];
        face[5].direction[1, 3] = 3;
        face[5].south[1] = face[3];
        face[5].direction[1, 2] = 1;

        face[5].east[2] = face[4];
        face[5].direction[2, 1] = 2;
        face[5].north[2] = face[1];
        face[5].direction[2, 0] = 0;
        face[5].west[2] = face[3];
        face[5].direction[2, 3] = 2;
        face[5].south[2] = face[6];
        face[5].direction[2, 2] = 0;

        face[5].east[3] = face[1];
        face[5].direction[3, 1] = 1;
        face[5].north[3] = face[3];
        face[5].direction[3, 0] = 3;
        face[5].west[3] = face[6];
        face[5].direction[3, 3] = 1;
        face[5].south[3] = face[4];
        face[5].direction[3, 2] = 3;
//-----------------------------------
        face[6].east[0] = face[4];
        face[6].direction[0, 1] = 3;
        face[6].north[0] = face[5];
        face[6].direction[0, 0] = 2;
        face[6].west[0] = face[3];
        face[6].direction[0, 3] = 1;
        face[6].south[0] = face[2];
        face[6].direction[0, 2] = 0;

        face[6].east[1] = face[5];
        face[6].direction[1, 1] = 3;
        face[6].north[1] = face[3];
        face[6].direction[1, 0] = 2;
        face[6].west[1] = face[2];
        face[6].direction[1, 3] = 1;
        face[6].south[1] = face[4];
        face[6].direction[1, 2] = 0;

        face[6].east[2] = face[3];
        face[6].direction[2, 1] = 3;
        face[6].north[2] = face[2];
        face[6].direction[2, 0] = 2;
        face[6].west[2] = face[4];
        face[6].direction[2, 3] = 1;
        face[6].south[2] = face[5];
        face[6].direction[2, 2] = 0;

        face[6].east[3] = face[2];
        face[6].direction[3, 1] = 3;
        face[6].north[3] = face[4];
        face[6].direction[3, 0] = 2;
        face[6].west[3] = face[5];
        face[6].direction[3, 3] = 1;
        face[6].south[3] = face[3];
        face[6].direction[3, 2] = 0;
//----------------------------------------
//----------------------------------------

        nyuryoku = Console.ReadLine();
        int number;
        number = int.Parse(nyuryoku);

        for (int i = 1; i < 7; i++)
        {
            face[i].number = new int[number+1];
        }
        for (int i = 1; i <= number; i++)
        {
            nyuryoku = Console.ReadLine();
            temp = nyuryoku.Split(' ');
            for(int j = 1; j < 7; j++ )
                face[j].number[i] = int.Parse(temp[j-1]);
        }


        for (int i = 1; i <= number; i++)
            for (int j = i+1; j <= number; j++)
            {
                for(int k = 1;k < 7;k++)
                {
                    if (face[1].number[i] == face[k].number[j])
                    {
                    if (match(1,k,face,i,j))
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }

            }
  
        }
                    Console.WriteLine("Yes");

    }
 }



Measured memory_bytes: 20016