#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int line[3][4] = {{1,2,4,3},{0,3,5,2},{0,1,5,4}}; 

struct dice {
	int f2n[6];
};

bool check_equal_dice(dice& d1, dice& d2) {
	for (int f = 0; f < 3; ++f) {
		if ((d1.f2n[0] == d2.f2n[f])&&(d1.f2n[5] == d2.f2n[5-f])) {
			for (int i = 0; i < 4; ++i) {
				bool seq = true;
				for (int j = 0; seq && j < 4; ++j) {
					if (d1.f2n[line[0][j]] != d2.f2n[line[f][(i+j)%4]]) {
						seq = false;
					}
				}
				if (seq) {
					return true;
				}
			}
		}
		else if ((d1.f2n[0] == d2.f2n[5-f])&&(d1.f2n[5] == d2.f2n[f])) {
			for (int i = 0; i < 4; ++i) {
				bool seq = true;
				for (int j = 0; seq && j < 4; ++j) {
					int next = i-j;
					if (next < 0) {
						next = 4 + (i-j);
					}
					if (d1.f2n[line[0][j]] != d2.f2n[line[f][next]]) {
						seq = false;
					}
				}
				if (seq) {
					return true;
				}
			}
		}
	}
	return false;
}

int main(void) {
	int n;
	cin >> n;
	vector<dice> d(n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 6; ++j) {
			cin >> d[i].f2n[j];
		}
	}
	bool find = false;
	for (int i = 0; !find && i < n-1; ++i) {
		for (int j = i+1; !find && j < n; ++j) {
			find = check_equal_dice(d[i],d[j]);
		}
	}

	if (!find) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

