#include <cstring>
#include <cstdio>
int lst[400005], to[800005], pre[800005], tot;
int seq[400005], cnta[400005], cntb[400005], ans[400005], cnt;
bool del[400005];
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 i = lst[u];
		if (i == -1)
			break;
		lst[u] = pre[i];
		if (!del[i >> 1])
		{
			del[i >> 1] = true;
			work(to[i]);
			seq[cnt++] = i;
		}
	}
}
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
		{
			cnta[--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
		{
			cntb[--x] ^= 1;
			add_edge(x + n, i + n);
			add_edge(i + n, x + n);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (cnta[i] ^ cntb[i])
		{
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (cnta[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;
}
