#include <iostream>
#include <array>
#include <string>
#include <vector>


class Dice
{
    /*
 * Dice faces are numbered as followings
 *
 *      [N]
 * [W] [top] [E]
 *      [S]
 *
 *     [1]:top
 * [4] [2] [3] [5]:back(north)
 *     [6]:bottom
 * 
 * face_id means its potision. (e.g. face_id = top)
 * face_num means the number on a face (e.g. face_id = top; face_num = 100;)
 *
 * Notice : The index above is differnt
 *              from the index of the class member array.
 */
public:
    // {{{ constructer
    Dice() = default;
    Dice(std::array<int8_t, 6> dice_face_num) : m_dice_face_num(dice_face_num)
    {
        this->m_dice_top = 1;
        this->m_dice_north = 5;
        this->m_dice_east = 3;
    };
    // }}}
    // {{{ moveDirections
    // turn the dice to the north
    void moveNorth()
    {
        int8_t latest_top = this->m_dice_top;
        this->m_dice_top = static_cast<int8_t>(7 - this->m_dice_north);
        this->m_dice_north = latest_top;
    }

    // turn the dice to the east
    void moveEast()
    {
        int8_t latest_top = this->m_dice_top;
        this->m_dice_top = static_cast<int8_t>(7 - this->m_dice_east);
        this->m_dice_east = latest_top;
    }

    // turn the dice to the west
    void moveWest()
    {
        int8_t latest_top = this->m_dice_top;
        this->m_dice_top = this->m_dice_east;
        this->m_dice_east = static_cast<int8_t>(7 - latest_top);
    }

    // turn the dice to the south
    void moveSouth()
    {
        int8_t latest_top = this->m_dice_top;
        this->m_dice_top = this->m_dice_north;
        this->m_dice_north = static_cast<int8_t>(7 - latest_top);
    }

    void moveClockWise()
    {
        int8_t latest_east = this->m_dice_east;
        this->m_dice_east = this->m_dice_north;
        this->m_dice_north = static_cast<int8_t>(7 - latest_east);
    }

    void moveUntiClockWise()
    {
        int8_t latest_north = this->m_dice_north;
        this->m_dice_north = this->m_dice_east;
        this->m_dice_east = static_cast<int8_t>(7 - latest_north);
    }

    // }}}
    // {{{ utils
    void resetDice()
    {
        this->m_dice_top = 1;
        this->m_dice_north = 5;
        this->m_dice_east = 3;
    }
    // search face from number on the face
    int8_t faceNumtoFaceID(int8_t face_num)
    {
        bool is_already_matched = false;
        int8_t face_id = static_cast<int8_t>(127);  // 1-6
        for (int8_t i = 0; i < 6; i++) {
            if (not is_already_matched and this->m_dice_face_num.at(i) == face_num) {
                is_already_matched = true;
                face_id = static_cast<int8_t>(i + 1);
            } else if (is_already_matched and this->m_dice_face_num.at(i) == face_num) {
                //std::cerr << "error occured in function faceNumtoFaceID: two or more same numbers exist." << std::endl;
            }
        }
        if (not is_already_matched) {
            //std::cerr << "error occured in function faceNumtoFaceID" << std::endl;
        }
        return face_id;
    }
    void makeTop(int8_t face_id)
    {
        this->resetDice();
        switch (face_id) {
        case 1:
            break;
        case 2:
            this->moveNorth();
            break;
        case 3:
            this->moveWest();
            break;
        case 4:
            this->moveEast();
            break;
        case 5:
            this->moveSouth();
            break;
        case 6:
            this->moveNorth();
            this->moveNorth();
            break;
        default:
            //std::cerr << "error occured in function makeTop" << std::endl;
            break;
        }
    }

    void makeSouthIfSide(int8_t face_id)
    {
        bool is_on_side = true;
        if (face_id == this->m_dice_north) {
            this->moveClockWise();
            this->moveClockWise();
        } else if (face_id == this->m_dice_east) {
            this->moveClockWise();
        } else if (face_id == static_cast<int8_t>(7 - this->m_dice_north)) {
        } else if (face_id == static_cast<int8_t>(7 - this->m_dice_east)) {
            this->moveUntiClockWise();
        } else {
            is_on_side = false;
            //std::cerr << "error in function makeSouthIfSide. face is not on side" << std::endl;
        }
        if (not is_on_side) {
            //std::cerr << "error in function makeSouthIfSide" << std::endl;
        }
    }
    void makeFixed(int8_t top_id, int8_t south_id)
    {
        this->makeTop(top_id);
        this->makeSouthIfSide(south_id);
    }
    // }}}

