Problem:
 Score : 400 points    Problem Statement Snuke has an empty sequence a .  He will perform N operations on this sequence.  In the i -th operation, he chooses an integer j satisfying 1 \leq j \leq i , and insert j at position j in a (the beginning is position 1 ).  You are given a sequence b of length N . Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.      Constraints  All values in input are integers.  1 \leq N \leq 100  1 \leq b_i \leq N         Input Input is given from Standard Input in the following format:  N  b_1  \dots  b_N       Output If there is no sequence of N operations after which a would be equal to b , print -1 .
If there is, print N lines. In the i -th line, the integer chosen in the i -th operation should be printed. If there are multiple solutions, any of them is accepted.        Sample Input 1 3
1 2 1      Sample Output 1 1
1
2  In this sequence of operations, the sequence a changes as follows:   After the first operation: (1)  After the second operation: (1,1)  After the third operation: (1,2,1)        Sample Input 2 2
2 2      Sample Output 2 -1  2 cannot be inserted at the beginning of the sequence, so this is impossible.       Sample Input 3 9
1 1 1 2 2 1 2 3 2      Sample Output 3 1
2
2
3
1
2
2
1
1

Solution (Python):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

n = read_int()[0]
B = read_int()

def solve():
    for i in range(n):
        if B[i] > i + 1:
            print(-1)
            return

    res = []
    for i in range(n):
        app = 0
        index = 0
        for j in range(len(B)):
            if B[j] == j + 1:
                app = max(app, B[j])
                index = j
        B.pop(index)
        res.append(app)

    for i in range(n):
        print(res[n - 1 - i])
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
B = list(map(int,input().split()))

copy = B[:]
ans = []
def func():
    while any(B):
        for i in range(N-1,-1,-1):
            if B[i] == 1:
                ans.append(copy[i])
                for j in range(i,N):
                    if B[j] > 0:
                        B[j] -= 1
                break
            elif i == 0:
                return

func()

if any(B):
    print(-1)
else:
    for a in ans:
        print(a)

Solution (Python):
N = int( input())
B = list( map( int, input().split()))
C = [0]*(N+1)
ans = 0
for i in range(N):
    if B[i] > i+1:
        ans = -1
        break
ANS = []
if ans == 0:
    for i in range(1, N+1):
        L = []
        for j in range(N):
            if 1 <= B[j] <= i:
                L.append(B[j])
        now = i-1
        for s in L[::-1]:
            if s == i:
                ANS.insert(now,i)
            now += 1
if ans == -1:
    print(-1)
else:
    for i in range(N):
        print(ANS[i])

Solution (Python):

import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N = int(input())
        B = np.asarray(list(map(int, input().split())))
    else:
        pass
    A = np.asarray(range(N))
    A += 1
    res = np.asarray([])
    for _ in range(N):
        for i in range(B.size)[::-1]:
            if A[i] == B[i]:
                res = np.append(res,A[i])
                
                B = B[A[:B.size]!=A[i]]
                break
        else:
            print(-1)
            exit()
    
    for i in range(N)[::-1]:
        print(int(res[i]))

if __name__ =='__main__':
    main()

Solution (Python):
N = int(input())
b = [int(x) for x in input().split()]
ans = []
maker = 0
for i in range(N):
    if b[i] > i+1:
        maker = -1
        break
if maker < 0:
    print(-1)
else:     
    for i in range(N):
        for j in range(N-i):
            if b[j] == j + 1:
                x = j + 1
        ans.append(x)
        b.pop(x-1)

    for i in range(N):
        print(ans[-i-1])

Solution (Python):
N = int(input())
b = [int(x) for x in input().split()]
ans = []
while len(b) > 1:
    tmp = max(b)
    flag = 0
    if tmp > len(b):
        ans = None
        break
    while flag == 0:
        if b[tmp-1] == tmp: 
            ans.append(b.pop(tmp-1))
            flag = 1
        else:
            tmp -= 1
        if tmp == 0:
            flag = -1
            break
    if flag == -1:
        ans = None
        break

if ans == None or b[0] != 1:
    print(-1)
else: 
    ans.append(1)
    for i in ans[::-1]:
        print(i)

