#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
class Dice {
	int a[7];
public:
	Dice(int b,int c,int d,int e,int f,int g) {
		a[1] = b, a[2] = c, a[3] = d, a[4] = e, a[5] = f, a[6] = g;
	}
	Dice() {

	}
	void roll(string s) {
		for (int i = 0; i < s.size(); i++) {
			int k = a[1];
			switch (s[i]) {
			case 'E':
				a[1] = a[4], a[4] = a[6], a[6] = a[3], a[3] = k;
				break;
			case 'N':
				a[1] = a[2], a[2] = a[6], a[6] = a[5], a[5] = k;
				break;
			case 'W':
				roll("E"); roll("E"); roll("E");
				break;
			case 'S':
				roll("N"); roll("N"); roll("N");
				break;
			}
		}
	}
	int right(int top, int fr) {
		int x = 0, y = 0;
		for (int i = 1; i < 7; i++) {
			if (a[i] == top) x = i;
			if (a[i] == fr) y = i;
		}
		if (x == 1) {
			if (y == 2) return 3;
			if (y == 3) return 5;
			if (y == 5) return 4;
			if (y == 4) return 2;
		}
		else if (x == 2) {
			if (y == 6) return 3;
			if (y == 3) return 1;
			if (y == 1) return 4;
			if (y == 4) return 6;
		}
		else if (x == 3) {
			if (y == 6) return 5;
			if (y == 5) return 1;
			if (y == 1) return 2;
			if (y == 2) return 6;
		}
		else if (x == 4) {
			if (y == 2) return 1;
			if (y == 1) return 5;
			if (y == 5) return 6;
			if (y == 6) return 2;
		}
		else if (x == 5) {
			if (y == 3) return 6;
			if (y == 6) return 4;
			if (y == 4) return 1;
			if (y == 1) return 3;
		}
		else {
			if (y == 2) return 4;
			if (y == 4) return 5;
			if (y == 5) return 3;
			if (y == 3) return 2;
		}
	}
	int number(int x) {
		return a[x];
	}

	void set(int b, int c, int d, int e, int f, int g) {
		a[1] = b, a[2] = c, a[3] = d, a[4] = e, a[5] = f, a[6] = g;
	}
	bool operator==(Dice dice) const{
		bool l = 1;
		for (int i = 1; i <= 6; i++) {
			if (dice.number(i) != this->a[i]) l = 0;
		}
		return l;
	}
};
string b[] = { "N","E" };
bool solve(int x, Dice dice, Dice roul) {
	if (x == 4) {
		if (dice == roul) {
			return true;
		}
		else return false;
	}
	bool sum = 0;
	for (int i = 0; i < 3; i++) {
		roul.roll(b[x%2]);
		sum |= solve(x + 1, dice, roul);
	}
	return sum;
}
signed main() {
	int a[6];
	Dice dices[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> a[j];
		}
		dices[i].set(a[0], a[1], a[2], a[3], a[4], a[5]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (solve(0, dices[i], dices[j])) {
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
}


Measured memory_bytes: 3152