using System;
using System.Collections.Generic;

class program
{

    public static void Main()
    {
        var faces = new int[6];

        var n = int.Parse(Console.ReadLine());

        var dArray = new Dice[n];

        for (int i = 0; i < n; i++)
        {
            var nums = Console.ReadLine().Split(' ');
            for (var j = 0; j < 6; j++)
            {
                faces[j] = int.Parse(nums[j]);
            }

            dArray[i] = new Dice(faces);
        }

        bool flag = false;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                if (dArray[i].Equals(dArray[j]))
                {
                    flag = true;
                    break;
                }
            }
        }

        if (flag)
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }
    }
}

public class Dice
{
    public int front { get; set; }
    private int back { get; set; } // rear
    private int up { get; set; }
    private int down { get; set; }
    private int left { get; set; }
    private int right { get; set; }

    public Dice(int[] faces)
    {
        this.front = faces[0];
        this.down = faces[1];
        this.right = faces[2];
        this.left = faces[3];
        this.up = faces[4];
        this.back = faces[5];
    }

    public int findRightNum(int front, int down)
    {
        for (int i = 0; i < 5; i++)
        {
            if (front == this.front) break;

            if (i < 3) // 0..2
            {
                doE();
            }
            else if (i == 3)
            {
                doN();
            }
            else // 4
            {
                doS(); doS();
            }

        }

        for (int i = 0; i < 3; i++)
        {
            if (down == this.down) break;
            doRotateR();
        }

        return this.right;
    }

    public void next(string command)
    {
        switch (command)
        {
            case "N":
                doN();
                break;
            case "E":
                doE();
                break;
            case "S":
                doS();
                break;
            case "W":
                doW();
                break;
        }
    }

    private void doN()
    {
        var buf = this.down;
        this.down = this.back;
        this.back = this.up;
        this.up = this.front;
        this.front = buf;
    }

    private void doE()
    {
        var buf = this.left;
        this.left = this.back;
        this.back = this.right;
        this.right = this.front;
        this.front = buf;
    }

    private void doS()
    {
        var buf = this.up;
        this.up = this.back;
        this.back = this.down;
        this.down = this.front;
        this.front = buf;
    }

    private void doW()
    {
        var buf = this.right;
        this.right = this.back;
        this.back = this.left;
        this.left = this.front;
        this.front = buf;
    }

    private void doRotateR()
    {
        var buf = this.up;
        this.up = this.left;
        this.left = this.down;
        this.down = this.right;
        this.right = buf;
    }

    public bool Equals(Dice dice)
    {
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                dice.doRotateR();
                if (EqualDice(dice))
                {
                    return true;
                }
            };

            if (i < 3) // 0..2
            {
                doE();
                for (int j = 0; j < 4; j++)
                {
                    dice.doRotateR();
                    if (EqualDice(dice))
                    {
                        return true;
                    }
                };
            }
            else if (i == 3)
            {
                doN();
                for (int j = 0; j < 4; j++)
                {
                    dice.doRotateR();
                    if (EqualDice(dice))
                    {
                        return true;
                    }
                };
            }
            else // 4
            {
                doS(); doS();
                for (int j = 0; j < 4; j++)
                {
                    dice.doRotateR();
                    if (EqualDice(dice))
                    {
                        return true;
                    }
                };
            }
        }
        return false;
    }

    private bool EqualDice(Dice dice)
    {
        if (this.front == dice.front &&
            this.left == dice.left &&
            this.right == dice.right &&
            this.down == dice.down &&
            this.up == dice.up &&
            this.back == dice.back)
        {
            return true;
        }

        return false;
    }
}

Measured memory_bytes: 19676