This page is still under construction.

Parts of this page are still being built. What you see may change.

The Addition Game

Time limit1sMemory limit256 MB

Summary
Decide whether two permutations of 1 to n add up to the given sequence modulo n.
Level

Medium7 of 10

Topics
Math, Combinatorics
Solved
No attempts yet

Problem

Alan works at a company that specialises in computer security. He designed a public key cryptosystem in which the private key is a pair of permutations π\pi and σ\sigma of {1,…,n}\{1, \dots, n\}. The public key (a1,…,an)(a_1, \dots, a_n) is then given by ai≡πi+σi(modn)a_i \equiv \pi_i + \sigma_i \pmod n for 1≤i≤n1 \le i \le n. The notation x≡y(modn)x \equiv y \pmod n means that xx and yy leave the same remainder when divided by nn.

Take n=5n = 5 with

  • π=(3,1,5,2,4)\pi = (3, 1, 5, 2, 4),
  • σ=(5,1,3,4,2)\sigma = (5, 1, 3, 4, 2).

The public key is then a=(3,2,3,1,1)a = (3, 2, 3, 1, 1). For instance a5≡1≡4+2≡π5+σ5(mod5)a_5 \equiv 1 \equiv 4 + 2 \equiv \pi_5 + \sigma_5 \pmod 5, and each of π\pi and σ\sigma contains every number of {1,…,5}\{1, \dots, 5\} exactly once.

Alan's coworkers doubt that the system is secure, since any private key matching the public key breaks it. Help them out. Given nn and a sequence a=(a1,…,an)a = (a_1, \dots, a_n), decide whether there are permutations π\pi and σ\sigma of {1,…,n}\{1, \dots, n\} with πi+σi≡ai(modn)\pi_i + \sigma_i \equiv a_i \pmod n for every ii.

Input

The first line contains the length nn of the sequence (1≤n≤10001 \le n \le 1000).

The second line contains nn integers a1,…,ana_1, \dots, a_n (1≤ai≤n1 \le a_i \le n).

Output

Print possible if permutations π\pi and σ\sigma with the property above exist, and impossible otherwise.

Examples4

  1. Example 1

    Input
    5
    3 2 3 1 1
    
    Expected output
    possible
    
  2. Example 2

    Input
    4
    3 1 1 4
    
    Expected output
    impossible
    
  3. Example 3

    Input
    1
    1
    
    Expected output
    possible
    
  4. Example 4

    Input
    2
    1 2
    
    Expected output
    impossible