Solution (Python):
"""
A - Limited Insertion
"""


def solve():
    N = int(input())
    b = list(map(int, input().split()))
    ans = make_list(b, 0, [])

    if ans == -1:
        print(ans)
    else:
        for a in list(reversed(ans)):
            print(a)
        
        
        


def make_list(b: list, x: int, ans: list):
    re = -1
    
    

    if len(b) == 0:
        return ans

    if check_list(b) is False:
        return re

    for i, element in enumerate(b, 1):
        if i == element:
            b_c = b.copy()
            ans_c = ans.copy()
            ans_c.append(b_c[i - 1])
            b_c.remove(element)  
            
            
            tmp = make_list(b_c, x + 1, ans_c)
            if tmp != -1:
                re = tmp
                break
    
    return re


def check_list(b):
    re = True
    for i, element in enumerate(b, 1):
        if i < element:
            re = False
            break
    return re


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np



N = int(input())

b = np.zeros(N)
b = input().split()
for i in range(N):
    b[i] = int(b[i])



error = 0
for i in range(N):
    if b[i] > i+1:
        error += 1

if error != 0:
    print(-1)
else:
    c = []
    while len(b) > 1:
        for i in range(len(b)-1,-1,-1):
            if b[i] == i+1:
                c.append(b.pop(i))
                break
    c.append(1)
    c.reverse()
    for i in range(N):
        print(c[i])

Solution (Python):
N = int(input())
b_list = list(map(int, input().split()))
ans = []
while b_list:
    for i, b in enumerate(b_list):
        if i+1 == b:
            next_i = i
        if i+1 < b:
            print(-1)
            exit()
    ans.append(b_list.pop(next_i))
for i in reversed(ans):
    print(i)

Solution (Python):





"""
gc032 A
"""

from collections import Counter

n = int(input())
bli = list(map(int, input().split()))
cli = bli.copy()
cli.reverse()
dli = []

for i in range(1, n+1):
    if 1 in cli:
        x = cli.index(1)
        for j in range(0, x+1):
            cli[j] -= 1
    else:
        print(-1)
        quit()
    dli.append(bli[n-1-x])

for i in dli:
    print(i)

Solution (Python):
n= int(input())
s = input()
num = [int(s) for s in s.split(" ")]
ans=[]

while(True):
  ch = False
  for i in reversed(range(len(num))):
    if num[i] == i+1:
      ch = True
      del num[i]
      ans.append(i+1)
      break
  if not ch:
    break
if len(num)==0:
  for i in reversed(ans):
    print(i)
else:
  print("-1")

Solution (Python):


N = int(input())

B = [int(i) for i in input().split()]

ans = []

while (len(B) > 0):
  for _ in range(len(B)):
    for i in list(range(len(B)))[::-1]:
      if B[i] == i+1:
        ans.append(i+1)
        B.pop(i)
        break
  break

if len(ans) != N:
  print(-1)
else:
  for i in ans[::-1]:
    print(i)

Solution (Python):
N = int(input())
b = []
c = [0]*N
count_flag=0
b = list(map(int, input().split()))

for count in range(N):
  for i in range(N-count):
    if count_flag == count and b[N-1-count-i]==N-1-count-i+1 :
      c[N-1-count]=N-1-count-i+1
      b.pop(N-1-count-i)
      count_flag+=1
if count_flag == N:
  for i in range(N):
    print(c[i])
else:print(-1)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))


def fast():
    candidate = list()
    
    while len(b) != 0:
        for i in range(len(b))[::-1]:
            if b[i] == (i+1):
                value = b.pop(i)
                candidate.append(value)
                break
            
        else:
            return [-1]

    candidate.reverse()
    return candidate

ans_list = fast()
for ans in ans_list:
    print(ans)

Solution (Python):
N = int(input())
bs = [int(i) for i in input().split()]
cs = bs.copy()
f = [False for i in range(N)]

def solve():
    ans = []
    i = N - 1
    while i >= 0:
        if f[i]:
            i -= 1
            continue
        
        if cs[i] == 1:
            ans.append(bs[i])
            f[i] = True
            i -= 1
        elif cs[i] < 1:
            return []
        else:
            j = i
            flg = True
            while j >= 0:
                if f[j]:
                    j -= 1
                    continue
                if cs[j] == 1:
                    ans.append(bs[j])
                    f[j] = True
                    flg = False
                    break
                else:
                    cs[j] -= 1
                    j -= 1
            if flg:
                return []
    return ans

