#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 800005
#define ll long long
int tar[N], nex[N], fir[N], cnt = 1;
int n, rt1, rt2, deg[N], ans[N], vis[N];
void Read(int &p)
{
	p = 0;
	int f = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar())f |= (c == '-');
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
	if (f)p = -p;
}
void Add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
void Dfs(int r)
{
	for (int &t = fir[r]; t; t = nex[t])
	{
		if (vis[t])continue;
		int v = tar[t];
		vis[t] = vis[t ^ 1] = 1;
		Dfs(v);
		if (r > 2 * n || v > 2 * n)
			continue;
		if (r + n == v)
			ans[r] = 1;
		if (v + n == r)
			ans[v] = -1;
	}
}
int main()
{
	Read(n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		Read(x);
		deg[i] ^= 1;
		if (x != -1)
		{
			Add(x, i), Add(i, x);
			deg[x] ^= 1;
		}
		else
			Add(2 * n + 1, i), Add(i, 2 * n + 1);
	}
	for (int i = 1; i <= n; i++)
	{
		int x;
		Read(x);
		deg[n + i] ^= 1;
		if (x != -1)
		{
			Add(n + x, n + i), Add(n + i, n + x);
			deg[n + x] ^= 1;
		}
		else
			Add(2 * n + 1, n + i), Add(n + i, 2 * n + 1);
	}
	for (int i = 1; i <= n; i++)
	{
		if (deg[i] != deg[n + i])
		{
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	puts("POSSIBLE");
	for (int i = 1; i <= n; i++)
		if (deg[i])
			Add(i, n + i), Add(n + i, i);
	Dfs(2 * n + 1);
	for (int i = 1; i <= n; i++)
		printf("%d%c", ans[i], i == n ? 10 : 32);
}
