#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

class Dice {
public:
    Dice(int i_one, int i_two, int i_three, int i_four, int i_five, int i_six)
      : one(i_one)
      , two(i_two)
      , three(i_three)
      , four(i_four)
      , five(i_five)
      , six(i_six)
    {
    }

    Dice(){}

    inline void E() noexcept
    {
        int buf_one   = this->one;
        int buf_three = this->three;
        int buf_four  = this->four;
        int buf_six   = this->six;

        this->one   = buf_four;
        this->three = buf_one;
        this->four  = buf_six;
        this->six   = buf_three;
    }

    inline void N() noexcept
    {
        int buf_one   = this->one;
        int buf_two   = this->two;
        int buf_five  = this->five;
        int buf_six   = this->six;

        this->one   = buf_two;
        this->two   = buf_six;
        this->five  = buf_one;
        this->six   = buf_five;
    }

    inline void S() noexcept
    {
        int buf_one   = this->one;
        int buf_two   = this->two;
        int buf_five  = this->five;
        int buf_six   = this->six;

        this->one   = buf_five;
        this->two   = buf_one;
        this->five  = buf_six;
        this->six   = buf_two;

    }

    inline void W() noexcept
    {
        int buf_one   = this->one;
        int buf_three = this->three;
        int buf_four  = this->four;
        int buf_six   = this->six;

        this->one   = buf_three;
        this->three = buf_six;
        this->four  = buf_one;
        this->six   = buf_four;
    }

    inline void slide() noexcept
    {
        int buf     = this->two;
        this->two   = this->four;
        this->four  = this->five;
        this->five  = this->three;
        this->three = buf;
    }

    inline bool operator ==(const Dice& dice)
    {
        if (this->one   == dice.one
         && this->two   == dice.two
         && this->three == dice.three
         && this->four  == dice.four
         && this->five  == dice.five
         && this->six   == dice.six
        ) {
            return true;
        } else {
            return false;
        }
    }

public:
    int one;
    int two;
    int three;
    int four;
    int five;
    int six;
};

bool slideTest(Dice& dice1, Dice& dice2)
{
    for (int i = 0; i < 4; ++i) {
        dice2.slide();
        if (dice1 == dice2) {
            return true;
        }
    }

    return false;
}

bool compare(Dice& dice1, Dice& dice2)
{
    if (slideTest(dice1, dice2)) {
        return true;
    }

    dice2.S();
    if (slideTest(dice1, dice2)) {
        return true;
    }

    dice2.S();
    if (slideTest(dice1, dice2)) {
        return true;
    }

    dice2.S();
    if (slideTest(dice1, dice2)) {
        return true;
    }

    dice2.S();
    dice2.W();
    if (slideTest(dice1, dice2)) {
        return true;
    }

    dice2.E();
    dice2.E();
    if (slideTest(dice1, dice2)) {
        return true;
    }

    return false;
}

int main()
{


    int n;
    std::cin >> n;

    Dice dice[n];

    for (int i = 0; i < n; ++i) {
        std::cin >> dice[i].one >> dice[i].two >> dice[i].three >> dice[i].four >> dice[i].five >> dice[i].six;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (compare(dice[i], dice[j])) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 3084