#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int tot, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }
void add(int x, int y) { _add(x, y), _add(y, x); }
int n, root, fa[N], w[N], s[N], d[N];
int find(int x)
{
    if(fa[x] == x) return x;
    int anc = find(fa[x]); d[x] ^= d[fa[x]];
    return fa[x] = anc;
}
void merge(int x, int y)
{
    int fx = find(x), fy = find(y);
    if(fx != fy) d[fx] = d[x]^d[y]^1, fa[fx] = fy;
}
int dfs(int x, int fa)
{
    vector<int> u; w[x] = 0;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa) continue;
        u.push_back(dfs(y, x)), s[x] ^= 1, w[x] ^= 1;
    }
    if(!w[x]) u.push_back(x);
    for(int i = 1; i < u.size(); i += 2) merge(u[i], u[i+1]);
    head[x] = 0; return u[0];
}
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) fa[i] = i;
    for(int i = 1, f; i <= n; ++i) 
        if((f = read()) == -1) root = i; else add(f, i);
    dfs(root, 0), tot = 0;
    for(int i = 1, f; i <= n; ++i) 
        if((f = read()) == -1) root = i; else add(f, i);
    dfs(root, 0);
    for(int i = 1; i <= n; ++i) if(s[i]) return puts("IMPOSSIBLE"), 0;
    puts("POSSIBLE");
    for(int i = 1; i <= n; ++i) printf("%d ", w[i]?0:((find(i), d[i])?-1:1));
    return 0;
}