ans = solve()
if len(ans) == 0:
    print(-1)
else:
    print(*ans, sep='\n')

Solution (Python):
import sys

l = raw_input().split()
N = int(l[0])
B = [int(b) for b in raw_input().split()]

for i in range(N):
    if B[i] > i + 1:
        print(-1)
        exit()


ret = []
i = N
while i > 0:
    found = False
    for j in range(i):
        a = i - 1 - j
        
        if B[a] - 1 >= a:
            
            ret.append(B[a])
            del B[a]
            found = True
            break
    if not found:
        print(-1)
        exit()
    i -= 1

for i in range(N):
    print(ret[N - 1 - i])

Solution (Python):
    
N = int(input())
b = list(map(int,input().split()))
a = [0]*N

aequalb = True
for i in reversed(range(1, N+1)):
    for j in reversed(range(1,i+1)):
        if b[j-1] == j:
            a[N-i] = b.pop(j-1)
            break
        elif j == 1:
            aequalb = False
    if aequalb == False:
        break

if aequalb:
    for i in range(N):
        print(a[N-1-i]) 
else:
    print(-1)

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        
        if a[i] == i+1:
            l.append(a.pop(i))
            break
if len(l) == N:
    print("\n".join(map(str,reversed(l))))
else:
    print(-1)

Solution (Python):
n = int(input())
ls = [int(i) for i in input().split()]
ans = [0]*n    
if len(ls) >= n:
    for i in range(n,0,-1):
        for j in range(i,0,-1):
            if ls[j-1] == j:
                ls.remove(j)
                ans[i-1] = j
                break
if ls == []:
    for s in range(len(ans)):
        print(ans[s])
else:
    print(-1)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

check = True
for i in range(n):
    if a[i] > i+1:
        check = False
if check:
    ans = []
    for i in range(n):
        temp = 0
        tempindex = 0
        for k in range(len(a)):
            if k+1 == a[k]:
                temp = a[k]
                tempindex = k
        ans.append(temp)
        a.pop(tempindex)

    ans.reverse()
    for i in range(n):
        print(ans[i])
else:
    print("-1")

Solution (Python):
def solve():
    n = int(input())
    B = [0] + list(map(int, input().split()))
    ans = []
    for i in range(n):
        t = 0
        for j in range(1, n - i + 1):
            if B[j] == j:
                t = j
        if t == 0:
            return [-1]
        else:
            ans.append(t)
            del B[t]
    return ans[::-1]
print(*solve(), sep="\n")

Solution (Python):
N=int(input().strip())
b=list(map(int,input().split()))

anslist=[]
for _ in range(N):
    for i in reversed(range(len(b))):
        if i+1==b[i]:
            anslist.append(b[i])
            del b[i]
            
            
            break
if len(b)==0:
    for i in reversed(range(len(anslist))):
        print(anslist[i])
else:
    print("-1")

Solution (Python):
def solve():
    N=int(input())
    b=list(map(int,input().split()))
    for i,bi in enumerate(b):
        if bi>i+1:
            print(-1)
            return
    ans=[]
    for bi in b:
        ans.insert(bi-1,bi)
    for a in ans:
        print(a)

solve()

Solution (Python):





n=int(input())
li=list(map(int,input().split()))
check=0
ans=[]
for m in range(n):
    if li[m]<=m+1:
        continue
    else:
        print(-1)
        check=1
        break
if check==0:
    box=[]
    for i in range(n):
        for j in range(n-i):
            if li[j]==j+1:
                box.append(j+1)
        flag=0
        while flag==0:
            if box[-1]<len(li):
                if li[box[-1]-1]==li[box[-1]]:
                    box[-1]+=1
                    continue
                else:
                    flag=1
            else:
                flag=1
        li_a=li[:box[-1]-1]
        li_b=li[box[-1]:]
        ans.append(li[box[-1]-1])
        li=li_a+li_b
    for i in range(n):
        print(ans.pop())

