History of OI -> II OI 1994/1995 -> Problems

 News About Olympic History of OI XVII OI 2009/2010 XVI OI 2008/2009 XV OI 2007/2008 XIV OI 2006/2007 XIII OI 2005/2006 XII OI 2004/2005 XI OI 2003/2004 X OI 2002/2003 IX OI 2001/2002 VIII OI 2000/2001 VII OI 1999/2000 VI OI 1998/1999 V OI 1997/1998 IV OI 1996/1997 III OI 1995/1996 II OI 1994/1995 Stage III - results Stage I - results Problems I OI 1993/1994 OI books National team Olympic camps Photo gallery Links SIO MAIN
Niebieskie ksi.eczki

The Coding of Permutations

 III stage contest

Every permutation A = (a1, ..., an) of numbers 1, ..., n can be coded by a sequence B = (b1, ..., bn) in which bi equals the number of all aj such that (j < i & aj > ai), for i = 1, ..., n.

### Example

The sequence B = (0, 0, 1, 0, 2, 0, 4) is the code of the permutation A = (1, 5, 2, 6, 4, 7, 3).

Write a program that:
• reads from the text file KOD.IN the length n and successive elements of the sequence B,
• examines whether it is a code of some permutation of numbers 1, ..., n,
• if so, it finds that permutation and writes it in the text file KOD.OUT,
• otherwise it writes in the file KOD.OUT one word NIE ("no").

### Input

• In the first line of the text file KOD.IN there is a positive integer n <= 30000. It is the number of elements of the sequence B.
• In each of the following n lines there is one nonnegative integer not greater than 30000. It is the successive element of the sequence B.

### Output

The file KOD.OUT should contain:
• in each of n consecutive lines - one element of the permutation A, whose code is the sequence B written in the file KOD.IN,
• one word NIE, if the sequence B is not a code of any permutation.

### Examples

For the file KOD.IN:
```7
0
0
1
0
2
0
4
```
the file KOD.OUT should contain:
```1
5
2
6
4
7
3
```

For the file KOD.IN:

```4
0
2
0
0
```
the file KOD.OUT should contain:
```NIE
```

Your program should look for the file KOD.IN in the current directory and create the file KOD.OUT also in the current directory. The source file containing the program written by you should be named KOD.???, where ??? are substituted by at most three-letter abbreviation of the programming language used. The same program in an executable form should be written in a file KOD.EXE.

Print friendly version