// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+10;

struct E{

	int x,y,nxt,flag;

}mm[N<<2];

int h[N],len,p[N],n,ans[N],cur[N];

bool v[N];

inline int rd(){

	int x=0;int f=1;char s=getchar();

	while(!isdigit(s)) f=(s=='-'?-1:f),s=getchar();

	while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar();

	return x*f;

}



inline void add(int x,int y){

	++len;

	mm[len].x=x;mm[len].y=y;mm[len].nxt=h[x];h[x]=len;

	++len;

	mm[len].x=y;mm[len].y=x;mm[len].nxt=h[y];h[y]=len;

	p[x]++;p[y]++;

	return ;

}

void dfs(int u,int f){

	

	for(int& k=cur[u];k;k=mm[k].nxt){

		int y=mm[k].y;

		if(mm[k].flag||f==y) continue; 

		mm[k].flag=mm[k%2==0?k-1:k+1].flag=1;

		if(v[u] && u<=n && y>n) ans[u]=ans[y]=1; 

		if(v[u] && u>n && y<=n) ans[u]=ans[y]=-1;

		h[u]=mm[k].nxt;

		dfs(y,u);

	}

}

int main(){

//	freopen("t.in","r",stdin);

	n=rd();memset(h,0,sizeof h);

	for(int i=1;i<=n;i++){

		int u=rd();u=max(0,u);

		add(u,i);

	}

	for(int i=1;i<=n;i++){

		int u=rd();u=u==-1?0:(u+n);

		add(u,i+n);

	}

	for(int i=1;i<=2*n;i++){

		if(p[i]%2) v[i]=1;

		else v[i]=0;

	}

	bool flag=true;

	for(int i=1;i<=n;i++)

		if(v[i]!=v[i+n]) flag=0;

	if(flag) printf("POSSIBLE\n");

	else {

		printf("IMPOSSIBLE\n");

		return 0;

	}

	for(int i=1;i<=n;i++)

		if(v[i]) add(i,i+n);//,printf("#%d %d\n",i,i+n);

	for(int i=0;i<=2*n;i++) cur[i]=h[i]; 

	dfs(1,0);

	for(int i=1;i<=n;i++) printf("%d ",ans[i]);printf("\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.815711898222871x):
#include<bits/stdc++.h>

using namespace std;

int n,s;

int fa[200200];

int d[200200];

int rt1,rt2;



int te;

struct data{

	int to,nxt,id;

}mp[1000100];

int head[200200],cnt;

void link(int x,int y,int id)

{

	mp[++cnt].to=y;

	mp[cnt].id=id;

	mp[cnt].nxt=head[x];

	head[x]=cnt;

}



int ans[200200];

bool del[500500];

int sta[500500][2],top;

int ro[500500],cr;

void dfs(int s)

{

	sta[++top][0]=s;

	sta[top][1]=1;

	int x,v;

	while(top)

	{

		x=sta[top][0];

		int fl=1;

		if(sta[top][1]==1)

		{

			for(int i=head[x];i;i=mp[i].nxt)

			{

				if(del[mp[i].id])continue;

				del[mp[i].id]=1;

				head[x]=mp[i].nxt;

				fl=0;

				v=mp[i].to;

				sta[++top][0]=v;

				sta[top][1]=1;

				break;

			}

			if(fl)

			{

				sta[top][1]=2;

				continue;

			}

		}

		else if(sta[top][1]==2)

		{

			ro[++cr]=sta[top][0];

			top--;

		}

	}

}

int main()

{

	scanf("%d",&n);

	s=n*2+1;

	for(int i=1;i<=n;++i)

	{

		scanf("%d",&fa[i]);

		if(fa[i]==-1)fa[i]=s;

		d[fa[i]]++;

		++te;

		link(fa[i],i,te);

		link(i,fa[i],te);

	}

	for(int i=1;i<=n;++i)

	{

		scanf("%d",&fa[i]);

		if(fa[i]==-1)fa[i]=s;

		else fa[i]=s-fa[i];

		d[fa[i]]++;

		++te;

		link(fa[i],s-i,te);

		link(s-i,fa[i],te);

	}

	for(int i=1;i<s;++i)d[i]=(!(d[i]&1));

	for(int i=1;i<=n;++i)

	{

		if(d[i]!=d[s-i])

		{

			puts("IMPOSSIBLE");

			return 0;

		}

		if(d[i])

		{

			++te;

			link(i,s-i,te);

			link(s-i,i,te);

		}

	}

	dfs(1);

	puts("POSSIBLE");

	for(int i=cr;i>1;--i)

		if(ro[i]+ro[i-1]==s)

		{

			if(ro[i]<=n)ans[ro[i]]=ans[ro[i-1]]=1;

			else ans[ro[i]]=ans[ro[i-1]]=-1;

		}

	for(int i=1;i<=n;++i)printf("%d ",ans[i]);puts("");

	return 0;

}