#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 301000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
int n, Rt;
int cnt[N];
int fa1[N], fa2[N];
struct edge{
	int nxt, to;
}e[N << 1];
int head[N], ecnt = 1;
inline void addedge(int from, int to) {
	e[++ecnt] = (edge){head[from], to};
	head[from] = ecnt;
}

int blong[N];
bool evis[N << 1], etype[N << 1];
void dfs(int cur) {
	for (int &i = head[cur]; i; i = e[i].nxt) {
		if (evis[i])	continue;
		evis[i] = evis[i ^ 1] = true;
		etype[i] = true;
		int to = e[i].to; dfs(to);
	}
}

int main() {
	read(n); Rt = n + n + 1;
	for (int i = 1; i <= n; ++i) {
		read(fa1[i]);
		if (fa1[i] == -1)	fa1[i] = Rt;
		addedge(fa1[i], i); addedge(i, fa1[i]);
		++cnt[fa1[i]];
	}
	for (int i = 1; i <= n; ++i) {
		read(fa2[i]);
		if (fa2[i] == -1)	fa2[i] = Rt;
		else	fa2[i] += n;
		addedge(fa2[i], i + n); addedge(i + n, fa2[i]);
		++cnt[fa2[i]];
	}
	for (int i = 1; i <= n; ++i) {
		if ((cnt[i] & 1) != (cnt[i + n] & 1)) {
			puts("IMPOSSIBLE");
			return 0;
		}
		if (!(cnt[i] & 1))
			addedge(i, i + n), blong[i] = ecnt, addedge(i + n, i);
	}
	puts("POSSIBLE");
	dfs(1);
	for (int i = 1; i <= n; ++i) {
		if (cnt[i] & 1)	printf("0 ");
		else	printf("%d ", etype[blong[i]] ? 1 : -1);
	}
	return 0;
}
