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

const int N=100100;
int n,vis[N],col[N],ra,rb;
vector<int>g[N],ga[N],gb[N];
void add_edge(int x,int y){
	g[x].push_back(y);
	g[y].push_back(x);
}
int dfs(int x,vector<int>*g){
	int la=0;
	for(int i:g[x]){
		int u=dfs(i,g);
		if(!la)la=u;
		else add_edge(la,u),la=0;
	}
	if(la==0)vis[x]++,la=x;
	return la;
}
void dfs2(int x,int y){
	col[x]=y;
	for(int i:g[x])if(!col[i])dfs2(i,-y);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		int x;cin>>x;
		if(x==-1)ra=i;
		else ga[x].push_back(i);
	}
	for(int i=1;i<=n;++i){
		int x;cin>>x;
		if(x==-1)rb=i;
		else gb[x].push_back(i);
	}
	dfs(ra,ga);dfs(rb,gb);
	for(int i=1;i<=n;++i)
		if(vis[i]&1){
			cout<<"IMPOSSIBLE\n";
			return 0;
		}
	cout<<"POSSIBLE\n";
	for(int i=1;i<=n;++i){
		if(vis[i]&&!col[i])dfs2(i,1);
		cout<<col[i]<<" \n"[i==n];
	}
	return 0;
}
