#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
#define y1			fafa____
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);puts("");}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);puts("");}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);puts("");}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=600010;
ll a[N],b[N],c[N],mp[N],ans[N],n,ned[N],gg[N],Rev[N],pos[N],sum1,sum2;
void add(ll x,ll v){for(;x<=n;x+=x&-x)c[x]+=v;}
ll ask(ll x){ll ans=0;for(;x;x-=x&-x)ans+=c[x];return ans;}
ll find_pos(ll x){return pos[x]+ask(pos[x]);}
void work1(){
	memset(c,0,sizeof c);
	memset(Rev,0,sizeof Rev);
	For(i,1,n)pos[abs(ans[i])]=i;
	For(i,1,n)if (i&1){
		ll Pos=find_pos(i)+i-1;
		add(pos[i],-2);
		if (i!=Pos)Rev[i+1]^=1,Rev[Pos]^=1;
	}
	For(i,1,n)Rev[i]^=Rev[i-1];
	For(i,1,n)if (!(i&1)&&Rev[i])ans[i]=-ans[i];
	For(i,1,n)if (i&1){
		if (abs(abs(ans[i])-i)%4==2)	gg[abs(ans[i])]=-ans[i];
		else							gg[abs(ans[i])]=ans[i];
	}
	For(i,1,n)if (i&1)ans[i]=gg[i];
}
void work2(){
	memset(c,0,sizeof c);
	memset(Rev,0,sizeof Rev);
	For(i,1,n)pos[abs(ans[i])]=i;
	For(i,1,n)if (!(i&1)){
		ll Pos=find_pos(i)+i-2;
		add(pos[i],-2);
		if (i!=Pos)Rev[i+1]^=1,Rev[Pos]^=1;
		
	}
	For(i,1,n)Rev[i]^=Rev[i-1];
	For(i,1,n)if ((i&1)&&Rev[i])ans[i]=-ans[i];
	For(i,1,n)if (!(i&1)){
		if (abs(abs(ans[i])-i)%4==2)	gg[abs(ans[i])]=-ans[i];
		else							gg[abs(ans[i])]=ans[i];
	}
	For(i,1,n)if (!(i&1))ans[i]=gg[i];
}
int main(){
	n=read();
	For(i,1,n)a[i]=read();
	For(i,1,n)b[i]=read();
	For(i,1,n)c[i]=read();
	For(i,1,n){
		if (mp[a[i]])return puts("No"),0;mp[a[i]]=1;
		if (mp[b[i]])return puts("No"),0;mp[b[i]]=1;
		if (mp[c[i]])return puts("No"),0;mp[c[i]]=1;
		if (a[i]%3==1&&b[i]%3==2&&c[i]%3==0&&(a[i]+1==b[i])&&(b[i]+1==c[i])){
			if (i&1){
				if (!(c[i]/3&1))return puts("No"),0;
				else	ans[i]=c[i]/3;
			}else{
				if ((c[i]/3&1))return puts("No"),0;
				else	ans[i]=c[i]/3;
			}
		}
		lf (a[i]%3==0&&b[i]%3==2&&c[i]%3==1&&(a[i]-1==b[i])&&(b[i]-1==c[i])){
			if (i&1){
				if (!(a[i]/3&1))return puts("No"),0;
				else	ans[i]=-a[i]/3;
			}else{
				if ((a[i]/3&1))return puts("No"),0;
				else	ans[i]=-a[i]/3;
			}
		}
		else	return puts("No"),0;
	}
	work1();	work2();
	For(i,1,n)	if(i&1)	sum1^=ans[i]<0;
				else	sum2^=ans[i]<0;
	puts((!sum1&&!sum2)?"Yes":"No");
}

Measured memory_bytes: 26752