#include<bits/stdc++.h>

using namespace std;

#define N 120000

int n,rta,rtb,sa[N],sb[N],A[N],B[N],c[N];
vector<int> a[N],b[N],g[N];
bool vis[N];

void add(int x,int y){
	g[x].push_back(y); g[y].push_back(x);
}

void dfs1(int u){
	for (int v:a[u]){
		sa[u]^=1;
		dfs1(v);
		if (A[u]){add(A[u],A[v]); A[u]=0;}
		else A[u]=A[v];
	}
	if (!A[u]) A[u]=u;
}

void dfs2(int u){
	for (int v:b[u]){
		sb[u]^=1;
		dfs2(v);
		if (B[u]){add(B[u],B[v]); B[u]=0;}
		else B[u]=B[v];
	}
	if (!B[u]) B[u]=u;
}

void dfs(int u){
	vis[u]=1;
	for (int v:g[u]) if (!vis[v]){c[v]=-c[u]; dfs(v);}
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		int x; scanf("%d",&x);
		if (~x) a[x].push_back(i); else rta=i;
	}
	for (int i=1;i<=n;++i){
		int x; scanf("%d",&x);
		if (~x) b[x].push_back(i); else rtb=i;
	}
	dfs1(rta); dfs2(rtb);
	for (int i=1;i<=n;++i){
		if (sa[i]^sb[i]){puts("IMPOSSIBLE"); return 0;}
		if (sa[i]) vis[i]=1;
	}
	for (int i=1;i<=n;++i) if (!vis[i]){c[i]=1; dfs(i);}
	puts("POSSIBLE");
	for (int i=1;i<=n;++i) printf(i==n?"%d\n":"%d ",c[i]);
	
	return 0;
}
			