#include <bits/stdc++.h>

using std::swap;

const int N=2e5+10;

struct Edge{ int to,next; }way[N<<1];

int n,num[N],tot,In[N],app[N],val[N],val1[N],val2[N];
bool cir[N],vis[N];

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void Init() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&In[i]);
}

void Dfs(int x,int fa) {
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		Dfs(v,x);
	}
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		app[val[v]]++;
	}
	int cnt=fa?1:2;
	for (int i=0;cnt;++i) if (!app[i]) {
		if (cnt==2) val2[x]=i;
		else val[x]=val1[x]=i; 
		cnt--;
	}
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		app[val[v]]--;
	}
}

void Solve() {
	int rt=1; while (!vis[rt]) vis[rt]=1,rt=In[rt];
	while (!cir[rt]) cir[rt]=1,rt=In[rt];
	for (int i=1;i<=n;++i) if (!cir[i]) Build(In[i],i);
	for (int i=1;i<=n;++i) if (cir[i]) Dfs(i,0);
	for (int i=1;i<=n;++i) if (cir[i]) {
		for (int j=1;j<=n;++j) if (cir[j]) {
			val[j]=-1;
			if (val2[j]<val1[j]) swap(val1[j],val2[j]);
		}
		val[i]=val1[i]; 
		int x=In[i],pre=i;
		do{
			if (val[pre]==val1[x]) val[x]=val2[x];
			else val[x]=val1[x];
			pre=x; x=In[x];
		}while (x!=In[i]);
		if (val1[i]==val[i]) { printf("POSSIBLE\n"); return ; }
		
		for (int j=1;j<=n;++j) if (cir[j]) val[j]=-1;
		val[i]=val2[i]; x=In[i],pre=i;
		do{
			if (val[pre]==val1[x]) val[x]=val2[x];
			else val[x]=val1[x];
			pre=x; x=In[x];
		}while (x!=In[i]);
		if (val2[i]==val[i]) { printf("POSSIBLE\n"); return ; }
		else { printf("IMPOSSIBLE\n"); return ; }
		break;
	}
}

int main() {
	Init();
	Solve();
	return 0;
}
### Prompt

In CPP, your task is to solve 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 std::swap;

const int N=2e5+10;

struct Edge{ int to,next; }way[N<<1];

int n,num[N],tot,In[N],app[N],val[N],val1[N],val2[N];
bool cir[N],vis[N];

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void Init() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&In[i]);
}

void Dfs(int x,int fa) {
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		Dfs(v,x);
	}
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		app[val[v]]++;
	}
	int cnt=fa?1:2;
	for (int i=0;cnt;++i) if (!app[i]) {
		if (cnt==2) val2[x]=i;
		else val[x]=val1[x]=i; 
		cnt--;
	}
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		app[val[v]]--;
	}
}

void Solve() {
	int rt=1; while (!vis[rt]) vis[rt]=1,rt=In[rt];
	while (!cir[rt]) cir[rt]=1,rt=In[rt];
	for (int i=1;i<=n;++i) if (!cir[i]) Build(In[i],i);
	for (int i=1;i<=n;++i) if (cir[i]) Dfs(i,0);
	for (int i=1;i<=n;++i) if (cir[i]) {
		for (int j=1;j<=n;++j) if (cir[j]) {
			val[j]=-1;
			if (val2[j]<val1[j]) swap(val1[j],val2[j]);
		}
		val[i]=val1[i]; 
		int x=In[i],pre=i;
		do{
			if (val[pre]==val1[x]) val[x]=val2[x];
			else val[x]=val1[x];
			pre=x; x=In[x];
		}while (x!=In[i]);
		if (val1[i]==val[i]) { printf("POSSIBLE\n"); return ; }
		
		for (int j=1;j<=n;++j) if (cir[j]) val[j]=-1;
		val[i]=val2[i]; x=In[i],pre=i;
		do{
			if (val[pre]==val1[x]) val[x]=val2[x];
			else val[x]=val1[x];
			pre=x; x=In[x];
		}while (x!=In[i]);
		if (val2[i]==val[i]) { printf("POSSIBLE\n"); return ; }
		else { printf("IMPOSSIBLE\n"); return ; }
		break;
	}
}

int main() {
	Init();
	Solve();
	return 0;
}
```