using System;
using System.Collections.Generic;
using System.Linq;

namespace ITP1_11_D
{
    class Dice
    {
        //static int count = 0;
        int[] srf_current = new int[6];
        int[] srf_first = new int[6];

        public Dice(int[] x)
        {
            for (int i = 0; i < 6; i++)
                srf_current[i] = srf_first[i] = x[i];
        }

        public int this[int index]
        {
            get { return srf_current[index]; }
            set { srf_current[index] = value; }
        }

        public void turn(char vct)
        {
            int[] sub = new int[6];

            for (int i = 0; i < 6; i++)
                sub[i] = srf_current[i];

            switch (vct)
            {
                case 'S':
                    srf_current[0] = sub[4];
                    srf_current[1] = sub[0];
                    srf_current[5] = sub[1];
                    srf_current[4] = sub[5];
                    break;
                case 'N':
                    srf_current[0] = sub[1];
                    srf_current[1] = sub[5];
                    srf_current[5] = sub[4];
                    srf_current[4] = sub[0];
                    break;
                case 'W':
                    srf_current[0] = sub[2];
                    srf_current[2] = sub[5];
                    srf_current[5] = sub[3];
                    srf_current[3] = sub[0];
                    break;
                case 'E':
                    srf_current[0] = sub[3];
                    srf_current[2] = sub[0];
                    srf_current[5] = sub[2];
                    srf_current[3] = sub[5];
                    break;
                default:
                    break;
            }
            //count++;
            //foreach (var s in srf_current)
            //    Console.Write(" " + s);
            //Console.WriteLine("  " + count + " " + vct);
        }

        public void reset()
        {
            //Console.WriteLine("reset");
            for (int i = 0; i < 6; i++)
            {
                srf_current[i] = srf_first[i];
                //Console.Write(" " + srf_current[i]);
            }
            //Console.WriteLine();      
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dice d1 = new Dice(Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
            var input = new List<Dice>();
            bool isEqual = true;

            for (int i = 0; i < n - 1; i++)
            {
                Dice d = new Dice(Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
                input.Add(d);
            }
            foreach (var i in input)
            {
                for (int j = 0; j < 4; j++)
                {
                    isEqual = checkD(i, d1);
                    if (isEqual || j == 3) break;
                    else
                    {
                        i.reset();
                        for (int l = 0; l <= j; l++) i.turn('S');
                    }
                }
                if (!isEqual)
                {
                    i.reset();
                    i.turn('E');
                    i.turn('N');
                    i.turn('W');
                    isEqual = checkD(i, d1);
                }
                if (!isEqual)
                {
                    i.reset();
                    i.turn('W');
                    i.turn('N');
                    i.turn('E');
                    isEqual = checkD(i, d1);
                }
                if (isEqual) break;
            }
            if (isEqual) Console.WriteLine("No");
            else Console.WriteLine("Yes");
        }
        static bool checkD(Dice x, Dice y)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; x[j] == y[j]; j++)
                    if (j == 5)
                        return true;

                if (i == 3) break;
                else x.turn('E');
            }
            return false;
        }
    } 
}

Measured memory_bytes: 9476