#include <iostream>
#define MEN 6
using namespace std;


struct IN_DICE
{
	int num1;
	int num2;
	int num3;
	int num4;
	int num5;
	int num6;
};

struct DICE
{
	int num;
};

int main()
{
	DICE A[MEN];
	DICE B1[MEN];
	DICE B2[MEN];
	DICE B3[MEN];

	IN_DICE in[100];
	int flag = 0;
	int x;
	int n;

	cin >> n;

	for ( int i = 0; i < n; i++)
	{
		cin >> in[i].num1 >> in[i].num2 >> in[i].num3 >> in[i].num4 >> in[i].num5 >> in[i].num6;
	}

	for (int i1 = 0; i1 < n - 1; i1++)
	{
		for (int i2 = i1 + 1; i2 < n; i2++)
		{
			A[0].num = in[i1].num1;
			A[1].num = in[i1].num2;
			A[2].num = in[i1].num3;
			A[3].num = in[i1].num4;
			A[4].num = in[i1].num5;
			A[5].num = in[i1].num6;

			B1[0].num = in[i2].num1;
			B1[1].num = in[i2].num2;
			B1[2].num = in[i2].num3;
			B1[3].num = in[i2].num4;
			B1[4].num = in[i2].num5;
			B1[5].num = in[i2].num6;

			for (int count = 0; count < MEN; count++)
			{
				for (int i = 0; i < MEN; i++)
				{
					B2[i] = B1[i];
				}
				if (1 <= count && count <= 5)
				{
					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;
				}

				if (2 <= count && count <= 4)
				{
					for (int i = 0; i < count - 1; i++)
					{
						x = B2[0].num;
						B2[0].num = B2[2].num;
						B2[2].num = B2[5].num;
						B2[5].num = B2[3].num;
						B2[3].num = x;
					}
				}

				if (count == 5)
				{
					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;
				}

				if (A[0].num != B2[0].num)
				{
					continue;
				}

				for (int i = 0; i < MEN; i++)
				{
					B3[i] = B2[i];
				}

				for (int count2 = 0; count2 < 4; count2++)
				{
					for (int i = 0; i < MEN; i++)
					{
						B2[i] = B3[i];
					}
					for (int i = 0; i < count2; i++)
					{
						x = B2[1].num;
						B2[1].num = B2[2].num;
						B2[2].num = B2[4].num;
						B2[4].num = B2[3].num;
						B2[3].num = x;
					}

					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;

					if (A[1].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[2].num;
					B2[2].num = B2[5].num;
					B2[5].num = B2[3].num;
					B2[3].num = x;

					if (A[2].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[2].num;
					B2[2].num = B2[5].num;
					B2[5].num = B2[3].num;
					B2[3].num = x;

					if (A[4].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[2].num;
					B2[2].num = B2[5].num;
					B2[5].num = B2[3].num;
					B2[3].num = x;

					if (A[3].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;

					if (A[5].num == B2[0].num)
					{
						flag = 1;
					}
					if (flag == 1)
					{
						break;
					}
				}
				if (flag == 1)
				{
					break;
				}
			}
			if (flag == 1)
			{
				break;
			}
		}
		if (flag == 1)
		{
			break;
		}
	}

	if (flag == 1)
	{
		cout << "No" << endl;
	}
	else if (flag == 0)
	{
		cout << "Yes" << endl;
	}

	return 0;
}
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)            {dbg,args; cerr<<endl;}
#else
#define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;
#define MAXN 100000
int c[MAXN+10];
bool b[MAXN+10];
void solve(long long N, vector<vector<long long>> a){
	int r[2]={0,0},f[2]={0,0};
	for(int i=0; i<N; ++i) {
		c[i]=a[1][i]/3+1;
		if (c[i]%2==i%2) throw 2;
		if (a[0][i]==c[i]*3-2 && a[1][i]==c[i]*3-1 && a[2][i]==c[i]*3) {
		} else if (a[0][i]==c[i]*3 && a[1][i]==c[i]*3-1 && a[2][i]==c[i]*3-2) {
			r[(i+1)&1]^=1;
		} else {
			throw 1;
		}
	}
	memset(b,true,sizeof(b));
	for(int i=1; i<=N; ++i) {
		if (b[i]) {
			int x=c[i-1];
			while(x!=i) {
				debug(x);
				b[x]=false;
				f[i&1]^=1;
				x=c[x-1];
			}
		}
	}
	debug(f[0],f[1]);
	debug(r[0],r[1]);
	if (f[0]!=r[1] || f[1]!=r[0]) throw 3;
	puts("Yes");
}

int main(){
#ifdef WAAUTOMATON
	freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<vector<long long>> a(3-1+1,vector<long long>(N-1+1));
	for(int i = 0 ; i <= 3-1 ; i++){
		for(int j = 0 ; j <= N-1 ; j++){
			scanf("%lld",&a[i][j]);
		}
	}
	try {
		solve(N, a);
	} catch(int err) {
		puts("No");
		debug(err);
	}
	return 0;
}

