There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N.
The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional.
We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i.
 - Each a_i is a non-negative integer.
 - For each edge (i, j), a_i \neq a_j holds.
 - For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds.
Determine whether there exists such an assignment.

-----Constraints-----
 - 2 ≤ N ≤ 200 000
 - 1 ≤ p_i ≤ N
 - p_i \neq i
 - The graph is weakly connected.

-----Input-----
Input is given from Standard Input in the following format:
N
p_1 p_2 ... p_N

-----Output-----
If the assignment is possible, print POSSIBLE; otherwise, print IMPOSSIBLE.

-----Sample Input-----
4
2 3 4 1

-----Sample Output-----
POSSIBLE

The assignment is possible: {a_i} = {0, 1, 0, 1} or {a_i} = {1, 0, 1, 0}.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import sys\nsys.setrecursionlimit(10**6)\nn = int(input())\np = list(map(int, input().split()))\nc = [[] for _ in range(n)]\nis_leaf = [True for _ in range(n)]\nfor i in range(n):\n\tp[i] -= 1\n\tc[p[i]].append(i)\n\tis_leaf[p[i]] = False\n\nif sum(is_leaf) == 0:\n\tif n%2 == 0:\n\t\tprint("POSSIBLE")\n\telse:\n\t\tprint("IMPOSSIBLE")\n\treturn\n\nfor i in range(n):\n\tif is_leaf[i]:\n\t\tcur = i\n\t\tbreak\n\nvisited_set = {cur}\nvisited_list = [cur]\nwhile p[cur] not in visited_set:\n\tvisited_list.append(p[cur])\n\tvisited_set.add(p[cur])\n\tcur = p[cur]\n\nroot = p[cur]\n\ngrundy = [-1 for _ in range(n)]\ng_set = [set() for _ in range(n)]\n\ndef dfs(x):\n\tres = 0\n\tfor v in c[x]:\n\t\tdfs(v)\n\t\tg_set[x].add(grundy[v])\n\twhile res in g_set[x]:\n\t\tres += 1\n\tgrundy[x] = res\n\treturn res\n\nloop = [False for _ in range(n)]\nloop[root] = True\nind = len(visited_list)-1\nwhile visited_list[ind] != root:\n\tloop[visited_list[ind]] = True\n\tind -= 1\n#print(loop)\n\nfor i in range(n):\n\tif loop[i]:\n\t\tfor x in c[i]:\n\t\t\tif not loop[x]:\n\t\t\t\tdfs(x)\n\t\t\t\tg_set[i].add(grundy[x])\n\ncand = []\nnum = 0\nwhile num in g_set[root]:\n\tnum += 1\ncand.append(num)\nnum += 1\nwhile num in g_set[root]:\n\tnum += 1\ncand.append(num)\n\nfor x in cand:\n\tcur = root\n\tgrundy[root] = x\n\twhile True:\n\t\tnum = 0\n\t\twhile num in g_set[p[cur]] or num == grundy[cur]:\n\t\t\tnum += 1\n\t\tgrundy[p[cur]] = num\n\t\tif p[cur] == root:\n\t\t\tbreak\n\t\tcur = p[cur]\n\tif grundy[root] == x:\n\t\t#print(grundy)\n\t\tprint("POSSIBLE")\n\t\treturn\n\nprint("IMPOSSIBLE")'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: