#include "bits/stdc++.h"

using ll = long long;

using namespace std;
#define int ll

// 0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
// a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
// a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
// a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)                                                              \
	sort(all(v));                                                              \
	(v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
	type x;                                                                    \
	cin >> x
#define YES(f)                                                                 \
	if ((f)) {                                                                 \
		cout << "YES" << endl;                                                 \
	} else {                                                                   \
		cout << "NO" << endl;                                                  \
	}
#define Yes(f)                                                                 \
	if ((f)) {                                                                 \
		cout << "Yes" << endl;                                                 \
	} else {                                                                   \
		cout << "No" << endl;                                                  \
	}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

struct dice {
	vector<int> v;
	int &u, &s, &e, &w, &n, &d;
	dice(const vector<int>& t) : v(t.begin(), t.begin() + 6), u(v[0]), s(v[1]), e(v[2]), w(v[3]), n(v[4]), d(v[5]) {}
	dice(const dice& t) : v(t.v.begin(), t.v.begin() + 6), u(v[0]), s(v[1]), e(v[2]), w(v[3]), n(v[4]), d(v[5]) {}
	void rollE() {
		int t = e;
		e = u;
		u = w;
		w = d;
		d = t;
	}
	void rollS() {
		int t = s;
		s = u;
		u = n;
		n = d;
		d = t;
	}
	void rollW() {
		int t = w;
		w = u;
		u = e;
		e = d;
		d = t;
	}
	void rollN() {
		int t = n;
		n = u;
		u = s;
		s = d;
		d = t;
	}
	void rollR() {
		int t = s;
		s = w;
		w = n;
		n = e;
		e = t;
	}
	void rollL() {
		int t = s;
		s = e;
		e = n;
		n = w;
		w = t;
	}
	void roll(char c) {
		if (c == 'S') rollS();
		else if (c == 'E') rollE();
		else if (c == 'W') rollW();
		else if (c == 'N') rollN();
		else exit(1);
	}
	void set_up(int x) {
		for (int i = 0; u != x; i++) {
			if (i < 3) rollE();
			else if (i < 6) rollN();
			else exit(1);
		}
	}
	void set_south(int x) {
		while (s != x) {
			rollR();
		}
	}
	vector<dice> make_all() const {
		vector<dice> res;
		dice t(*this);
		for (int i = 0; i < 4; i++) {
			res.emplace_back(t);
			t.rollR();
		}
		t.rollE();
		for (int i = 0; i < 4; i++) {
			res.emplace_back(t);
			t.rollN();
		}
		t.rollE();
		for (int i = 0; i < 4; i++) {
			res.emplace_back(t);
			t.rollR();
		}
		t.rollE();
		for (int i = 0; i < 4; i++) {
			res.emplace_back(t);
			t.rollN();
		}
		t.rollR();
		for (int i = 0; i < 4; i++) {
			res.emplace_back(t);
			t.rollE();
		}
		t.rollR();
		t.rollR();
		for (int i = 0; i < 4; i++) {
			res.emplace_back(t);
			t.rollE();
		}
		return res;
	}
	void check(const string& m) {
		cout << m << endl;
		assert(u == v[0]);
		assert(s == v[1]);
		assert(e == v[2]);
		assert(w == v[3]);
		assert(n == v[4]);
		assert(d == v[5]);
	}
	bool comp(const dice& d) {
		auto a = d.make_all();
		for (auto& d : a) {
			bool f = true;
			rep(i, 6) {
				f = f && (v[i] == d.v[i]);
			}
			if (f) return true;
		}
		return false;
	}
};

bool solve() {
	int n;
	cin >> n;
	vector<dice> D;
	rep(i, n) {
		vector<int> t(6);
		rep(i, 6) cin >> t[i];
		D.emplace_back(t);
	}
	rep(i, n-1) {
		reps(j, i+1, n) {
			if (D[i].comp(D[j])) return false;
		}
	}
	return true;
}

signed main()
{
	if (solve()) cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 3180