#include <iostream>
using namespace std;

void EAST(int dice[100][6], int k) {
    int copy = dice[k][0];
    dice[k][0] = dice[k][3];
    dice[k][3] = dice[k][5];
    dice[k][5] = dice[k][2];
    dice[k][2] = copy;
}

void NORTH(int dice[100][6], int k) {
    int copy = dice[k][0];
    dice[k][0] = dice[k][1];
    dice[k][1] = dice[k][5];
    dice[k][5] = dice[k][4];
    dice[k][4] = copy;
}

void ROTATE(int dice[100][6], int index, int k) {
    switch(index) {
        case 1 : break;
        case 2 : {
            int copy = dice[k][1];
            dice[k][1] = dice[k][2];
            dice[k][2] = dice[k][4];
            dice[k][4] = dice[k][3];
            dice[k][3] = copy;
            break;
        }
        case 4 : {
            int copy = dice[k][1];
            dice[k][1] = dice[k][4];
            dice[k][4] = copy;
            copy = dice[k][2];
            dice[k][2] = dice[k][3];
            dice[k][3] = copy;
            break;
        }
        case 3 : {
            int copy = dice[k][1];
            dice[k][1] = dice[k][3];
            dice[k][3] = dice[k][4];
            dice[k][4] = dice[k][2];
            dice[k][2] = copy;
            break;
        }
    }
}

int main(void) {
    int dice[100][6];
    int dice_sub[6];
    int n;

    cin >> n;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 6; ++j) {
            cin >> dice[i][j];
        }
    }

    for(int k = 1; k < n; ++k) {
        int DICE = 0;
        for(int l = 0; l < 6; ++l) {
            dice_sub[l] = dice[k][l];
        }
    
        for(int i = 0; i < 4; ++i) {
            EAST(dice, 0);
            int check = 0;
            for(int j = 0; j < 6; ++j) {
                dice[k][j] = dice_sub[j];
            }
            int start = dice[k][0];
            while(dice[k][0] != dice[0][0]) {
                EAST(dice, k);
                if(dice[k][0] == dice[0][0])   break;
                NORTH(dice, k);
                if(dice[k][0] == start) {
                    break;
                }
            }
            int index = 1;
            while(true) {
                if(dice[k][index] == dice[0][1])   break;
                ++index;
                if(index == 5) {
                    break;
                }
            }
            ROTATE(dice, index, k);
            for(int i = 0; i < 6; ++i) {
                if(dice[0][i] == dice[k][i]) {
                    ++check;
                }
            }
            if(check == 6) {
                cout << "No" << endl;
                return 0;
            }
        }
        for(int i = 0; i < 4; ++i) {
            NORTH(dice, 0);
            int check = 0;
            for(int j = 0; j < 6; ++j) {
                dice[k][j] = dice_sub[j];
            }
            int start = dice[k][0];
            while(dice[k][0] != dice[0][0]) {
                EAST(dice, k);
                if(dice[k][0] == dice[0][0])   break;
                NORTH(dice, k);
                if(dice[k][0] == start) {
                    break;
                }
            }
        
            int index = 1;
            while(true) {
                if(dice[k][index] == dice[0][1])   break;
                ++index;
                if(index == 5) {
                    break;
                }
            }
            ROTATE(dice, index, k);
            for(int i = 0; i < 6; ++i) {
                if(dice[0][i] == dice[k][i]) {
                    ++check;
                }
            }
            if(check == 6) {
                cout << "No" << endl;
            }
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}




Measured memory_bytes: 3120