#include <bits/stdc++.h>
using namespace std; 
const int N = 200005;
int n;
int a[N], tot=0, h[N];
int dfn[N], low[N], sta[N], dfs_num=0, top=0;
vector<int> e[N]; 
int f[N];
bool vis[N], vis2[N];
void tarjan(int u){
	dfn[u] = low[u] = ++dfs_num;
	sta[++top] = u;
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!dfn[v]){
			tarjan(v);
			low[u] = min(low[v], low[u]);
		}else if (!vis2[v]) low[u] = min(dfn[v], low[u]);
	}
	if (dfn[u] == low[u]){
		vis2[u] = 1;
		if (sta[top] == u){
			top--;
			return;
		}
		do{
			vis2[sta[top]] = 1;
			a[++tot] = sta[top];
			h[sta[top]] = 1;
		}while (sta[top--] != u);
	}
}
void dfs(int u){
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!h[v]) dfs(v);
	}
    for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
        if (!h[v]) vis[f[v]] = 1;
    }
	while (vis[f[u]]) f[u]++;
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!h[v]) vis[f[v]] = 0;
	}
}
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++){
		int fa;
		cin >> fa;
		e[fa].push_back(i);
	}
	for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i);
	int mn = 0x3f3f3f3f, mx = -1;
	for (int i = 1; i <= tot; i++){
		dfs(a[i]);
		mn = min(f[a[i]], mn);
		mx = max(f[a[i]], mx);
	}
	puts((mn == mx && (tot&1) ? "IMPOSSIBLE" : "POSSIBLE"));
	return 0;
}
### Prompt

Your task is to create a Cpp solution to the following problem:

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`.

Examples

Input

4
2 3 4 1


Output

POSSIBLE


Input

3
2 3 1


Output

IMPOSSIBLE


Input

4
2 3 1 1


Output

POSSIBLE


Input

6
4 5 6 5 6 4


Output

IMPOSSIBLE

### Response

```cpp
#include <bits/stdc++.h>
using namespace std; 
const int N = 200005;
int n;
int a[N], tot=0, h[N];
int dfn[N], low[N], sta[N], dfs_num=0, top=0;
vector<int> e[N]; 
int f[N];
bool vis[N], vis2[N];
void tarjan(int u){
	dfn[u] = low[u] = ++dfs_num;
	sta[++top] = u;
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!dfn[v]){
			tarjan(v);
			low[u] = min(low[v], low[u]);
		}else if (!vis2[v]) low[u] = min(dfn[v], low[u]);
	}
	if (dfn[u] == low[u]){
		vis2[u] = 1;
		if (sta[top] == u){
			top--;
			return;
		}
		do{
			vis2[sta[top]] = 1;
			a[++tot] = sta[top];
			h[sta[top]] = 1;
		}while (sta[top--] != u);
	}
}
void dfs(int u){
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!h[v]) dfs(v);
	}
    for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
        if (!h[v]) vis[f[v]] = 1;
    }
	while (vis[f[u]]) f[u]++;
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (!h[v]) vis[f[v]] = 0;
	}
}
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++){
		int fa;
		cin >> fa;
		e[fa].push_back(i);
	}
	for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i);
	int mn = 0x3f3f3f3f, mx = -1;
	for (int i = 1; i <= tot; i++){
		dfs(a[i]);
		mn = min(f[a[i]], mn);
		mx = max(f[a[i]], mx);
	}
	puts((mn == mx && (tot&1) ? "IMPOSSIBLE" : "POSSIBLE"));
	return 0;
}
```