#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int a[5][MAXN],n,tg[5],to[MAXN];
int Abs(int x)
{
	return x>=0?x:-x;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<3;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	
	for(int i=1;i<=n;i++)
	{
		to[i]=a[1][i]/3+1;
		if(!((a[0][i]-a[1][i]==-1&&a[1][i]-a[2][i]==-1&&a[0][i]%3==1)||(a[0][i]-a[1][i]==1&&a[1][i]-a[2][i]==1&&!(a[0][i]%3)))||(Abs(i-to[i])&1))
		{
			printf("No\n");
			return 0;
		}
		tg[i&1]^=(a[0][i]>a[1][i]);
	}
	
	for(int i=1;i<=n;i++)
	{
		while(to[i]!=i)
		{
			tg[i&1^1]^=1;
			swap(to[i],to[to[i]]);
		}
	}
	if(tg[0]||tg[1]) printf("No\n");
	else printf("Yes\n");
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,60) {
        ll x = 0;
        rep(j,n) if (a[j]>>i & 1) x++;
        ll now = x*(n-x)%mod; //今考えてる桁から生じる和
        rep(k,i) now = now*2%mod;
        ans += now;
        ans %= mod;
    }
   cout << ans << endl; 
}