#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;

bool is_connected(vector<int> p)
{
    int n = p.size();
    vector<vector<int>> e(n);
    for (int i = 0; i < n; i++)
    {
        e[p[i]].push_back(i);
        e[i].push_back(p[i]);
    }
    
    vector<int> d(n, -1);
    d[0] = 0;
    
    deque<int> q;
    q.push_back(0);
    
    while (!q.empty())
    {
        int v = q.front();
        q.pop_front();
        
        for (int u: e[v])
        {
            if (d[u] == -1)
            {
                d[u] = d[v] + 1;
                q.push_back(u);
            }
        }
    }
    
    for (int i = 0; i < n; i++)
        if (d[i] == -1)
            return false;
        
    return true;
}

void solve(bool read = true)
{
    int n;
    if (read)
        cin >> n;
    else
        n = rand() % 100 + 2;
    
    vector<int> p(n);
    
    while (true)
    {
        for (int i = 0; i < n; i++)
        {
            if (read)
            {
                cin >> p[i];
                p[i]--;
            }
            else
            {
                p[i] = i;
                while (p[i] == i)
                    p[i] = rand() % n;
            }
        }
        
        if (read) break;
        
        if (is_connected(p)) break;
    }
    
    int root = 0;
    vector<int> v;
    for (int i = 0; i < 3 * n; i++)
    {
        v.push_back(root);
        root = p[root];
    }
    reverse(all(v));
    
    vector<char> repeated(n, false);
    vector<int> loop;
    for (int i = 0; i < n; i++)
    {
        if (repeated[v[i]])
            break;
        
        loop.push_back(v[i]);
        repeated[v[i]] = true;
    }
    assert(loop.size() > 1);
    
    vector<vector<int>> e(n);
    vector<int> out_deg(n, 0);
    for (int i = 0; i < n; i++)
    {
        out_deg[p[i]]++;
        e[p[i]].push_back(i);
    }
    
    vector<char> used = repeated;
    
    deque<int> q;
    for (int i = 0; i < n; i++)
        if (out_deg[i] == 0)
            q.push_back(i);
        
    vector<int> mark(n, -1);
    while (!q.empty())
    {
        int v = q.front();
        q.pop_front();
        used[v] = true;
        
        vector<char> used(e[v].size() + 1);
        for (int x: e[v])
        {
            assert(mark[x] != -1);
            if (mark[x] < (int)used.size())
                used[mark[x]] = true;
        }
        
        int mex = 0;
        while (used[mex]) mex++;
        mark[v] = mex;
        
        out_deg[p[v]]--;
        if (out_deg[p[v]] == 0)
            q.push_back(p[v]);
    }
    
#if 0
    for (int i = 0; i < n; i++)
    {
        if (!used[i] && out_deg[i] == 0)
        {
            int now = i;
            int cur = 0;
            while (!used[now])
            {
                used[now] = true;
                mark[now] = cur;
                cur = 1 - cur;
                now = p[now];
            }
        }
    }
    
    
        cout << "TEST:\n";
        cout << n << "\n";
        for (int i = 0; i < n; i++)
            cout << p[i] + 1 << " ";
        cout << endl;
#endif
    
    for (int i = 0; i < n; i++)
    {
        assert(used[i]);
        assert(repeated[i] || mark[i] != -1);
    }
    
    vector<char> fu(e[loop[0]].size() + 3);
    for (int x: e[loop[0]])
        if (mark[x] >= 0 && mark[x] < (int)fu.size())
            fu[mark[x]] = true;
    
    vector<int> candies;
    for (int i = 0; i < (int)fu.size(); i++)
        if (!fu[i])
        {
            candies.push_back(i);
            if (candies.size() >= 2) break;
        }
    assert((int)candies.size() == 2);
    
    bool good = false;
    for (int first: candies)
    {
        auto old_mark = mark;
        bool fail = false;
        
        //printf("starting %d\n", first);
        
        mark[loop[0]] = first;
        for (int i = (int)loop.size() - 1; i >= 0; i--)
        {
            vector<char> used(e[loop[i]].size() + 1, false);
            for (int x: e[loop[i]])
            {
                assert(mark[x] != -1);
                if (mark[x] < (int)used.size())
                    used[mark[x]] = true;
            }
            
            int mex = -1;
            for (int k = 0; k < (int)e[loop[i]].size() + 1; k++)
                if (!used[k])
                {
                    mex = k;
                    break;
                }
                
            //printf("for %d got %d already %d\n", loop[i] + 1, mex, mark[loop[i]]);
                
            assert(mex != -1);
            if (mark[loop[i]] == -1 || mark[loop[i]] == mex)
            {
                mark[loop[i]] = mex;
            }
            else
            {
                fail = true;
                break;
            }
        }
        
        if (!fail)
        {
            good = true;
            break;
        }
        
        mark = old_mark;
    }
    
    cout << (good ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    
#if 0
    if (good)
    {
        cout << n << "\n";
        for (int i = 0; i < n; i++)
            cout << p[i] + 1 << " ";
        cout << "\n";
        
        for (int i = 0; i < n; i++)
            cout << mark[i] << " ";
        cout << endl;
        
        for (int i = 0; i < n; i++)
        {
            vector<char> used(e[i].size() + 1, false);
            
            for (int x: e[i])
                if (mark[x] < (int)used.size())
                    used[mark[x]] = true;
            
            int mex = 0;
            while (mex < (int)e[i].size() + 1 && used[mex]) mex++;
            assert(mex != (int)e[i].size() + 1);
            
            //if (mark[i] != mex) while(true);
            //printf("mark for %d is %d but mex %d\n", i + 1, mark[i], mex);
            assert(mark[i] == mex);
        }
    }
    
#if 1
    if (good)
    {
        for (int i = 0; i < n; i++)
            cout << mark[i] << " ";
        cout << endl;
    }
#endif
#endif
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve(true);
    
    //while (true)
    //    solve(false);
    
    return 0;
}


Measured memory_bytes: 17260