#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 200011;
#define x first
#define y second
#define pb push_back
#define mp make_pair

int n , p[N] , ans[N], root;
vector<int> g[N];
pii E;
int dsu[N];
int find(int u){
	return dsu[u]==u?u:dsu[u]=find(dsu[u]);
}

bool check() {
	g[E.x].pb(E.y);
	bool can = true;
	for (int i = 1; i <= n; ++i) {
		set<int> st;
		int cnt = 0;
		for (auto j : g[i]) {
			st.insert(ans[j]);
		}
		while(st.count(cnt))++cnt;
		if(ans[i] != cnt)can = false;
	}
	if (can) {
		puts("POSSIBLE");
		exit(0);
	}

}
int dfs(int u , int p) {
	set<int> st;
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		if (v == p)continue;
		st.insert(dfs(v, u));
	}
	int cnt = 0;
	while (st.count(cnt))++cnt;
	if(ans[u] == -1){
		ans[u] = cnt;
	}
	return ans[u];
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n ; ++i) {
		scanf("%d", &p[i]);
		dsu[i]=i;
	}
	for (int i = 1; i <= n; ++i){
		if(find(p[i])!=find(i)){
			g[p[i]].pb(i);
			dsu[find(p[i])]=find(i);
		}else{
			E = mp(p[i],i);
		}
	}
	root = E.second;
	
	memset(ans, -1, sizeof ans);
	dfs(root, -1);
	check();
	int cnt = 0;
	set<int> st;
	for (auto j : g[p[root]]) {
		st.insert(ans[j]);
	}
	g[E.first].pop_back();	
	while (st.count(cnt))++cnt;
	memset(ans, -1, sizeof ans);
	ans[E.first] = cnt;
	dfs(root, -1);
	check();


	puts("IMPOSSIBLE");
	return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 200011;
#define x first
#define y second
#define pb push_back
#define mp make_pair

int n , p[N] , ans[N], root;
vector<int> g[N];
pii E;
int dsu[N];
int find(int u){
	return dsu[u]==u?u:dsu[u]=find(dsu[u]);
}

bool check() {
	g[E.x].pb(E.y);
	bool can = true;
	for (int i = 1; i <= n; ++i) {
		set<int> st;
		int cnt = 0;
		for (auto j : g[i]) {
			st.insert(ans[j]);
		}
		while(st.count(cnt))++cnt;
		if(ans[i] != cnt)can = false;
	}
	if (can) {
		puts("POSSIBLE");
		exit(0);
	}

}
int dfs(int u , int p) {
	set<int> st;
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		if (v == p)continue;
		st.insert(dfs(v, u));
	}
	int cnt = 0;
	while (st.count(cnt))++cnt;
	if(ans[u] == -1){
		ans[u] = cnt;
	}
	return ans[u];
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n ; ++i) {
		scanf("%d", &p[i]);
		dsu[i]=i;
	}
	for (int i = 1; i <= n; ++i){
		if(find(p[i])!=find(i)){
			g[p[i]].pb(i);
			dsu[find(p[i])]=find(i);
		}else{
			E = mp(p[i],i);
		}
	}
	root = E.second;
	
	memset(ans, -1, sizeof ans);
	dfs(root, -1);
	check();
	int cnt = 0;
	set<int> st;
	for (auto j : g[p[root]]) {
		st.insert(ans[j]);
	}
	g[E.first].pop_back();	
	while (st.count(cnt))++cnt;
	memset(ans, -1, sizeof ans);
	ans[E.first] = cnt;
	dfs(root, -1);
	check();


	puts("IMPOSSIBLE");
	return 0;
}

```