#include<cstdio>
const int MaxN=200010;
int N,p[MaxN],deg[MaxN],stk[MaxN];
struct edge{int to;edge*next;}E[MaxN],*fir[MaxN];
bool vis[MaxN];
int f[MaxN][2],cir[MaxN],len,nxt[MaxN*2];
int dfn[MaxN*2],now=1;
void work(){
	
	for(int i=1;i<=N;i++){
		scanf("%d",p+i);
		deg[p[i]]++;
		E[i]=(edge){i,fir[p[i]]};
		fir[p[i]]=E+i;
	}
	int*tp=stk;
	for(int i=1;i<=N;i++)if(!deg[i])*tp++=i;
	while(tp>stk){
		int x=*--tp;
		for(edge*e=fir[x];e;e=e->next)vis[*f[e->to]]=1;
		while(vis[*f[x]])++*f[x];
		for(edge*e=fir[x];e;e=e->next)vis[*f[e->to]]=0;
		if(!--deg[p[x]])*tp++=p[x];
	}
	int o=0;
	for(int i=1;!o;i++)if(deg[i])o=i;
	for(int i=o;;){
		cir[len++]=i;
		for(edge*e=fir[i];e;e=e->next)if(!deg[e->to])vis[*f[e->to]]=1;
		while(vis[*f[i]])++*f[i];
		for(f[i][1]=*f[i]+1;vis[f[i][1]];++f[i][1]);
		for(edge*e=fir[i];e;e=e->next)if(!deg[e->to])vis[*f[e->to]]=0;
		if((i=p[i])==o)break;
	}
	for(int i=0;i<len;i++){
		nxt[i]=(i+1)%len+(f[cir[i]][0]==f[cir[(i+1)%len]][0])*len;
		nxt[i+len]=(i+1)%len+(f[cir[i]][1]==f[cir[(i+1)%len]][0])*len;
	}
	for(int i=0;i<len;i++){
		int la=now,x=i,mv=now;
		while(!dfn[x]){
			dfn[x]=now++;
			if(x<len)mv=dfn[x];
			x=nxt[x];
		}
		if(dfn[x]>=la&&now-dfn[x]==len&&mv>=dfn[x]){
			puts("POSSIBLE");
			return;
		}
	}
	puts("IMPOSSIBLE");
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(scanf("%d",&N)==1){
		for(int i=1;i<=N;i++)fir[i]=0,deg[i]=*f[i]=dfn[i-1]=dfn[i+N-1]=0;
		now=1;len=0;
		work();
	}
}
### Prompt

Please create a solution in Cpp 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<cstdio>
const int MaxN=200010;
int N,p[MaxN],deg[MaxN],stk[MaxN];
struct edge{int to;edge*next;}E[MaxN],*fir[MaxN];
bool vis[MaxN];
int f[MaxN][2],cir[MaxN],len,nxt[MaxN*2];
int dfn[MaxN*2],now=1;
void work(){
	
	for(int i=1;i<=N;i++){
		scanf("%d",p+i);
		deg[p[i]]++;
		E[i]=(edge){i,fir[p[i]]};
		fir[p[i]]=E+i;
	}
	int*tp=stk;
	for(int i=1;i<=N;i++)if(!deg[i])*tp++=i;
	while(tp>stk){
		int x=*--tp;
		for(edge*e=fir[x];e;e=e->next)vis[*f[e->to]]=1;
		while(vis[*f[x]])++*f[x];
		for(edge*e=fir[x];e;e=e->next)vis[*f[e->to]]=0;
		if(!--deg[p[x]])*tp++=p[x];
	}
	int o=0;
	for(int i=1;!o;i++)if(deg[i])o=i;
	for(int i=o;;){
		cir[len++]=i;
		for(edge*e=fir[i];e;e=e->next)if(!deg[e->to])vis[*f[e->to]]=1;
		while(vis[*f[i]])++*f[i];
		for(f[i][1]=*f[i]+1;vis[f[i][1]];++f[i][1]);
		for(edge*e=fir[i];e;e=e->next)if(!deg[e->to])vis[*f[e->to]]=0;
		if((i=p[i])==o)break;
	}
	for(int i=0;i<len;i++){
		nxt[i]=(i+1)%len+(f[cir[i]][0]==f[cir[(i+1)%len]][0])*len;
		nxt[i+len]=(i+1)%len+(f[cir[i]][1]==f[cir[(i+1)%len]][0])*len;
	}
	for(int i=0;i<len;i++){
		int la=now,x=i,mv=now;
		while(!dfn[x]){
			dfn[x]=now++;
			if(x<len)mv=dfn[x];
			x=nxt[x];
		}
		if(dfn[x]>=la&&now-dfn[x]==len&&mv>=dfn[x]){
			puts("POSSIBLE");
			return;
		}
	}
	puts("IMPOSSIBLE");
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(scanf("%d",&N)==1){
		for(int i=1;i<=N;i++)fir[i]=0,deg[i]=*f[i]=dfn[i-1]=dfn[i+N-1]=0;
		now=1;len=0;
		work();
	}
}
```