    // {{{ getter
    int8_t top() { return this->m_dice_face_num.at(m_dice_top - 1); }
    int8_t bottom() { return this->m_dice_face_num.at(6 - m_dice_top); }
    int8_t east() { return this->m_dice_face_num.at(m_dice_east - 1); }
    int8_t west() { return this->m_dice_face_num.at(6 - m_dice_east); }
    int8_t north() { return this->m_dice_face_num.at(m_dice_north - 1); }
    int8_t south() { return this->m_dice_face_num.at(6 - m_dice_north); }
    std::array<int8_t, 6> faceIdsAfterRotation()
    {
        std::array<int8_t, 6> result{
            this->top(),
            this->bottom(),
            this->east(),
            this->west(),
            this->north(),
            this->south()};
        return result;
    }
    void print()
    {
        std::cerr << static_cast<int>(this->top()) << " : top  "
                  << static_cast<int>(this->south()) << " : south  "
                  << static_cast<int>(this->east()) << " : east  "
                  << static_cast<int>(this->west()) << " : west  "
                  << static_cast<int>(this->north()) << " : north  "
                  << static_cast<int>(this->bottom()) << " : bottom  "
                  << std::endl;
    }
    // }}}
private:
    std::array<int8_t, 6> m_dice_face_num;
    int8_t m_dice_top;
    int8_t m_dice_north;
    int8_t m_dice_east;
};

//{{{ Utilities
bool isTheSameDice(std::array<int8_t, 6> dice_face_num_1,
    std::array<int8_t, 6> dice_face_num_2)
{
    Dice dice_1(dice_face_num_1);
    Dice dice_2(dice_face_num_2);
    // dice_1???ID1?????¢??¨????????°?????????????????????dice_2?????¢???ID
    std::vector<int> first_num_on_second_dice;
    bool does_first_number_exist = false;
    for (int i = 0; i < 6; i++) {
        if (dice_face_num_1.at(0) == dice_face_num_2.at(i)) {
            does_first_number_exist = true;
            first_num_on_second_dice.push_back(i + 1);
        }
    }
    if (not does_first_number_exist) {
        return false;
    } else {
        bool is_the_same_dice = false;
        for (auto e : first_num_on_second_dice) {
            dice_2.makeTop(dice_2.faceNumtoFaceID(dice_face_num_2.at(e - 1)));
            dice_2.makeSouthIfSide(dice_2.faceNumtoFaceID(dice_face_num_1.at(1)));
            bool way_to_choose = true;
            for (int i = 0; i < 6; i++) {
                if (dice_1.faceIdsAfterRotation().at(i) != dice_2.faceIdsAfterRotation().at(i)) {
                    way_to_choose = false;
                }
            }
            if (way_to_choose) {
                is_the_same_dice = true;
            }
        }
        if (is_the_same_dice) {
            return true;
        } else {
            return false;
        }
    }
}
//}}}

int main()
{
    // {{{input
    int dice_num;  // how many dices there are
    std::cin >> dice_num;
    std::vector<std::array<int8_t, 6>> dice_face_numbers;
    for (int i = 0; i < dice_num; i++) {
        std::array<int, 6> input_face_num;
        for (int j = 0; j < 6; j++) {
            std::cin >> input_face_num.at(j);
        }
        std::array<int8_t, 6> dice_face_num;
        for (int j = 0; j < 6; j++) {
            dice_face_num.at(j) = static_cast<int8_t>(input_face_num.at(j));
        }
        dice_face_numbers.push_back(dice_face_num);
    }
    //}}}
    bool is_all_differnt = true;
    for (int i = 0; i < dice_num; i++) {
        for (int j = i + 1; j < dice_num; j++) {
            if (isTheSameDice(dice_face_numbers.at(i), dice_face_numbers.at(j))) {
                is_all_differnt = false;
            }
        }
    }
    if (is_all_differnt) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3112