#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

bool flag = false;

class Dice{
    public:
        void set(int num[6]);
        int get_number(int num);
        void E(), N(), S(), W();
        void lateral_rotation();
    private:
    int dice_number[6];
};

int Dice::get_number(int num){
    return dice_number[num];
}
void Dice::set(int num[6]){
    for(int i = 0; i < 6; i++) dice_number[i] = num[i];
}

void Dice::E(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[3];
    dice_number[3] = dice_number[5];
    dice_number[5] = dice_number[2];
    dice_number[2] = tmp;
}

void Dice::N(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[1];
    dice_number[1] = dice_number[5];
    dice_number[5] = dice_number[4];
    dice_number[4] = tmp;
}
void Dice::S(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[4];
    dice_number[4] = dice_number[5];
    dice_number[5] = dice_number[1];
    dice_number[1] = tmp;
}
void Dice::W(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[2];
    dice_number[2] = dice_number[5];
    dice_number[5] = dice_number[3];
    dice_number[3] = tmp;
}
void Dice::lateral_rotation(){
    int tmp = dice_number[1];
    dice_number[1] = dice_number[3];
    dice_number[3] = dice_number[4];
    dice_number[4] = dice_number[2];
    dice_number[2] = tmp;
}
bool check_dices(Dice dice1, Dice dice2){
    //全ての面が一致しているか確認する
    for(int i = 0; i < 6; i++){
        if(dice1.get_number(i) != dice2.get_number(i)){
            return false;
        }
    }
    return true;
}

//ダイス同士が同じになるか確認する
bool comparison_dices(Dice dice1, Dice dice2){
    //1が上面の時
    for (int i = 0; i < 4; i++){
        if(check_dices(dice1, dice2) == true){
            return true;
        }
        dice2.lateral_rotation();
    }

    //2が上面の時
    dice2.N();
    for (int i = 0; i < 4; i++){
        if(check_dices(dice1, dice2) == true){
            return true;
        }
        dice2.lateral_rotation();
    }

    //6
    dice2.N();
    for (int i = 0; i < 4; i++){
        if(check_dices(dice1, dice2) == true){
            return true;
        }
        dice2.lateral_rotation();
    }

    //5
    dice2.N();
    for (int i = 0; i < 4; i++){
        if(check_dices(dice1, dice2) == true){
            return true;
        }
        dice2.lateral_rotation();
    }

    //3
    dice2.W();
    for (int i = 0; i < 4; i++){
        if(check_dices(dice1, dice2) == true){
            return true;
        }
        dice2.lateral_rotation();
    }

    //4
    dice2.E();
    dice2.E();
    for (int i = 0; i < 4; i++){
        if(check_dices(dice1, dice2) == true){
            return true;
        }
        dice2.lateral_rotation();
    }
    return false;
}

int main(){
    Dice dices[100];
    int n, dice_num[6];
    char order[100];
    //サイコロの数を入力
    cin >> n;
    //サイコロをn回入力
    for(int i = 0; i < n; i++){
        for (int j = 0; j < 6; j++ ) cin >> dice_num[j];
        dices[i].set( dice_num );
    }

    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            if(comparison_dices(dices[i], dices[j]) == true){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3080