using System;
using System.Linq;
using System.Collections.Generic;
 
class Program
{
    public class Dice
    {
        public int[] Face {get; set;}
        public Dice Nua(char dir)
        {
            int[] _f = Face.Clone() as int[];
            var f = Face;
            Face = _f;
            switch (dir)
            {
                case 'N':
                {
                    Face[0] = f[1];
                    Face[1] = f[5];
                    Face[5] = f[4];
                    Face[4] = f[0];
                }
                break;
                case 'E':
                {
                    Face[2] = f[0];
                    Face[0] = f[3];
                    Face[3] = f[5];
                    Face[5] = f[2];
                }
                break;
                case 'W':
                {
                    Face[3] = f[0];
                    Face[0] = f[2];
                    Face[2] = f[5];
                    Face[5] = f[3];
                }
                break;
                case 'S':
                {
                    Face[1] = f[0];
                    Face[5] = f[1];
                    Face[4] = f[5];
                    Face[0] = f[4];
                }
                break;
            }
            _f = Face;
            Face = f;
            return new Dice { Face = _f};
        }
        public override bool Equals(Object obj) 
        {
            var o = obj as Dice;
            if (o == null)
                return false;
            return Enumerable.SequenceEqual(Face, o.Face);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
    static void Main(string[] args)
    {
        List<Dice> diceList = new List<Dice>();
        var k = 1;
        int kc;
        var c = kc = int.Parse(Console.ReadLine());
        var aadc = 625;
        for (; c > 0; c--)
        for (int i = 0; i < k; i++)
        {
            var aif = new Dice { Face = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray()};
            //5^4 = 625
            foreach (var f0 in "_NSWE")
            {
                foreach (var f1 in "_NSWE")
                {
                    foreach (var f2 in "_NSWE")
                    {
                        foreach (var f3 in "_NSWE")
                        {
                            var rolled = aif.Nua(f0).Nua(f1).Nua(f2).Nua(f3);
                            diceList.Add(rolled);
                        }
                    }
                }
            }
        }
        var bf = false;
        for (int i = 0; i < kc; i++)
        {
            var j = aadc * i;
            for (int f = 0; f < kc; f++)
            {
                if (f == i)
                {
                    continue;
                }
                for (int l = aadc * f; l < aadc * f + aadc - 1; l++)
                {
                    if (bf)
                        break;
                    if (diceList[j].Equals(diceList[l]))
                    {
                        bf = true;
                    }
                }
            }
        }
        Console.WriteLine(bf ? "No" : "Yes");
    }
}


Measured memory_bytes: 21016