#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=4e5+9;
	int head[N],nex[N],to[N],cnt,st[N],top;
	inline void adde(int u,int v){
		nex[++cnt]=head[u];
		head[u]=cnt,to[cnt]=v;
	}
	int col[N];
	inline void dfs(int u){
		for(int i=head[u];i;i=nex[i]) 
			if(!col[to[i]]) col[to[i]]=-col[u],dfs(to[i]);
	}
	struct Graph{
		int head[N],nex[N],to[N],deg[N],cnt,rt;
		inline void add(int u,int v){
			nex[++cnt]=head[u];
			head[u]=cnt,to[cnt]=v;
		}
		inline void dfs(int u){
			for(int i=head[u];i;i=nex[i]){
				dfs(to[i]);
				if(!(deg[to[i]]&1)) st[++top]=to[i];
			}
			while(top>=2)
				adde(st[top],st[top-1]),adde(st[top-1],st[top]),top-=2;
		}
	}A,B;
	int n;
	int main(){
		n=read<int>();
		for(int i=1;i<=n;i++){
			int fa=read<int>();
			if(fa==-1) A.rt=i;
			else A.add(fa,i),A.deg[fa]++;
		}
		for(int i=1;i<=n;i++){
			int fa=read<int>();
			if(fa==-1) B.rt=i;
			else B.add(fa,i),B.deg[fa]++;
		}
		for(int i=1;i<=n;i++)
			if((A.deg[i]&1)^(B.deg[i]&1)) puts("IMPOSSIBLE"),exit(0);
		puts("POSSIBLE");
		A.dfs(A.rt),top=0,B.dfs(B.rt);
		for(int i=1;i<=n;i++) if(!(A.deg[i]&1) && !col[i]) col[i]=1,dfs(i);
		for(int i=1;i<=n;i++)
			printf("%d%c",col[i]," \n"[i==n]);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}