Solution (Python):
def main():
    
    n = int(input())

    B = input().split()

    for i in range(0,n):
            B[i]=int(B[i])

    prints=[]

    while len(B)>0:

        

        for i in range(len(B)-1, -1, -1):

            if B[i]-i == 1:

                prints.append(B[i])
                B = B[:i] + B[i+1:]
                break
        
        else:

            print(-1)
            return

    for i in range(n-1,-1,-1):

        print(prints[i])

    return

main()

Solution (Python):
N = int(input())
b = [int(x) for x in str(input()).split(' ')]

out = []
for i, x in enumerate(b):
    if x > i+1:
        out = [-1]
        break
    else:
        out.insert(x-1, x)

for x in out:
    print(x)

Solution (Python):
N = int(input())
B = list(map(int,input().split()))

for i in range(N):
    if i+1 < B[i]:
        print(-1)
        exit()

ans = []
for i in range(N):
    b = B[i]
    ans.insert( b-1, b)

for a in ans:
    print(a)

Solution (Python):
import sys

n = int(input())
b = list(map(int, input().split()))

c = list()

for i in range(n, 0, -1):
    for j in range(i):
        if b[i - j - 1] == i - j:
            c.insert(0, b[i - j - 1])
            del b[i - j - 1]
            break
        if i == j + 1:
            print(-1)
            sys.exit()

for i in c:
    print(i)

Solution (Python):

n = int(input())
b = [int(i) for i in input().split()]
ans = []
for j in range(n):
    for i in range(len(ans),n):
        if b[n-i-1] == n-i:
            ans.append(b.pop(n-i-1))
            break
if len(b) > 0:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Solution (Python):
n = int(input())
b = [int(i) for i in input().split()]
isContinue = True
res = []
isContinue = True
while isContinue and len(b)>0:
    tmp = 0
    for i in range(len(b)):
        if b[i] == i + 1:
            tmp = i + 1
    if tmp == 0:
        print(-1)
        isContinue = False
        break
    res.append(b.pop(tmp - 1))
if len(res) == n:
    for i in range(1, n + 1):
        print(res[-i])

Solution (Python):




def main():
    N = int(input())
    b = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in reversed(range(len(b))):
            if b[j]==j+1:
                ans.append(j+1)
                b = b[:j] + b[j+1:]
                
                break
    if len(ans)!=N:
        print(-1)
    else:
        for elem in reversed(ans):
            print(elem)



if __name__ == '__main__':
    main()

Solution (Python):

"""
Created on Sat Mar 23 21:42:28 2019

@author: Yamazaki Kenichi
"""
import sys

N = int(input())
B = list(map(int,input().split()))

for i in range(N):
    if B[i] > i+1:
        print(-1)
        sys.exit()
ans = []
def a(B):
    for i in range(1,len(B)+1):
        if B[-i] == len(B)+1-i:
            ans.append(B[-i])

            del B[-i]
            a(B)
            return
a(B)
ans.reverse()
for c in ans:
    print(c)

Solution (Python):
a = []
n = int(input())
b = [int(i) for i in input().split()]

flag = True
for i in range(n):
    if i+1 < b[i]:
        flag = False

for i in range(n):
    a.insert(b[i]-1,b[i])

if flag == False:
    print("-1")

else:
    for i in a:
        print(i)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))

l = [0] + l
diff = [0]*(n+1)

zeros = []
ans = []
for i in range(1,n+1):
    if l[i] > i:
        print("-1")
        exit(0)
    else:
        diff[i] = i-l[i]
        if diff[i] == 0:
            zeros.append(i)
for i in range(1,n+1):
    max0 = zeros.pop()
    for j in range(max0+1,n+1):
        if diff[j] == -1:
            continue
        diff[j] -= 1
        if diff[j] == 0:
            zeros.append(j)
    ans.append(l[max0])
    
for item in ans[::-1]:
    print(item)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.reverse()
L = [1] * N
q = []
i = 0
ans = []
def kousin(i):
  ans.append(A[i])
  if q:
    for u in q:
      if u < i:
        L[u] += 1
        if A[u] == L[u]:
          kousin(u)
