#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int a[401000],in[401000];
int h[401000],q[401000],nxt[401000],to[401000],K=0;
bool b[401000];int c[401000];
int ri[401000],len=0;
vector<int> v[401000];
void ins(int u,int v){nxt[++K]=h[u];h[u]=K;to[K]=v;}
int getsg(int u)
{
	for(int i=h[u];i;i=nxt[i])
		if(in[to[i]]<=0)b[a[to[i]]]=1;
	if(b[0]==0)return 0;
	for(int i=1;i<=200000;i++)if(!b[i])return i;
}
void Memset(int u)
{
	for(int i=h[u];i;i=nxt[i])
		if(in[to[i]]<=0)b[a[to[i]]]=0;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int p;scanf("%d",&p);ins(i,p);ins(p,i);in[p]++; 
		v[p].push_back(i);
	}
	int H=0,T=0;
	for(int i=1;i<=n;i++)if(!in[i])q[T++]=i,a[i]=0;
	while(H<T)
	{
		int u=q[H++];a[u]=getsg(u);Memset(u);
		for(int i=h[u];i;i=nxt[i])
		{
			in[to[i]]--;
			if(in[to[i]]==0)q[T++]=to[i];
		}
	}
	for(int i=1;i<=n;i++)if(in[i]==1){ri[++len]=i;}
	memset(h,0,sizeof(h));K=0;
	for(int i=1;i<=len;i++)
	{
		int SIZ=v[ri[i]].size();
		for(int j=0;j<SIZ;j++)ins(ri[i],v[ri[i]][j]);
	}
	for(int i=2;i<=len;i++)
	{
		for(int j=h[ri[i-1]];j;j=nxt[j])if(in[to[j]]==1){ri[i]=to[j];break;}
	}
	memset(in,0,sizeof(in));
	for(int i=1;i<=n;i++)c[i]=a[i];
	int o;in[ri[2]]++;a[ri[1]]=getsg(ri[1]);o=a[ri[1]];Memset(ri[1]);in[ri[2]]--;
	for(int i=len;i>=2;i--)
	{
		a[ri[i]]=getsg(ri[i]);Memset(ri[i]);
	}
	if(a[ri[2]]!=a[ri[1]]){puts("POSSIBLE");return 0;}
	for(int i=1;i<=n;i++)a[i]=c[i];
	a[ri[2]]=o;a[ri[1]]=getsg(ri[1]);Memset(ri[1]);
	for(int i=len;i>=3;i--)
	{
		a[ri[i]]=getsg(ri[i]);Memset(ri[i]);
	}
	if(getsg(ri[2])==o){puts("POSSIBLE");return 0;}
	puts("IMPOSSIBLE");
	return 0;
}//缩成一个环和环往外连的几个点 ，对于环上某一个点， 要么它取mex，要么它前一个点取mex 
### 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<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int a[401000],in[401000];
int h[401000],q[401000],nxt[401000],to[401000],K=0;
bool b[401000];int c[401000];
int ri[401000],len=0;
vector<int> v[401000];
void ins(int u,int v){nxt[++K]=h[u];h[u]=K;to[K]=v;}
int getsg(int u)
{
	for(int i=h[u];i;i=nxt[i])
		if(in[to[i]]<=0)b[a[to[i]]]=1;
	if(b[0]==0)return 0;
	for(int i=1;i<=200000;i++)if(!b[i])return i;
}
void Memset(int u)
{
	for(int i=h[u];i;i=nxt[i])
		if(in[to[i]]<=0)b[a[to[i]]]=0;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int p;scanf("%d",&p);ins(i,p);ins(p,i);in[p]++; 
		v[p].push_back(i);
	}
	int H=0,T=0;
	for(int i=1;i<=n;i++)if(!in[i])q[T++]=i,a[i]=0;
	while(H<T)
	{
		int u=q[H++];a[u]=getsg(u);Memset(u);
		for(int i=h[u];i;i=nxt[i])
		{
			in[to[i]]--;
			if(in[to[i]]==0)q[T++]=to[i];
		}
	}
	for(int i=1;i<=n;i++)if(in[i]==1){ri[++len]=i;}
	memset(h,0,sizeof(h));K=0;
	for(int i=1;i<=len;i++)
	{
		int SIZ=v[ri[i]].size();
		for(int j=0;j<SIZ;j++)ins(ri[i],v[ri[i]][j]);
	}
	for(int i=2;i<=len;i++)
	{
		for(int j=h[ri[i-1]];j;j=nxt[j])if(in[to[j]]==1){ri[i]=to[j];break;}
	}
	memset(in,0,sizeof(in));
	for(int i=1;i<=n;i++)c[i]=a[i];
	int o;in[ri[2]]++;a[ri[1]]=getsg(ri[1]);o=a[ri[1]];Memset(ri[1]);in[ri[2]]--;
	for(int i=len;i>=2;i--)
	{
		a[ri[i]]=getsg(ri[i]);Memset(ri[i]);
	}
	if(a[ri[2]]!=a[ri[1]]){puts("POSSIBLE");return 0;}
	for(int i=1;i<=n;i++)a[i]=c[i];
	a[ri[2]]=o;a[ri[1]]=getsg(ri[1]);Memset(ri[1]);
	for(int i=len;i>=3;i--)
	{
		a[ri[i]]=getsg(ri[i]);Memset(ri[i]);
	}
	if(getsg(ri[2])==o){puts("POSSIBLE");return 0;}
	puts("IMPOSSIBLE");
	return 0;
}//缩成一个环和环往外连的几个点 ，对于环上某一个点， 要么它取mex，要么它前一个点取mex 
```