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

typedef struct
{
        int top;
        int south_side;
        int east_side;
        int west_side;
        int north_side;
        int bottom;
} Dice;

Dice operation_right_rotation_from_topside( Dice dice_tmp )
{
        int tmp = dice_tmp.south_side;
        dice_tmp.south_side = dice_tmp.east_side;
        dice_tmp.east_side = dice_tmp.north_side;
        dice_tmp.north_side = dice_tmp.west_side;
        dice_tmp.west_side = tmp;
        return dice_tmp;
}

Dice change_top_to_northside( Dice dice_tmp )
{
        int tmp = dice_tmp.top;
        dice_tmp.top = dice_tmp.north_side;
        dice_tmp.north_side = dice_tmp.bottom;
        dice_tmp.bottom =  dice_tmp.south_side;
        dice_tmp.south_side = tmp;
        return dice_tmp;
}

Dice change_top_to_southside( Dice dice_tmp )
{
        int tmp = dice_tmp.top;
        dice_tmp.top = dice_tmp.south_side;
        dice_tmp.south_side = dice_tmp.bottom;
        dice_tmp.bottom = dice_tmp.north_side;
        dice_tmp.north_side = tmp;
        return dice_tmp;
}

Dice change_top_to_westside( Dice dice_tmp )
{
        int tmp = dice_tmp.top;
        dice_tmp.top = dice_tmp.west_side;
        dice_tmp.west_side = dice_tmp.bottom;
        dice_tmp.bottom = dice_tmp.east_side;
        dice_tmp.east_side = tmp;
        return dice_tmp;
}

Dice change_top_to_eastside( Dice dice_tmp )
{
        int tmp = dice_tmp.top;
        dice_tmp.top = dice_tmp.east_side;
        dice_tmp.east_side = dice_tmp.bottom;
        dice_tmp.bottom = dice_tmp.west_side;
        dice_tmp.west_side = tmp;
        return dice_tmp;
}

Dice change_top_to_bottom( Dice dice_tmp )
{
        int tmp = dice_tmp.top;
        dice_tmp.top = dice_tmp.bottom;
        dice_tmp.bottom = tmp;

        tmp = dice_tmp.west_side;
        dice_tmp.west_side = dice_tmp.east_side;
        dice_tmp.east_side = tmp;
        return dice_tmp;
}

int compare( Dice dice, Dice dice1 )
{
        if (
                        ( dice.top == dice1.top ) && ( dice.bottom == dice1.bottom ) &&
                        ( dice.north_side == dice1.north_side ) && ( dice.south_side == dice1.south_side) &&
                        ( dice.west_side == dice1.west_side ) && ( dice.east_side == dice1.east_side )
                )
        {
                return 1;
        }

        return 0;
}
int main()
{
        Dice dice[100], tmp;
        int eq_flag = 0, count = 0, change_count = 0, dice_number = 0, rotatio_count = 0, count_in = 0;

        scanf("%d", &dice_number);
        while ( count < dice_number )
        {
                scanf("%d %d %d %d %d %d", &dice[count].top, &dice[count].south_side,
                                &dice[count].east_side, &dice[count].west_side,
                                &dice[count].north_side, &dice[count].bottom);
                count = count + 1;
        }

        count = 0;
        while (  count < dice_number - 1 )
        {
                count_in = count + 1;
                while ( count_in < dice_number ){
                        change_count = 0;
                        while ( change_count < 6 )
                        {
                                tmp = dice[count];
                                if ( change_count == 1 )
                                {
                                        tmp = change_top_to_bottom( dice[count] );
                                }
                                else if ( change_count == 2 )
                                {
                                        tmp = change_top_to_northside( dice[count] );
                                }
                                else if ( change_count == 3 )
                                {
                                        tmp = change_top_to_southside( dice[count] );
                                }
                                else if ( change_count == 4 )
                                {
                                        tmp = change_top_to_westside( dice[count] );
                                }
                                else if ( change_count == 5 )
                                {
                                        tmp = change_top_to_eastside( dice[count] );
                                }
                                                /*printf("-------------------------------------------------------\n");
                                                printf(" dice[%d]   %d %d %d %d %d %d\n",count, tmp.top, tmp.south_side,
                                                                tmp.east_side, tmp.west_side, tmp.north_side, tmp.bottom);
                                                printf(" dice[%d]  %d %d %d %d %d %d\n", count_in, dice[count_in].top, dice[count_in].south_side,
                                                                dice[count_in].east_side, dice[count_in].west_side, dice[count_in].north_side, dice[count_in].bottom);
*/
                                rotatio_count = 0;
                                while ( rotatio_count < 4 )
                                {
                                        if ( compare( dice[count_in], tmp ) == 1 )
                                        {
                                        /*      printf("-------------------------------------------------------\n");
                                                printf(" dice[%d]   %d %d %d %d %d %d\n",count, tmp.top, tmp.south_side,
                                                                tmp.east_side, tmp.west_side, tmp.north_side, tmp.bottom);
                                                printf(" dice[count_in][%d]  %d %d %d %d %d %d\n", count_in, dice[count_in].top, dice[count_in].south_side,
                                                                dice[count_in].east_side, dice[count_in].west_side, dice[count_in].north_side, dice[count_in].bottom);
                                                */eq_flag = 1;
                                                break;
                                        }
                                        tmp = operation_right_rotation_from_topside( tmp );
                                        rotatio_count = rotatio_count + 1;
                                }
                                change_count = change_count + 1;
                        }
                        count_in = count_in + 1;
                }
                if ( eq_flag == 1 ) break;
                count = count + 1;;
        }

        if ( eq_flag == 1 )
        {
                printf("No\n");
        }
        else
        {
                printf("Yes\n");
        }

        return 0;
}

Measured memory_bytes: 580