while i < N:
  if A[i] != L[i]:
    q.append(i)
  else:
    kousin(i)
  i += 1
if len(ans) == N:
  for i in ans:
    print(i)
else:
  print(-1)

Solution (Python):
N = int(input()) 
b = [int(i) for i in input().split()]

r =[]
flag = True
blen = len(b) + 1
while b != []:
    if blen == len(b):
        flag = False
        break
    else:
        blen = len(b)
            
    for i in range(len(b)):


        if (len(b) - i == b[len(b) - 1 - i]):
            r.append(b.pop(len(b) - i - 1))
            forflag = True
            break

if flag == True:
    for i in reversed(r):
        print(i)
else:
    print("-1")

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(N):
    if b[i] > i + 1:
        print(-1)
        exit()
for i in range(N):
    ans.insert(b[i] - 1, b[i])
for i in range(N):
    print(ans[i])

Solution (Python):
N = int(input())
b = [int(i) for i in input().split()]
L = []

f = True

for _ in range(N):
  index = 0
  for i, bi in enumerate(b):
    if i+1 < bi:
      f = False
    if i+1 == bi:
      index = i
  L.append(index+1)
  del b[index]

if f:
  L.reverse()
  for l in L:
    print(l)
else:
  print(-1)

Solution (Python):

N = int(input())
b = list(map(int,input().split()))

def next(b,l):
	for i in range(len(b)-1,-1,-1): 
		if b[i] == i+1:
			b.pop(i) 
			l.append(i+1) 
			return b, l
	return -1,-1


l = []
while b != []:
	b,l = next(b,l)
	if b == -1:
		print(-1)
		exit()
l.reverse()

for i in range(N):
	print(l[i])

Solution (Python):
N = int(input())
B = [int(i) for i in input().split()]
if B[0] != 1:
    print(-1)
    exit()

cn = [0]*N
for n in reversed(range(1,N+1)):
    
    
    for i in reversed(range(1,n+1)):
        if B[i-1] == i:
            
            cn[n-1] = i
            break
    if cn[n-1] == 0:
        print(-1)
        exit()
    B.pop(i-1)
        
for n in range(N):
    print(cn[n])

Solution (Python):
n = int(input())
B = [0]+list(map(int,input().split()))
cases = 0
limits = 0
Ans = []
flag = True
while cases <= 101:
    for b,i in zip(B[:0:-1],range(len(B)-1,0,-1)):    
           if B[i] == i:
               Ans = [b]+Ans
               B.pop(i)
               break
    cases += 1
    if cases >= 100 and len(B) >= 2:
        flag = False

if flag:
    print(*Ans,sep="\n")
else:
    print(-1)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
res = []
for i in range(N):
    if b[i] > i + 1:
        print(-1)
        exit()
for i in range(N):
    res.insert(b[i] - 1, b[i])
for i in range(N):
    print(res[i])

Solution (Python):


import sys
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
B=LIST()

ans=deque()
j=N
while len(B):
    for i in range(j-1, -1, -1):
        if B[i]==i+1:
            ans.appendleft(B.pop(i))
            j-=1
            break
    else:
        print(-1)
        exit()

for i in range(N):
    print(ans[i])

Solution (Python):
def getN():
    return int(input())

def getlist():
    return [(int(x), i) for i, x in enumerate(input().split())]

n = getN()
nums = getlist()
nums.reverse()

buffer = []
tmp = 0
used = {}

def insertcheck(n, k):
    if sum(mask[:k]) < n-1:
        return False

    return True

ans = []
mask = [0 for i in range(n)]
flag = 1


def search(nums):
    for num in nums:
        val, idx = num
        if mask[num[1]] == 0:
            if insertcheck(val, idx):
                ans.append((val,idx))
                used[num[0]] = num[1]
                mask[num[1]] = 1
                return 1

    return 0

while(flag):
    flag = search(nums)

if len(ans) != n:
    ans = [(-1, -1)]

for an in ans:
    print(an[0])


"""
9
1 1 1 2 2 1 2 4 2
"""

