Problem A
Distributing Levels
Rare Candies are one of the scarcest resource in all of Pokemon, for a very good reason. They have the incredibly potent ability to raise a Pokemon’s level by $1$. They were seemingly impossible to mass produce until you stumbled upon a secret item that had never before been seen in Pokemon: the Common Candy. By feeding a Pokemon a Common Candy, its level will decrease by $1$, but a Rare Candy will be produced that you can use to raise any Pokemon’s level. As Pokemon’s levels are always between $1$ and $100$, you cannot feed a Common Candy to a Pokemon with level $1$ or a Rare Candy to a Pokemon with level $100$.
You have $N$ Pokemon that each start at a level between $1$ and $100$ (inclusive). You want them all to be very strong, so you line them up in some order and go through them one by one in order until you reach the end of the line, repeating a specific process once per Pokemon as follows:
-
If the current Pokemon is at level $1$, skip the following steps and move on to the next Pokemon since you cannot feed it a Common Candy.
-
Otherwise, feed the current Pokemon a Common Candy, which will lower its level by $1$ and produce a Rare Candy.
-
You then feed that Rare Candy to the Pokemon in the line that has the lowest level at the moment (it might be the current Pokemon you just fed a Common Candy to). If there are multiple Pokemon with the lowest level, you may pick any of them to feed the Rare Candy to.
After completing this process, you notice that the levels of your $N$ Pokemon are now $L_1, L_2, \dots , L_ N$, in no particular order. You suspect that a crafty Meowth might have tampered with your perfect system by feeding some Pokemon extra candies to mess things up, and you need to determine if any sabotage took place by checking if $L_1, L_2, \dots , L_ N$ are a possible outcome of the described process, given that your Pokemon started at various levels between $1$ and $100$.
Input
The first line of the input consists of an integer $N$. This denotes the number of Pokemon ($1 \leq N \leq 10^6$). The second line of the input consists of $N$ space-separated integers $L_1, L_2, \dots , L_ N$. These denote the level of each Pokemon ($1 \leq L_ i \leq 100$) after you complete the described process.
Output
Output possible if $L_1, L_2, \dots , L_ n$ are a possible outcome of the described process, otherwise output impossible.
Sample Input 1 | Sample Output 1 |
---|---|
2 6 4 |
possible |
Sample Input 2 | Sample Output 2 |
---|---|
5 4 4 5 7 7 |
possible |
Sample Input 3 | Sample Output 3 |
---|---|
10 3 4 7 7 7 7 7 7 7 7 |
impossible |