#P9947. [USACO20JAN] Photoshoot B
[USACO20JAN] Photoshoot B
Problem Description
Farmer John is lining up cows numbered to take a photo (). FJ originally planned that the cow with number would stand in the -th position from left to right, so he wrote down the permutation on a sheet of paper. Unfortunately, this sheet of paper has just been stolen by Farmer Nhoj!
Luckily, FJ still has a chance to recover the permutation he wrote earlier. Before the paper was stolen, Bessie recorded a sequence , where for each , we have .
Based on Bessie's information, help FJ recover the lexicographically smallest permutation that can produce the sequence . A permutation is lexicographically smaller than a permutation if there exists some such that for all , , and (in other words, the two permutations are the same up to some position, and at that position is smaller than ). It is guaranteed that at least one valid exists.
Input Format
The first line contains an integer .
The second line contains space-separated integers .
Output Format
Output one line containing space-separated integers .
5
4 6 7 6
3 1 5 2 4
Hint
Sample Explanation 1
The sequence can produce because , , , .
Test Point Properties
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5