#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 200000;
int A[N], B[N], v[N], ans[N], rt;
vector <int> bn[N], bi[N];
int dfs(int t)
{
    int ls = 0; v[t] ^= bi[t].size();
    if ((!(bi[t].size() & 1))) ls = t;
    for (int i = 0; i < bi[t].size(); ++ i)
    {
        int nw = dfs(bi[t][i]);
        if (nw)
        {
            if (ls) bn[ls].push_back(nw), bn[nw].push_back(ls), ls = 0;
            else ls = nw;
        }
    }
    return ls;
}
void solve(int t, int v)
{
    ans[t] = v;
    for (int i = 0; i < bn[t].size(); ++ i)
        if (!ans[bn[t][i]]) solve(bn[t][i], -v);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> A[i];
    for (int i = 1; i <= n; ++ i) cin >> B[i];
    for (int i = 1; i <= n; ++ i)
        if (A[i] == -1) rt = i; else bi[A[i]].push_back(i);
    dfs(rt);
    for (int i = 1; i <= n; ++ i) bi[i].clear();
    for (int i = 1; i <= n; ++ i)
        if (B[i] == -1) rt = i; else bi[B[i]].push_back(i);
    dfs(rt);

    for (int i = 1; i <= n; ++ i)
        if (v[i] & 1) return puts("IMPOSSIBLE"), 0;
    for (int i = 1; i <= n; ++ i)
        if (!ans[i] && (!(bi[i].size() & 1))) solve(i, 1);
    puts("POSSIBLE");
    for (int i = 1; i <= n; ++ i) cout << ans[i] << " "; cout << endl;
}
