#include<iostream>
using namespace std;
#include<stdio.h>

class dice {
        private:
                int temp_t;
                int temp_e;
                int temp_s;
                int temp_b;
                int temp_w;
                int temp_n;
        public:
                int top;
                int east;
                int south;
                int bottom;
                int west;
                int north;

                void init(int _top, int _east, int _south, int _bottom, int _west, int _north);
                void roll(char dir);
                bool isexist(int x);
                bool isExistAll(dice x);
                bool isSame(dice x);
                bool ArrangeCheck(dice x);
                ~dice();
};

void dice::init(int _top, int _east, int _south, int _bottom, int _west, int _north){
        top = _top;
        east = _east;
        south = _south;
        bottom = _bottom;
        west = _west;
        north = _north;
}

void dice::roll(char dir){
        switch (dir){
                case 'N':
                        temp_n = north;
                        temp_t = top;
                        temp_s = south;
                        temp_b = bottom;
                        north = temp_t;
                        bottom = temp_n;
                        south = temp_b;
                        top = temp_s;
                        break;
                case 'S':
                        temp_n = north;
                        temp_t = top;
                        temp_s = south;
                        temp_b = bottom;
                        north = temp_b;
                        bottom = temp_s;
                        south = temp_t;
                        top = temp_n;
                        break;
                case 'E':
                        temp_e = east;
                        temp_t = top;
                        temp_w = west;
                        temp_b = bottom;
                        east = temp_t;
                        bottom = temp_e;
                        west = temp_b;
                        top = temp_w;
                        break;
                case 'W':
                        temp_e = east;
                        temp_t = top;
                        temp_w = west;
                        temp_b = bottom;
                        east = temp_b;
                        bottom = temp_w;
                        west = temp_t;
                        top = temp_e;
                        break;
                case 'R':
                        temp_e = east;
                        temp_w = west;
                        temp_n = north;
                        temp_s = south;
                        east = temp_s;
                        north = temp_e;
                        west = temp_n;
                        south = temp_w;
                        break;
                default:
                        cout << "Unknown Roll Command. Quit." << endl;
                        break;
        }
}

dice::~dice(){}

bool dice::isexist(int x) {
        if(top == x) return true;
        else if (bottom == x) return true;
        else if (east == x) return true;
        else if (west == x) return true;
        else if (north == x) return true;
        else if (south == x) return true;
        else return false;
}

bool dice::isExistAll(dice x) {
        if(isexist(x.bottom) && isexist(x.top) && isexist(x.west) && isexist(x.east) && isexist(x.north) && isexist(x.south)) return true;
        else return false;
}
bool dice::isSame(dice x) {
        if(x.top == top && x.bottom == bottom && x.east == east && x.west == west && x.north == north && x.south == south) return true;
        else return false;
}

bool dice::ArrangeCheck(dice x) {
        for(int j = 0; j < 2; j++) {
                if(top == x.north || top == x.south) x.roll('N');
                for(int i = 0; i < 3; i++) {
                    if(top == x.top && bottom == x.bottom) break;
                    x.roll('E');
                    }
                    for(int i = 0; i < 3; i++) {
                        if(south == x.south && north == x.north && east == x.east && west == x.west) break;
                        x.roll('R');
                    }
                    if(isSame(x)) break;
        }
        if(isSame(x)) return true;
        else return false;
}

int main() {
        bool r;
r = false;
        int m, T, S, E, W, N, B;
        dice myDice[100];
        cin >> m;
        for(int i = 0; i < m; i++) {
                cin >> T >> S >> E >> W >> N >> B;
                myDice[i].init(T, E, S, B, W, N);
        }
        for(int i = 0; i < m - 1; i++) {
                for(int j = i + 1; j < m; j++) {
                        if(myDice[i].ArrangeCheck(myDice[j])) {
                                r = true;
                                break;
                        }
                }
        }
        if(r == true) cout << "No" << endl;
        else cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 3096