#include<bits/stdc++.h>
#include<vector>
#define N 400005
using namespace std;
vector<int> G[N];
int n,m=1,a[N],b[N],head[N],nxt[N],num[N],vis[N],op[N],dex[N],X[N],rt,cnt;
void link(int x,int y,int z) {
	num[++m]=y,dex[m]=z,nxt[m]=head[x],head[x]=m;
	num[++m]=x,dex[m]=z,nxt[m]=head[y],head[y]=m;
}
void dfs(int t)
{
	int i;
	while (i=head[t]) {
		head[t]=nxt[i];
		if (vis[i]||vis[i^1]) continue;		
		if (++cnt==1000000) {
			printf("F**K");
			exit(0);
		}
		vis[i]=vis[i^1]=1;
		dfs(num[i]);
		if (~dex[i]&1)
			X[dex[i]/2]=(i&1 ? 1 : -1);
	}
}
void DFS(int t)
{
	int i;
	for(i=0;i<G[t].size();i++)
		X[t]-=X[G[t][i]],DFS(G[t][i]);
}
int main()
{
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) scanf("%d",&b[i]);
	for (i=1;i<=n;i++) {
		if (a[i]!=-1) G[a[i]].push_back(i); else rt=i;
		link(i,(a[i]==-1 ? n+1 : a[i]),2*i);
		link((b[i]==-1 ? n+1 : b[i]),i,2*i+1);
		if (a[i]>0) op[a[i]]^=1;
		if (b[i]>0) op[b[i]]^=1;
	}
	for (i=1;i<=n;i++)
		if (op[i]) {
			printf("IMPOSSIBLE");
			return 0;
		}
 	dfs(n+1);
	DFS(rt);
	printf("POSSIBLE\n");
	for (i=1;i<=n;i++)
		printf("%d ",X[i]);
	return 0;
}
