#include <bits/stdc++.h>
using namespace std;

const int N=100010;
struct edge{int s,t,p,n;}e[4*N];
int n,tot=1,a[N],b[N],h[N],d[N],ans[N];

void link(int u,int v)
{
	e[++tot]=(edge){u,v,0,h[u]},h[u]=tot,d[u]++;
	e[++tot]=(edge){v,u,0,h[v]},h[v]=tot,d[v]++;
}

void dfs(int x)
{
	for (int i=h[x],y; y=e[i].t,h[x]=e[h[x]].n,i; i=h[x])
		if (!e[i].p)
			{
				e[i].p=e[i^1].p=1,dfs(y);
				if (i&2)  ans[a[x]==e[i].t?x:e[i].t]=(i&1?-1:1);
			}
}

void calc(int x)
{
	for (int i=h[x]; i; i=e[i].n)
		ans[x]-=ans[i],calc(i);
}

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)  scanf("%d",&a[i]),a[i]=(a[i]==-1?n+1:a[i]);
	for (int i=1; i<=n; i++)  scanf("%d",&b[i]),b[i]=(b[i]==-1?n+1:b[i]);
	for (int i=1; i<=n; i++)  link(a[i],i),link(b[i],i);
	for (int i=1; i<=n; i++)  if (d[i]&1)  puts("IMPOSSIBLE"),exit(0);
	puts("POSSIBLE");
	dfs(1);
	for (int i=1; i<=n+1; i++)  h[i]=0;
	for (int i=1; i<=n; i++)  e[i]=(edge){a[i],i,0,h[a[i]]},h[a[i]]=i;
	calc(n+1);
	for (int i=1; i<=n; i++)  printf("%d ",ans[i]);
}

int main()
{
	work();
	return 0;
}