Solution (Python):
import sys,collections,math,copy;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
b = Is()
out = []
def dfs(a,ans):
    if a == []:
        global out
        out = ans
    cand = []
    for i,e in enumerate(a):
        if e - i > 1:
            return
        elif e - i == 1:
            cand.append(i)
    if cand == []:
        return
    else:
        for i in cand:
            t = copy.deepcopy(a)
            del t[i]
            dfs(t,ans+[i+1])
dfs(b,[])
if out == []:
    print(-1)
else:
    out = out[::-1]
    print(*out)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))

    else:
        ret = []
        ret.append(-1)
        break

for it in ret[::-1]:
    print(it)

Solution (Python):
N=int(input())
b=list(map(int, input().split()))
ans=[]
while len(b)>0:
    x=-1
    for i in range(len(b)):
        if b[i]==i+1:
            x=i
    if x==-1:
        break
    else:
        ans.append(b.pop(x))
if x==-1:
    print("-1")
else:
    ans.reverse()
    [print(ans[i]) for i in range(len(ans))]

Solution (Python):
N = int(input())
B = input().split()

history = []
while len(B):

    if B[0] != '1':
        print(-1)
        exit(0)

    bef_kick_len = len(B)
    

    for ind in range(len(B))[::-1]:
        
        if int(B[ind]) == ind + 1:
            history.append(B.pop(ind))
            break

    if len(B) == bef_kick_len:
        for state in range(len(B) - 1):
            
            if B[state] == B[state + 1]:
                history.append(B.pop(state))
                break



rev_his = reversed(history)
for i in rev_his:
    print(i)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
judge = "Y"
for i in range(N):
    if b[i] > i + 1:
        judge = "N"
        break

if judge == "N":
    print(-1)
else:
    X = []
    for i in range(N):
        for j in range(N - i):
            if b[N - 1 - i - j] == N -  i - j:
                X.append(N - i - j)
                del b[N - 1 - i - j]
                break
    for i in range(N):
        print(X[-1 - i])

Solution (Python):
import sys

N = int(input())
saveN = N
B = list(map(int,input().split()))
B.insert(0, -1) 
rem = []
while N > 0:
    sch = N
    while sch >= 0:
        if B[sch] == sch:
            rem.append(B.pop(sch))
            N -= 1
            break
        sch -= 1
    if sch == -1: 
        print("-1")
        sys.exit()

for i in range(saveN):
    print(str(rem[saveN-1 - i]))

Solution (Python):
n = int(input())
lis = list(map(int, input().split()))


ans = []

for j in range(n):
    if lis == []:
        break
    else:
        for i in range((len(lis)-1),-1,-1):
            if lis[i]==i+1:
                del lis[i]
                ans.append(i+1)
                break
            else:
                pass


if lis==[]:
    ans.reverse()
    for i in range(n):
        print(ans[i])
else:
    print(-1)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))

def dfs(c):
  if len(c) == 0:
    return []

  for i in range(len(c), 0, -1):
    if c[i-1] > i:
      return False

    if c[i-1] == i:
      cc = c.copy()
      del cc[i-1]
      res = dfs(cc)
      if res is not False:
        res.append(i)
        return res

  return False

res = dfs(b)
if res is False:
  print(-1)
else:
  for i in res:
    print(i)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

def main(n):
	b = list(map(int, input().split()))
	ans = []
	for i in range(n):
		if i+1 < b[i]:
			print(-1)
			return
		if i == 0:
			ans = [1]
			continue
		ans = ans[:b[i]-1] + [b[i]] + ans[b[i]-1:]
	print("\n".join(map(str,ans)))

main(int(input()))

Solution (Python):
n = int(input())
nums = list(map(int, input().split()))
answers = list()

while True:
    i = len(nums) - 1
    while i  >= 0:
        num = nums[i]
        if i + 1 == num:
            answers.insert(0, nums.pop(i))
            break
        i -= 1
    else:
        break
if len(nums) == 0:
    for num in answers:
        print(num)
else:
    print(-1)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[]
for i in range(n):
    j=n-i-1
    flg=False
    while j>=0:
        if b[j]==j+1:
            a+=[b.pop(j)]
            flg=True
            break
        j-=1
    if not flg:
        break
if b:
    print(-1)
else:
    for x in a[::-1]:
        print(x)

Solution (Python):
N=int(input())
b=list(map(int,input().split()))
flg=True

