using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var labels = new int[num][];
            for (int i = 0; i < labels.Length; i++)
            {
                labels[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            }

            const string Yes = "Yes";
            const string No = "No";
            for (int y = 0; y < labels.Length-1; y++)
            {
                var diceY = new Dice(labels[y]);
                for (int x = y+1; x < labels.Length; x++)
                {
                    var diceX = new Dice(labels[x]);
                    if (DiceEquals(diceY, diceX))
                    {
                        Console.WriteLine(No);
                        return;
                    }
                }
            }
            Console.WriteLine(Yes);
            
        }

        private static bool DiceEquals(Dice diceA, Dice diceB)
        {
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    for (int z = 0; z < 4; z++)
                    {
                        if (Dice.ValueEquals(diceA, diceB))
                        {
                            return true;
                        }
                        diceB.RollZ(true);
                    }
                    diceB.RollY(true);
                }
                diceB.RollX(true);
            }
            return false;
        }
        
    }

    class Dice
    {
        public int Front { get; private set; }
        public int Bottom { get; private set; }
        public int Right { get; private set; }
        public int Left { get; private set; }
        public int Top { get; private set; }
        public int Rear { get; private set; }

        public Dice(int[] label)
        {
            Front = label[0];
            Bottom = label[1];
            Right = label[2];
            Left = label[3];
            Top = label[4];
            Rear = label[5];
        }

        public void RollX(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Left;
                Left = Rear;
                Rear = Right;
                Right = temp;
            }
            else
            {
                temp = Front;
                Front = Right;
                Right = Rear;
                Rear = Left;
                Left = temp;
            }
        }
        public void RollY(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Bottom;
                Bottom = Rear;
                Rear = Top;
                Top = temp;
            }
            else
            {
                temp = Front;
                Front = Top;
                Top = Rear;
                Rear = Bottom;
                Bottom = temp;
            }
        }
        public void RollZ(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Top;
                Top = Left;
                Left = Bottom;
                Bottom = Right;
                Right = temp;
            }
            else
            {
                temp = Top;
                Top = Right;
                Right = Bottom;
                Bottom = Left;
                Left = temp;
            }
        }
        static public bool ValueEquals(Dice a, Dice b)
        {
            if (a.Front != b.Front) return false;
            else if (a.Bottom != b.Bottom) return false;
            else if (a.Right != b.Right) return false;
            else if (a.Left != b.Left) return false;
            else if (a.Top != b.Top) return false;
            else if (a.Rear != b.Rear) return false;
            else return true;
        }
    }
}

Measured memory_bytes: 5508