#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int V=233333;
const int E=520233;
struct G{
	int fir[V],nxt[E],to[E],cnt[V],tote,p[V];
	void adde(int u,int v){++cnt[u];to[++tote]=v;nxt[tote]=fir[u];fir[u]=tote;}
	int dfs(int u)
	{
		int o1=0,o2=0;
		for(int i=fir[u];i;i=nxt[i])
		{
			o2=dfs(to[i]);
			if(o1){p[o1]=o2;p[o2]=o1;o1=o2=0;}
			else o1=o2;
		}
		if(cnt[u]&1)return o1;
		else return u;
	}
}A,B;
int n,rtA,rtB,x[V];
void dfs(int u)
{
	if(!x[A.p[u]])
	{
		x[A.p[u]]=-x[u];
		dfs(A.p[u]);
	}
	if(!x[B.p[u]])
	{
		x[B.p[u]]=-x[u];
		dfs(B.p[u]);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1,f;i<=n;++i)
	{
		scanf("%d",&f);
		if(~f)A.adde(f,i);
		else rtA=i;
	}
	for(int i=1,f;i<=n;++i)
	{
		scanf("%d",&f);
		if(~f)B.adde(f,i);
		else rtB=i;
	}
	for(int i=1;i<=n;++i)if((A.cnt[i]^B.cnt[i])&1)return puts("IMPOSSIBLE"),0;
	puts("POSSIBLE");
	A.dfs(rtA);B.dfs(rtB);
	for(int i=1;i<=n;++i)
	{
		if(A.cnt[i]&1)printf("0 ");
		else
		{
			if(!x[i]){x[i]=1;dfs(i);}
			printf("%d ",x[i]);
		}
	}
	return 0;
}