ans = [0 for i in range(N)]
for i in range(N):
    for j in range(N-i):
        if b[N-i-j-1]==N-i-j:
            del b[N-i-j-1]
            
            ans[N-i-1]=N-i-j
            break

for a in ans:
    if a==0:
        flg=False
        break

if flg:
    for a in ans:
        print(a)
else:
    print(-1)

Solution (Python):
import math

n = int(input())
b = list(map(int, input().split()))

a = []
lis = []

for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
        lis.insert(b[i-1]-1, b[i-1])
    else:
        break

if(a != b):
    print(-1)
else:
    for i in range(len(a)):
        print(lis[i])

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
b.reverse()
ans = []
for i in range(N):
    for j in range(len(b)):
        if b[j] == len(b)-j:
            ans.insert(0, b.pop(j))
            break

if not len(ans)==N:
    ans = [-1]

for a in ans:
    print(a)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return



N = 0
B = []


def set_inputs():
    global N, B
    N = get_int()
    B = get_list_of_int()
    return



def solve(b):
    if len(b) == 0:
        return []
    if sum(b) > len(b) * (len(b) + 1) // 2:
        return [-1]
    for i, v in enumerate(b):
        if v > i + 1:
            return [-1]
    possible_indices = []
    for i, v in enumerate(b):
        if i + 1 == v:
            possible_indices.append(i)
    if len(possible_indices) == 0:
        return [-1]
    for i in possible_indices:
        ans = solve(b[:i] + b[i+1:])
        if len(ans) == 1 and ans[0] == -1:
            continue
        return ans + [i+1]
    return [-1]


def main():
    setrecursionlimit(100000)
    set_inputs()
    for i in solve(B):
        print(i)
    return


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
c = 0
t = []
for i in range(n):
        if i + 1 < b[i]:
                print(-1)
                c = 1
                break

if c == 0:
        while b != []:
                s = []
                for  i in range(len(b)):
                        if i + 1 == b[i]:
                                s.append(b[i])
                t.insert(0,max(s))
                b.pop(max(s)-1)
        for i in range(len(t)):
                print(t[i])

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG =  True   and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
b = inl()
seq = [0] * n
for i in range(n-1,-1,-1):
    ok = False
    for j in range(i,-1,-1):
        ddprint("i {} j {} bj {}".format(i,j,b[j]))
        if b[j] == j+1:
            seq[i] = j
            ddprint("j {} to seq i {}".format(j,i))
            b.pop(j)
            ok = True
            break
    ddprint("ok {}".format(ok))
    ddprint(b)
    if not ok:
        print(-1)
        exit()

for i in range(n):
    print(seq[i]+1)

Solution (Python):
N = int(input())
tmp = input().split()
b = []
ans = []

for i in range(N):
  b.append(tmp[i])
  
for index, item in enumerate(b):
  if int(item) > index+1:
    print('-1')
    exit()
  dist = index + 1 - int(item)
  ans.insert(index-dist, int(item))

for i in range(len(ans)):
  print(ans[i])

Solution (Python):
n = int(input())
a = list()
b = [int(i) for i in input().split()]
flag = True
find = False
while b != []:
    for i in reversed(range(0,len(b))):
        if b[i] == (i+1):
            del b[i]
            a.append(i+1)
            find = True
            break
    if find == True:
        find = False
        continue
    else:
        flag = False
        break
if flag == False:
    print(-1)
else:
    for i in reversed(range(0,n)):
        print(a[i])

Solution (Python):
N = int(input())
b_list = list(map(int, input().split()))

generate_seq = []


def is_ok(b):
    len_b = len(b)
    if len_b == 1 and b[0] == 1:
        generate_seq.append(1)
        return True

    for idx, val in enumerate(b):
        if idx + 1 < val:
            return False

    processing = []
    for idx in range(len_b):
        if b[idx] != idx + 1:
            processing.append(False)
        else:
            b_tmp = b[:]
            del b_tmp[idx]
            tmp = is_ok(b_tmp)
            if tmp:
                generate_seq.append(idx + 1)
                return True
    return False


result = is_ok(b_list)
if result:
    print('\n'.join(list(map(str, generate_seq))))
else:
    print(-1)