#include <stdio.h>
#include <string.h>

//Structure definition-----------------------------------------------------------------------------------------
typedef struct{
  int top;
  int front;
  int right;
  int left;
  int back;
  int under;
} DICE;

//Macro--------------------------------------------------------------------------------------------------------
#define TOP   Dice.top
#define FRONT Dice.front
#define RIGHT Dice.right
#define LEFT  Dice.left
#define BACK  Dice.back
#define UNDER Dice.under

//Prototype-----------------------------------------------------------------------------------------------------
int main(void);
int dice_check(DICE, int, int, int, int, int, int, int);
DICE R_rotation(DICE);
DICE dice_rotation(DICE, char*);
DICE direction_change(char*, DICE);

//main()---------------------------------------------------------------------------------------------------------
int main(void){
    DICE Dice1;
    DICE Dice2;
    char* move_ad;
    int count = 1;  //Rotation counting variable
    int flag  = 1;
    int n = 0;      //Number of dice
    int D_array[100][6] = {0};

    scanf("%d", &n);
    D_array[n][6];

    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d %d %d %d", &D_array[i][0], &D_array[i][1], &D_array[i][2], &D_array[i][3], &D_array[i][4], &D_array[i][5]);
    }

    for (int i = 0; i < n-1; i++)
    {
        Dice1.top   = D_array[i][0];
        Dice1.front = D_array[i][1];
        Dice1.right = D_array[i][2];
        Dice1.left  = D_array[i][3];
        Dice1.back  = D_array[i][4];
        Dice1.under = D_array[i][5];

        for (int j = i+1; j < n; j++)
        {
            Dice2.top   = D_array[j][0];
            Dice2.front = D_array[j][1];
            Dice2.right = D_array[j][2];
            Dice2.left  = D_array[j][3];
            Dice2.back  = D_array[j][4];
            Dice2.under = D_array[j][5];
            count = 1;

            //Dice rotation
            while (count <= 6)
            {
                switch (count){
                    case 2:
                    case 3:
                    case 4:
                        Dice2 = R_rotation(Dice2);
                        break;
                    case 5:
                        Dice2 = R_rotation(Dice2);
                        move_ad = "N\0";
                        Dice2 = dice_rotation(Dice2, move_ad);
                        break;
                    case 6:
                        move_ad = "NN\0";
                        Dice2 = dice_rotation(Dice2, move_ad);
                        break;
                    default:
                        break;
                }

                flag = dice_check(Dice2, Dice1.top, Dice1.front, Dice1.right, Dice1.left, Dice1.back, Dice1.under, flag);

                if (!flag){
                    printf("No\n");
                    return 0;
                }
                count++;
            }
        }
    }
    printf("Yes\n");

    return 0;
}


//dice_check()----------------------------------------------------------------------------------------------------------
int dice_check(DICE Dice, int T, int F, int R, int L, int B, int U, int _flag)
{
    for (int i = 0; i < 4; i++)
    {
        if(T == TOP & F == FRONT & R == RIGHT & L == LEFT & B == BACK & U == UNDER){
            _flag = 0;
            break;
        }
        Dice = dice_rotation(Dice, "W\0");
    }

    return _flag;
}


//L_rotation()--------------------------------------------------------------------------------------------------------
DICE R_rotation(DICE Dice)
{
    int hold = FRONT;
    FRONT = RIGHT;
    RIGHT = BACK;
    BACK = LEFT;
    LEFT = hold;

    return Dice;
}

//dice_rotation()-----------------------------------------------------------------------------------------------------
DICE dice_rotation(DICE Dice, char* m_ad)
{
    char direction[3] = {};
    strcpy(direction, m_ad);

    for (int i = 0; i < strlen(direction); i++) {
        Dice = direction_change(&direction[i], Dice);
    }
    return Dice;
}


//direction_change()--------------------------------------------------------------------------------------------------
DICE direction_change(char* judge, DICE Dice){
    int hold = 0;
    switch (*judge)
    {
        case 'N':
            hold = UNDER;
            UNDER = BACK;
            BACK = TOP;
            TOP = FRONT;
            FRONT = hold;
            break;
        case 'E':
            hold = UNDER;
            UNDER = RIGHT;
            RIGHT= TOP;
            TOP = LEFT;
            LEFT = hold;
            break;
        case 'S':
            hold = UNDER;
            UNDER = FRONT;
            FRONT = TOP;
            TOP = BACK;
            BACK = hold;
            break;
        case 'W':
            hold = UNDER;
            UNDER = LEFT;
            LEFT= TOP;
            TOP = RIGHT;
            RIGHT = hold;
            break;
    }
    return Dice;
}


Measured memory_bytes: 2132