Given an array a of length n, find another array, b, of length n such that: for each i (1≤i≤n) MEX({b1, b2, …, bi})=ai. The MEX of a set of integers is the smallest non-negative integer that doesn’t belong to this set. If such array doesn’t exist, determine this.
Input
The first line contains an integer n (1≤n≤105) — the length of the array a. The second line contains n integers a1, a2, …, an (0≤ai≤i) — the elements of the array a. It’s guaranteed that ai≤ai+1 for 1≤i<n.
Output
If there’s no such array, print a single line containing −1. Otherwise, print a single line containing n integers b1, b2, …, bn (0≤bi≤106) If there are multiple answers, print any.
Examples
inputCopy 3 1 2 3 outputCopy 0 1 2 inputCopy 4 0 0 0 2 outputCopy 1 3 4 0 inputCopy 3 1 1 3 outputCopy 0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
我们可以将a[]中没有的数放入一个小根堆中,每次输出堆顶元素,然后移除堆顶元素。如果a[]中某个元素已经没有了,那么就将该元素再放入堆中。