#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n,a[5][N],i,j,k,x,y,b[N],c[2];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=3;++i)
		for(j=1;j<=n;++j)
			scanf("%d",a[i]+j);
	for(i=1;i<=n;++i)
	{
		x=y=a[1][i];
		for(j=2;j<=3;++j)
			x=max(x,a[j][i]),y=min(y,a[j][i]);
		if(x-y!=2||y+1!=a[2][i])
		{
			printf("No");
			return 0;
		}
		b[i]=x/3;
		if(a[1][i]!=y)
			c[i&1]=!c[i&1];
		if((x/3-i)%2)
		{
			printf("No");
			return 0;
		}
	}
	for(i=1;i<=n;++i)
	while(i!=b[i])
	{
		swap(b[i],b[b[i]]);
		c[i&1^1]=!c[i&1^1];
	}
	if(c[0]||c[1])
		printf("No");
	else
		printf("Yes");
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
using namespace std;
const int MOD=998244353;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> c(n),d(n);
    REP(i,n) cin >> d[i], c[d[i]]++;
    if ( d[0]!=0 || c[0]>1 ) { cout << 0 << '\n'; return 0; }
    int ans=1;
    REP1(i,1,n-1) {
        if ( c[i-1]==0 && c[i]==0 ) continue;
        REP(j,c[i]) ans=(long long)ans*c[i-1]%MOD;
    }
    cout << ans << '\n';
    return 0;
}