#include<cstdio>
using namespace std;
const int N=200200;
int i,j,k,n,m,ch,x,En;
int a[N],b[N],f[N],fa[N],z[N],h[N],d[N],du[N],sz[N];
struct edge { int s,n;} E[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
}
void dfs(int x) {
	for (int k=h[x];k;k=E[k].n) if (du[E[k].s]!=1) dfs(E[k].s);
	for (int k=h[x];k;k=E[k].n) if (du[E[k].s]!=1) z[a[E[k].s]]=x;
	a[x]=0;
	while (z[a[x]]==x) a[x]++;
	if (du[x]==1) {
		b[x]=a[x]+1;
		while (z[b[x]]==x) b[x]++;
	}
}
int main() {
	R(n);
	for (i=1;i<=n;i++) {
		R(x);du[x]++;fa[i]=x;
		E_add(x,i);
	}
	for (i=1;i<=n;i++) if (du[i]==0) d[++j]=i;
	i=0;
	while (i<j) {
		i++;
		if (--du[fa[d[i]]]==0) d[++j]=fa[d[i]];
	}
	for (i=1;i<=n;i++) if (du[i]==1) dfs(i);
	j=0;
	for (i=1;i<=n;i++) if (du[i]==1) break;
	d[++j]=i;
	i=0;
	while (i<j) {
		i++;
		for (k=h[d[i]];k;k=E[k].n) if (du[E[k].s]==1 && E[k].s!=d[1]) d[++j]=E[k].s;
	}
	f[d[j]]=a[d[j]];
	for (i=j-1;i;i--) {
		if (a[d[i]]==f[d[i+1]]) f[d[i]]=b[d[i]];
		else f[d[i]]=a[d[i]];
	}
	if (f[d[1]]!=f[d[j]]) return puts("POSSIBLE"),0;
	f[d[j]]=b[d[j]];
	for (i=j-1;i;i--) {
		if (a[d[i]]==f[d[i+1]]) f[d[i]]=b[d[i]];
		else f[d[i]]=a[d[i]];
	}
	if (f[d[1]]==a[d[j]]) return puts("POSSIBLE"),0;
	puts("IMPOSSIBLE");
}
### Prompt

Please provide a CPP coded solution to the problem described below:

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>
using namespace std;
const int N=200200;
int i,j,k,n,m,ch,x,En;
int a[N],b[N],f[N],fa[N],z[N],h[N],d[N],du[N],sz[N];
struct edge { int s,n;} E[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
}
void dfs(int x) {
	for (int k=h[x];k;k=E[k].n) if (du[E[k].s]!=1) dfs(E[k].s);
	for (int k=h[x];k;k=E[k].n) if (du[E[k].s]!=1) z[a[E[k].s]]=x;
	a[x]=0;
	while (z[a[x]]==x) a[x]++;
	if (du[x]==1) {
		b[x]=a[x]+1;
		while (z[b[x]]==x) b[x]++;
	}
}
int main() {
	R(n);
	for (i=1;i<=n;i++) {
		R(x);du[x]++;fa[i]=x;
		E_add(x,i);
	}
	for (i=1;i<=n;i++) if (du[i]==0) d[++j]=i;
	i=0;
	while (i<j) {
		i++;
		if (--du[fa[d[i]]]==0) d[++j]=fa[d[i]];
	}
	for (i=1;i<=n;i++) if (du[i]==1) dfs(i);
	j=0;
	for (i=1;i<=n;i++) if (du[i]==1) break;
	d[++j]=i;
	i=0;
	while (i<j) {
		i++;
		for (k=h[d[i]];k;k=E[k].n) if (du[E[k].s]==1 && E[k].s!=d[1]) d[++j]=E[k].s;
	}
	f[d[j]]=a[d[j]];
	for (i=j-1;i;i--) {
		if (a[d[i]]==f[d[i+1]]) f[d[i]]=b[d[i]];
		else f[d[i]]=a[d[i]];
	}
	if (f[d[1]]!=f[d[j]]) return puts("POSSIBLE"),0;
	f[d[j]]=b[d[j]];
	for (i=j-1;i;i--) {
		if (a[d[i]]==f[d[i+1]]) f[d[i]]=b[d[i]];
		else f[d[i]]=a[d[i]];
	}
	if (f[d[1]]==a[d[j]]) return puts("POSSIBLE"),0;
	puts("IMPOSSIBLE");
}
```