#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
int r[2];
vector<int> V[2][MC];
int p[MC][2];
int X[MC];

int dfs(int t , int q){
	int z = 0;
	for(auto u : V[t][q]){
		int y = dfs(t,u);
		if(z){
			p[y][t] = z;
			p[z][t] = y;
			z = 0;
		} else {
			z = y;
		}
	}
	return z ? z : q;
}

int main(){
	scanf("%d" , &N);
	repp(t,0,2){
		repp(i,1,N+1){
			int A;
			scanf("%d" , &A);
			if(A<0) r[t] = i;
			else V[t][A].PB(i);
		}
	}
	repp(i,1,N+1){
		if((V[0][i].size() - V[1][i].size()) % 2){
			printf("IMPOSSIBLE\n");
			return 0;
		}
	}
	printf("POSSIBLE\n");
	dfs(0,r[0]);
	dfs(1,r[1]);
	repp(i,1,N+1){
		if(V[0][i].size()%2){
			printf("0%c" , i==N ? '\n' : ' ');
			continue;
		}
		if(X[i]==0){
			repp(k,0,2){
				int q = i;
				int t = k;
				X[i] = 1;
				while(p[q][t] > 0 && X[p[q][t]] == 0){
					X[p[q][t]] = -X[q];
					q = p[q][t];
					t = 1-t;
				}
			}
		}
		printf("%d%c" , X[i] , i==N ? '\n' : ' ');
	}
	return 0;
}
