#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;

int main() {
//	cout << fixed << setprecision(15);
    int n;
    cin >> n;
    vvi a(n, vi(n));
    rep(i, n) rep(j, n) cin >> a[i][j];

    vll sc(1 << n);
    rep(i, 1 << n) {
        rep(j, n) for(int k = j; k < n; k++) {
            if(!((1 << j) & i && (1 << k) & i)) continue;
            sc[i] += a[j][k];
        }
    }

    vll dp(1 << n, -INFL);
    dp[0] = 0;
    rep(use, 1 << n) {
        int unuse = ((1 << n) - 1) & (~use);
        for(int i = unuse; i > 0; i = (i - 1) & unuse) {
            if(i <= use) continue;
            chmax(dp[use | i], dp[use] + sc[i]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

#include <cstdio>
int N, a[100001], ref[100001], _[3][100001], d[100001], T[100001], cover[100001];
void P(int x)
{
	while (x <= N)
	{
		T[x]++;
		x += x & -x;
	}
}
int G(int x)
{
	int r = 0;
	while (x)
	{
		r += T[x];
		x &= x - 1;
	}
	return r;
}
int main()
{
	scanf("%d", &N);
	for (int i = 0; i < 3; i++)
		for (int j = 1; j <= N; j++)
			scanf("%d", _[i] + j);
	for (int i = 1; i <= N; i++)
		if (_[0][i] == _[1][i] - 1 && _[1][i] == _[2][i] - 1 && _[2][i] % 3 == 0)
		{
			a[i] = _[2][i] / 3;
			ref[a[i]] = i;
			d[a[i]] = 0;
		}
		else if (_[0][i] == _[1][i] + 1 && _[1][i] == _[2][i] + 1 && _[0][i] % 3 == 0)
		{
			a[i] = _[0][i] / 3;
			ref[a[i]] = i;
			d[a[i]] = 1;
		}
		else
		{
			puts("No");
			return 0;
		}
	for (int i = 1; i <= N; i++)
		if (i - a[i] & 1)
		{
			puts("No");
			return 0;
		}
	for (int i = N - !(N & 1); i >= 1; i -= 2)
	{
		cover[i] ^= 1;
		cover[i + (G(ref[i]) << 1)] ^= 1;
		d[a[i]] ^= i - a[i] >> 1 & 1;
		P(ref[i]);
	}
	for (int i = 2; i <= N; i++)
		cover[i] ^= cover[i - 1];
	for (int i = 2; i <= N; i += 2)
		d[a[i]] ^= cover[i];
	for (int i = 1; i <= N; i += 2)
		a[i] = ref[i] = i;
	for (int i = 1; i <= N; i++)
		cover[i] = T[i] = 0;
	for (int i = N - (N & 1); i >= 2; i -= 2)
	{
		cover[i] ^= 1;
		cover[i + (G(ref[i]) << 1)] ^= 1;
		d[a[i]] ^= i - a[i] >> 1 & 1;
		P(ref[i]);
	}
	for (int i = 2; i <= N; i++)
		cover[i] ^= cover[i - 1];
	for (int i = 1; i <= N; i += 2)
		d[a[i]] ^= cover[i];
	if (N == 3)
		puts(d[1] == 0 && d[2] == 0 && d[3] == 0 ? "Yes" : "No");
	else if (N == 4)
		puts(d[1] == d[2] && d[2] == d[3] && d[3] == d[4] ? "Yes" : "No");
	else
	{
		int c0 = 0, c1 = 0;
		for (int i = 1; i <= N; i += 2)
			c0 += d[i];
		for (int i = 2; i <= N; i += 2)
			c1 += d[i];
		puts((c0 & 1) || (c1 & 1) ? "No" : "Yes");
		return 0;
	}
}
