using System;

namespace ITP1_11_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);
            Dice[] dice = new Dice[n];

            for(int i = 0; i < n; ++i)
            {
                string[] str1 = Console.ReadLine().Split(' ');
                dice[i] = new Dice(int.Parse(str1[0]), int.Parse(str1[1]), int.Parse(str1[2]), int.Parse(str1[3]), int.Parse(str1[4]), int.Parse(str1[5]));
            }

            string Ans = "Yes";
            for(int i = 1; i<n;++i)
            {
                if (allCheckSame(dice[0], dice[i])) { Ans = "No"; }
            }

            Console.WriteLine(Ans); 
        }

        static bool checkSame(Dice dice1, Dice dice2)
        {
            return (true
                && dice1.TopPip == dice2.TopPip
                && dice1.NorthPip == dice2.NorthPip
                && dice1.SouthPip == dice2.SouthPip
                && dice1.WestPip == dice2.WestPip
                && dice1.EastPip == dice2.EastPip
                && dice1.BottomPip == dice2.BottomPip
                );
        }

        static bool revolveCheckSame(Dice dice1, Dice dice2)
        {
            for (int i = 0; i < 4; ++i)
            {
                if (checkSame(dice1, dice2)) { return true; }
                dice2.RevolveLeft();
            }
            return false;
        }

        static bool allCheckSame(Dice dice1, Dice dice2)
        {
            if (revolveCheckSame(dice1, dice2)) { return true; }

            dice2.MoveEast();
            if (revolveCheckSame(dice1, dice2)) { return true; }
            dice2.MoveWest();

            dice2.MoveNorth();
            if (revolveCheckSame(dice1, dice2)) { return true; }
            dice2.MoveSouth();

            dice2.MoveSouth();
            if (revolveCheckSame(dice1, dice2)) { return true; }
            dice2.MoveNorth();

            dice2.MoveWest();
            if (revolveCheckSame(dice1, dice2)) { return true; }

            dice2.MoveWest();
            if (revolveCheckSame(dice1, dice2)) { return true; }

            return false;
        }
    }

    class Dice
    {
        public int TopPip { get; private set; }
        public int SouthPip { get; private set; }
        public int EastPip { get; private set; }
        public int WestPip { get; private set; }
        public int NorthPip { get; private set; }
        public int BottomPip { get; private set; }

        public Dice(int topPip, int southPip, int eastPip, int westPip, int northPip, int bottomPip)
        {
            this.TopPip = topPip;
            this.SouthPip = southPip;
            this.EastPip = eastPip;
            this.WestPip = westPip;
            this.NorthPip = northPip;
            this.BottomPip = bottomPip;
        }

        public Dice(Dice dice)
        {
            this.TopPip = dice.TopPip;
            this.SouthPip = dice.SouthPip;
            this.EastPip = dice.EastPip;
            this.WestPip = dice.WestPip;
            this.NorthPip = dice.NorthPip;
            this.BottomPip = dice.BottomPip;
        }

        public void MoveNorth()
        {
            int temp = this.NorthPip;
            this.NorthPip = this.TopPip;
            this.TopPip = this.SouthPip;
            this.SouthPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void MoveSouth()
        {
            int temp = this.SouthPip;
            this.SouthPip = this.TopPip;
            this.TopPip = this.NorthPip;
            this.NorthPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void MoveWest()
        {
            int temp = this.WestPip;
            this.WestPip = this.TopPip;
            this.TopPip = this.EastPip;
            this.EastPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void MoveEast()
        {
            int temp = this.EastPip;
            this.EastPip = this.TopPip;
            this.TopPip = this.WestPip;
            this.WestPip = this.BottomPip;
            this.BottomPip = temp;
        }

        public void RevolveLeft()
        {
            int temp = this.SouthPip;
            this.SouthPip = this.EastPip;
            this.EastPip = this.NorthPip;
            this.NorthPip = this.WestPip;
            this.WestPip = temp;
        }
    }
}

Measured memory_bytes: 5344