#include <bits/stdc++.h>
#define ad(x) ((x - 1 ^ 1) + 1)

const int N = 200054, M = N * 3;

int n, R1, R2, E = 0;
int to[M], first[N], next[M];
int deg[N], eg[N];
bool used[M], dir[M];

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	for (int &i = first[x]; i; i = next[i])
		if (!used[i])
			used[ad(i)] = used[i] = dir[i] = true, dfs(to[i]);
}

int main() {
	int i, x;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", &x), ~x ? (addedge(i, x), ++deg[x]) : (R1 = i);
	for (; i <= 2 * n; ++i) scanf("%d", &x), ~x ? (addedge(i, x + n), ++deg[x + n]) : (R2 = i);
	addedge(R1, R2);
	for (i = 1; i <= n; ++i)
		if ((deg[i] ^ deg[i + n]) & 1) return puts("IMPOSSIBLE"), 0;
		else if (~deg[i] & 1) addedge(i, i + n), eg[i] = E;
	for (i = 1; i <= 2 * n; ++i) dfs(i);
	puts("POSSIBLE");
	for (i = 1; i <= n; ++i) printf("%d%c", deg[i] & 1 ? 0 : dir[eg[i]] ? 1 : -1, i == n ? 10 : 32);
	return 0;
}