Problem:
Score : 700 points

Problem Statement

Aoki loves numerical sequences and trees.

One day, Takahashi gave him an integer sequence of length N, a_1, a_2, ..., a_N, which made him want to construct a tree.

Aoki wants to construct a tree with N vertices numbered 1 through N, such that for each i = 1,2,...,N, the distance between vertex i and the farthest vertex from it is a_i, assuming that the length of each edge is 1.

Determine whether such a tree exists.

Constraints

2 ≦ N ≦ 100

1 ≦ a_i ≦ N-1

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If there exists a tree that satisfies the condition, print Possible. Otherwise, print Impossible.

Sample Input 1

5
3 2 2 3 3

Sample Output 1

Possible

The diagram above shows an example of a tree that satisfies the conditions. The red arrows show paths from each vertex to the farthest vertex from it.

Sample Input 2

3
1 1 2

Sample Output 2

Impossible

Sample Input 3

10
1 2 2 2 2 2 2 2 2 2

Sample Output 3

Possible

Sample Input 4

10
1 1 2 2 2 2 2 2 2 2

Sample Output 4

Impossible

Sample Input 5

6
1 1 1 1 1 5

Sample Output 5

Impossible

Sample Input 6

5
4 3 2 3 4

Sample Output 6

Possible

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const ll mod = 100003;
const int cons = 100001;
const double pi = 3.141592653589793;

vector <int> rem[100];
vector <int> used[100];
int parent[101];
vector < vector <int> > adj;
int root;

int main()
{
	int n;
	scanf("%d", &n);

	int maxlen = 0;

	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		rem[x].push_back(i);

		maxlen = max(maxlen, x);
	}

	int rootlen = (maxlen + 1) / 2;

	adj.resize(n + 1);

	root = -1;
	for (int i = n - 1; i >= 0; i--)
	{
		int sz = rem[i].size();
		while (sz--)
		{
			int u = rem[i].back();
			rem[i].pop_back();
			used[i].push_back(u);
			sz--;
			int cur = i;

			while (rootlen < cur)
			{
				if (rem[cur - 1].size())
				{
					int v = rem[cur - 1].back();
					rem[cur - 1].pop_back();
					used[cur - 1].push_back(v);

					parent[u] = v;
					adj[v].push_back(u);
				}
				else if (used[cur - 1].size())
				{
					int v = used[cur - 1].back();
					parent[u] = v;
					adj[v].push_back(u);
					break;
				}
				else
				{
					puts("Impossible");
					return 0;
				}
			}
		}
	}

	if (maxlen % 2 == 0)
	{
		if (used[rootlen].size() > 1)
		{
			puts("Impossible");
			return 0;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (rem[i].size())
		{
			puts("Impossible");
			return 0;
		}
	}

	puts("Possible");

	return 0;
}