spoj#PERMTGEN. Permutation Generator
Permutation Generator
Hasan Jaddouh has invented a new algorithm for generating permutations this algorithm takes an array with length N as input and generate a permutation with length N from this array.
the array must satsify (1 <= Ai <= i) in order for the resulting array to be a permutation.
and here is the pseudo code of the algorithm:
read N
for i=1 to N do
read A[i]
for i=1 to N do
for j=1 to i-1 do
if A[j] >= A[i] do
A[j]=A[j]+1
for i=1 to N do
print A[i]
but unfortunately for Hasan Jaddouh, his algorithm is too slow for big arrays so he asked you to help him to find a fast way to implement his algorithm.
your program should read input same as the pseudo code and output the new array
Input
first line contains integer N (1 <= N <= 105)
second line contains N integers separated by spaces each interger is between 1 and 109 inclusive
note: in order for Hasan Jaddouh's algorithm to work and generate a permutation the constrain (1 <= Ai <= i) must be satsified but to make this problem harder this constrian is not guaranteed so it's also not necessary that the output is a permutation.
Output
Output N integers separated by spaces, the new array after applying Hasan Jaddouh's algorithm
Example
Input:
4
4 2 1 3
Output:
7 4 1 3