#include <cstring>
#include <cstdio>
int lst[200005], to[600005], pre[600005], tot;
int dega[200005], degb[200005];
int seq[300005], ans[200005], cnt;
bool del[300005];
inline void add_edge(int u, int v)
{
	to[tot] = v;
	pre[tot] = lst[u];
	lst[u] = tot++;
}
void work(int u)
{
	while (true)
	{
		int e = lst[u];
		if (e == -1)
			break;
		lst[u] = pre[e];
		if (del[e >> 1])
			continue;
		del[e >> 1] = true;
		work(to[e]);
		seq[cnt++] = e;
	}
}
int main()
{
	// freopen("AGC018-F.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		if (x == -1)
		{
			add_edge(n << 1, i);
			add_edge(i, n << 1);
		}
		else
		{
			dega[--x] ^= 1;
			add_edge(x, i);
			add_edge(i, x);
		}
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		if (x == -1)
		{
			add_edge(n << 1, i + n);
			add_edge(i + n, n << 1);
		}
		else
		{
			degb[--x] ^= 1;
			add_edge(x + n, i + n);
			add_edge(i + n, x + n);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (dega[i] ^ degb[i])
		{
			puts("IMPOSSIBLE");
			return 0;
		}
		if (dega[i] ^ 1)
		{
			add_edge(i, i + n);
			add_edge(i + n, i);
		}
	}
	work(0);
	for (int i = 0; i < cnt; i++)
	{
		int u = to[seq[i] ^ 1], v = to[seq[i]];
		if (u < n && n <= v && v != n << 1)
			ans[u] = 1;
		if (v < n && n <= u && u != n << 1)
			ans[v] = -1;
	}
	puts("POSSIBLE");
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}
