#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7, i2 = (mod+1)/2;
int n, owo = -1, f[maxn], vis[maxn];
vector<int> g[maxn], trail;
void cyc(int v, int p) {
	vis[v] = 1;
	trail.pb(v);
	for(auto i : g[v]) if(i != p) {
		if(vis[i] == 1) {
			owo = v;
			//cout << i << " : ";
			//for(auto i : trail) cout << i << " "; cout << endl;
			while(true) {
				f[trail.back()] = 1;
				if(trail.back() == i) break;
				else trail.pop_back();
			}
		} else cyc(i, v);
		if(owo != -1) return;
	}
	vis[v] = 2;
	trail.pop_back();
}

int val[maxn];
int get(int v) {
	if(val[v] != -1) return val[v];
	vector<int> t;
	for(auto i : g[v]) {
		t.pb(get(i));
	}
	sort(all(t));
	int mex = 0;
	for(auto i : t) {
		if(i > mex) break;
		mex += mex==i;
	}
	return val[v] = mex;
}
bool check(int v, int x) {
	memset(val, -1, sizeof val);
	val[v] = x;
	for(int i = 1; i <= n; i++) get(i);
	val[v] = -1;
	return get(v) == x;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int t, i = 1; i <= n; i++) {
		cin >> t;
		g[t].pb(i);
	}
	for(int i = 1; owo == -1 && i <= n; i++) if(!vis[i])
	cyc(i, i);
	if(owo == -1) return cout << "POSSIBLE\n", 0;
	memset(val, -1, sizeof val);
	vector<int> t;
	int nxt = 0;
	for(auto i : g[owo]) if(!f[i]) {
		t.pb(get(i));
	} else nxt = i;
	sort(all(t));
	int mex = 0;
	for(auto i : t) {
		if(i > mex) break;
		mex += mex==i;
	}
	cout << (check(owo, mex)||check(nxt, mex)?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

### Prompt

Your challenge is to write 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
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7, i2 = (mod+1)/2;
int n, owo = -1, f[maxn], vis[maxn];
vector<int> g[maxn], trail;
void cyc(int v, int p) {
	vis[v] = 1;
	trail.pb(v);
	for(auto i : g[v]) if(i != p) {
		if(vis[i] == 1) {
			owo = v;
			//cout << i << " : ";
			//for(auto i : trail) cout << i << " "; cout << endl;
			while(true) {
				f[trail.back()] = 1;
				if(trail.back() == i) break;
				else trail.pop_back();
			}
		} else cyc(i, v);
		if(owo != -1) return;
	}
	vis[v] = 2;
	trail.pop_back();
}

int val[maxn];
int get(int v) {
	if(val[v] != -1) return val[v];
	vector<int> t;
	for(auto i : g[v]) {
		t.pb(get(i));
	}
	sort(all(t));
	int mex = 0;
	for(auto i : t) {
		if(i > mex) break;
		mex += mex==i;
	}
	return val[v] = mex;
}
bool check(int v, int x) {
	memset(val, -1, sizeof val);
	val[v] = x;
	for(int i = 1; i <= n; i++) get(i);
	val[v] = -1;
	return get(v) == x;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int t, i = 1; i <= n; i++) {
		cin >> t;
		g[t].pb(i);
	}
	for(int i = 1; owo == -1 && i <= n; i++) if(!vis[i])
	cyc(i, i);
	if(owo == -1) return cout << "POSSIBLE\n", 0;
	memset(val, -1, sizeof val);
	vector<int> t;
	int nxt = 0;
	for(auto i : g[owo]) if(!f[i]) {
		t.pb(get(i));
	} else nxt = i;
	sort(all(t));
	int mex = 0;
	for(auto i : t) {
		if(i > mex) break;
		mex += mex==i;
	}
	cout << (check(owo, mex)||check(nxt, mex)?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

```