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

input = sys.stdin.readline

n = int(input())

b_list = list(map(int, input().split()))
result_list = []
while len(b_list) > 0:
    flag = False
    for i,b in enumerate(reversed(b_list)):
        if len(b_list)-i == b:
            result_list.append(b)
            b_list.pop(len(b_list)-i -1)
            flag = True
            break
    if not flag:
        print(-1)
        exit(0)

for b in reversed(result_list):
    print(b)

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

ans = []
for i in range(n):
  ind = -1
  for j in range(len(A)):
    if A[j] == j + 1:
      ind = j
  if ind == -1:
    break
  else:
    A.pop(ind)
    ans.append(ind+1)

if ind == -1:
  print(-1)
else:
  ans.reverse()
  for a in ans:
    print(a)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    ans = []
    for _ in range(N):
        j = -1
        for i in range(len(B)):
            if B[i] == i+1:
                j = i
        if j == -1:
            print(-1)
            exit()
        ans.append(j+1)
        B.pop(j)
    for a in ans[::-1]:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

for n in range(N):
  if A[n] >  n+1:
    print(-1)
    sys.exit()

ans = []

while A != []:
  tmp = 0
  for p in range(len(A)):
    if A[p] == p+1:
      tmp = p
  ans.insert(0,A.pop(tmp))

  
for x in ans:
  print(x)

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
i = N-1
jun = []
while i > -1:
    if b[i] == i+1:
        del b[i]
        jun.append(i+1)
        i = len(b)-1
    else:
        i -= 1
if len(b) != 0:
    print(-1)
else:
    for j in jun[::-1]:
        print(j)

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

Solution (Python):
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N = read_int()
    B = read_ints()
    answer = [0]*N
    for j in range(N-1, -1, -1):
        last_valid = -1
        for i in range(len(B)):
            if B[i] == i+1:
                last_valid = i
        if last_valid == -1:
            print(-1)
            return
        answer[j] = B.pop(last_valid)
    for a in answer:
        print(a)


if __name__ == '__main__':
    solve()

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

ans = []
while len(b):
    memo = -1
    for key,val in enumerate(b):
        if key+1==val:
            memo = key
    if memo != -1:
        ans.append(b.pop(memo))
    else:
        break

if len(b):
    print(-1)
else:
    ans.reverse()
    for a in ans:
        print(a)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
l = [""]
for i in b:
    l.insert(i - 1, i)
print(*l[-1] and [-1] or l, sep="\n")

Solution (Python):
from collections import deque
n = int(input())
b = list(map(int,input().split()))
ans = deque()
for _ in range(n):
    for i in range(len(b))[::-1]:
        if b[i] == i + 1:
            ans.appendleft(b[i])
            b.pop(i)
            break
        if i == 0:
            print(-1)
            exit(0)
for i in ans:
    print(i)

Solution (Python):

def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    ans = []
    while B:
        for i in range(len(B) - 1, -1, -1):
            if B[i] == i + 1:
                ans.append(i + 1)
                del B[i]
                break
        else:
            print(-1)
            return 
    print(*ans[::-1], sep='\n')



if __name__ == "__main__":
    resolve()

Solution (Python):

def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    ans = []
    while B:
        for i in range(len(B) - 1, -1, -1):
            if B[i] == i + 1:
                ans.append(i + 1)
                del B[i]
                break
        else:
            print(-1)
            return 
    print(*ans[::-1], sep='\n')



if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
new_B = list(map(int, input().split()))
ans = []
cnt = 0

while (cnt < 100000) & (new_B != []):
    B = new_B
    length = len(B)
    new_B = []
    for i in range(1, length + 1):
        if B[-i] < (len(B) - i + 1):
            new_B = [B[-i]] + new_B
        elif B[-i] == (len(B) - i + 1):
            ans.append(B[-i])
            new_B = B[:-i] + new_B
            break
        else:
            print(-1)
            exit()
    cnt += 1


if cnt == 100000:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans = []
max_b = max(B)
for i in range(N):
    for b in range(max_b, 0, -1):
        if len(B) > b-1 and B[b-1] == b:
            ans += [B.pop(b-1)]
            break

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

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

while B:
    
    for idx in range(len(B) - 1, -1, -1):
        if B[idx] == idx + 1:
            v = B.pop(idx)
            V.append(v)
            break
    else:
        print(-1)
        exit()

for v in V[::-1]:
    print(v)

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
answers=[]
while B:
    length=len(B)
    for n in range(len(B)-1,-1,-1):
        if B[n]==n+1:
            answers.append(B[n])
            del B[n]
            break
    if length==len(B):
        break
if len(answers)!=N:
    print(-1)
else:
    for answer in list(reversed(answers)):
        print(answer)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = []

for i in range(n):
    for j in range(len(b), 0, -1):
        if j == b[j-1]:
            b = b[0:j-1] + b[j:n]
            ans.append(j)
            break

if len(ans) == n:
    ans.reverse()
    for item in ans:
        print(item)
else:
    print(-1)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = []; c = 0
while len(a) > 0:
    for j in range(len(a)):
        if a[-j-1] == len(a)-j: b.append(a.pop(-j-1)); break
    else: c = 1; break
else:
    b.reverse()
    for i in range(n):
        if b[i] > i+1: c = 1
print(-1) if c == 1 else print(*b, sep="\n")

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

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

ans = []


while b:
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            ans.append(i+1)
            del b[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')

Solution (Python):
N=int(input())
b=list(map(int, input().split()))
a=[]
for i in b:
    if len(a)<i-1:
        print(-1)
        exit()
    a.insert(i-1,i)
for i in a:
    print(i)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
a = []
for i in b:
    if len(a) < i - 1:
        print(-1)
        exit()
    a.insert(i-1,i)
for i in a:
    print(i)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
b = readInts()

d = deque()

def renzoku(arr):
	i = -1
	boo = 1
	for i in range(1,len(arr)+1):
		
		if arr[len(arr)-i] == len(arr)-i+1:
			boo = 0
			break
	if boo:
		print(-1)
		exit()
	
	return len(arr)-i


for i in range(len(b)):
	r = renzoku(b)
	
	
	d.append(r)
	del b[r]

for i in reversed(d):
	print(i+1)

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n-1,-1,-1):
  for j in range(i,-1,-1):
    if B[j]==j+1:
      A.append(j+1)
      del B[j]
      break
if len(A)==n:
  for a in A[::-1]:print(a)
else:
  print(-1)

Solution (Python):
import sys
n = int(input())
b = list(map(int, input().split()))
ans = []

for i in b:
    if len(ans) >= i-1:
        ans.insert(i-1, i)
    else:
        print(-1)
        sys.exit()
for i in ans:
    print(i, sep='\n')

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
fl = [False] * n
q = []
while len(b) != 0:
    ptr = -1
    for i in range(len(b)):
        if b[i] == i+1:
            ptr = i

    if ptr == -1:
        break

    _b = []
    for i in range(len(b)):
        if i == ptr:
            q.append(b[i])
        else:
            _b.append(b[i])

    b = _b.copy()

if ptr == -1:
    print(ptr)
else:
    for qq in reversed(q):
        print(qq)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
ans=[]
for a in A:
    if len(ans)<a-1:
        ans=[-1]
        break
    else:
        ans.insert(a-1,a)

for x in ans:
    print(x)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
    if a[i] > i + 1:
        print(-1)
        exit()
for i in range(n):
    for i in range(n - i)[-1::-1]:
        if a[i] == i + 1:
            ans.append(a[i])
            del a[i]
            break
for i in ans[-1::-1]:
    print(i)

Solution (Python):
N=int(input())

A=list(map(int, input().split()))

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

ans=[]

while A:
    now=0
    for i in range(len(A)):
        if i+1==A[i]:
            now=i
    a=A.pop(now)
    ans.append(a)

ans=ans[::-1]
for a in ans:
    print(a)

Solution (Python):
import sys

N = int(sys.stdin.readline())
B = list(map(int, sys.stdin.readline().split()))

ans = []
while B:
    for i in range(N-1, -1, -1):
        if B[i] == i + 1:
            ans.append(B[i])
            B.pop(i)
            N -= 1
            break
    else:
        break

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

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

ans = []
for i in range(N):
    for j in range(len(b)-1,-1,-1):
        if b[j]==(j+1):
            ans += [b[j]]
            del b[j]
            break
if len(b)!=0:
    print(-1)
    exit()

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

Solution (Python):
N = int(input())
b = list(int(x) for x in input().split())

result = []
while b:
    remove_flag = False
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            result.insert(0, b.pop(i))
            remove_flag = True
            break
    if not remove_flag:
        print(-1)
        exit()

        remove_flag = False

for i in result:
    print(i)

Solution (Python):
import sys
N = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(N):
    for j in range(N-i, 0, -1):
        if b[j-1] == j:
            ans.append(b.pop(j-1))
            break
    if len(ans) != i+1:
        print(-1)
        sys.exit()

for i in reversed(ans):
    print(i)

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

ans = []
while len(ans) < N:
    j = -1
    for i,b in enumerate(B):
        if b==i+1:
            j = i
    if j==-1:
        print(-1)
        exit()
    ans.append(j+1)
    del B[j]
print(*ans[::-1], sep='\n')

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
b = LI()
flag = [True] * n
ans = []
for i in range(n):
    cnt = 0
    idx = -1
    for j in range(n):
        if flag[j]:
            cnt += 1
            if b[j] == cnt:
                idx = j
    if idx == -1:
        print(-1)
        quit() 
    flag[idx] = False
    ans.append(b[idx])
for i in ans[::-1]:
    print(i)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = []
while b:
    m = len(b)
    ok = False
    for i in range(m)[::-1]:
        
        if b[i] == i+1:
            a.append(b.pop(b[i]-1))
            ok = True
            break
    
    if not ok:
        print(-1)
        exit()

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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
B.insert(0,0)
A = []
while True:
    flag = 0
    for i in range(len(B)-1,0,-1):
        if B[i]==i:
            A.append(B.pop(i))
            flag = 1
            break
    if flag==0 and len(B)>1:break
    if len(B)==1:break
if len(B)>1:
    print(-1)
else:
    for _ in range(N):
        print(A.pop())

Solution (Python):
import sys
import numpy as np

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

ans = []
for i in range(n):
    c = np.arange(1, n - i + 1)
    diff = b - c
    if not 0 in diff:
        print(-1)
        sys.exit()
    rem = np.where(diff == 0)[0][-1]
    ans.append(rem + 1)
    b = np.delete(b, rem)

print(*ans[::-1], sep="\n")

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = []

for i in range(n):
    for j in range(n-1-i, -1, -1):
        if b[j] == j+1:
            
            tmp = b.pop(j)
            ans.append(tmp)
            break
    else:
        print(-1)
        exit()

for a in ans[::-1]:
    print(a)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(N):
    
    d = -1
    for j in range(N-i):
        if (j+1)-b[j] == 0:
            d = j
    if d == -1:
        print(-1)
        exit()
    else:
        ans.append(b[d])
        del b[d]
[print(a) for a in ans[::-1]]

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

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

Flag = True

memo = []

while Flag:
    Flag = False
    index = -1
    for i, v in enumerate(b):
        if i == v-1:
            Flag = True
            index = i
    if index != -1:
        m = b.pop(index)
        memo.append(m)
if len(b):
    print(-1)
else:
    memo.reverse()
    for aa in memo:
        print(aa)

Solution (Python):

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

curr_bl = bl[:]

ans = []
for i in range(n):
    rem = n - i
    deleted_j = -1
    for j in range(rem-1,-1,-1):
        if curr_bl[j] == j+1:
            deleted_j = j
            ans.append(j+1)
            break
    if deleted_j == -1:
        print(-1)
        exit()
    else:
        new_bl = []
        for j in range(rem):
            if j != deleted_j:
                new_bl.append(curr_bl[j])
        curr_bl = new_bl[:]


for a in ans[::-1]:
    print(a)

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

flag = [1] * (N + 1) 
ans = []
i = N
_i = 0
while True:
    
    if b[i - _i] > i - _i:
        print(-1)
        exit()
        break
    elif b[i - _i] == i - _i:
        ans.append(i - _i)
        del b[i - _i]
        i -= 1
        _i = 0
    else:
        _i += 1
    if _i >= i:
        
        break
for a in reversed(ans):
    print(a)

Solution (Python):
n=input()
b=list(map(int,input().split()))
a=[]
while b:
  c=0
  for i,j in enumerate(b,1):
    if i==j:c=i
  if c==0:
    print(-1)
    exit()
  a+=[b.pop(c-1)]
print(*a[::-1],sep='\n')

Solution (Python):
def main():
    N = int(input())
    B = list(map(int, input().split()))
    ans = list()
    while len(B) > 0:
        D = [(i + 1) - b for i, b in enumerate(B)]
        last_zero_index = -1
        for i, d in enumerate(D):
            if d < 0:
                print(-1)
                return
            if d == 0:
                last_zero_index = i
        if last_zero_index == -1:
            print(-1)
            return
        ans.append(B[last_zero_index])
        B = B[:last_zero_index] + B[(last_zero_index+1):]
    ans.reverse()
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

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

anslist = []

while l:
    for i in range(len(l)-1,-1,-1):
        if l[i] == i+1:
            anslist.append(l.pop(i))
            break
    else:
        print(-1)
        exit()

anslist.reverse()
for i in anslist:
    print(i)

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
ans = []
while len(ans) < N:
    for i in range(len(B) - 1, -1, -1):
        num = i + 1
        if num == B[i]:
            B.pop(i)
            ans.append(num)
            break
        if i == 0:
            print(-1)
            exit()
ans = ans[::-1]
print(*ans, sep='\n')

Solution (Python):
n=int(input())
b=[int(i) for i in input().split()]
ans=[]
while len(b)>0:
  f=0
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(i)
      del b[i-1]
      f=1
      break
  if f==0:
    print(-1)
    exit()
print(*ans[::-1],sep='\n')

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

ans = [0 for _ in range(n)]

for i in range(n):
    p = False
    for j in range(len(a)-1, -1, -1):
        if a[j] == j+1:
            ans[n-1-i] = a.pop(j)
            p = True
            break

    if not p:
        print(-1)
        exit()

for ai in ans:
    print(ai)

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

ans=[]
for i in range(N):
    for j in range(N-1-i,-1,-1):
        if b[j]==j+1:
            ans.append(b.pop(j))
            break
        elif j==0:
            print('-1')
            sys.exit()
        else:
            continue

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

Solution (Python):
def main():
    N = int(input())
    B = list(map(int, input().split()))
    ans = []
    while B:
        for i in range(len(B)-1,-1,-1):
            if B[i] == i + 1:
                ans.append(B[i])
                B.pop(i)
                break
        else:
            print(-1)
            exit()
    for i in range(N-1,-1,-1):
        print(ans[i])





if __name__ == "__main__":
    main()

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()



def main():
    n = int(input().strip())
    B = [int(i) for i in input().strip().split()]
    ans = []
    ptr = len(B)
    while ptr > 0:
        if B[ptr - 1] == ptr:
            ans.append(B.pop(ptr - 1))
            ptr = len(B)
        else:
            ptr -= 1
    if len(ans) == n:
        for i in ans[::-1]:
            print(i)
    else:
        print(-1)

    return


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
a = []
for i in b:
    if i == 1:
        a.insert(0,1)
    else:
        if len(a)+1 < i:
            print(-1)
            exit()
        a.insert(i-1,i)
    
for i in a:
    print(i)

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
li = []
a = 0
while a <= 101:
    for i in range(len(L)-1,-1,-1):
        if i == L[i]-1:
            li.append(L[i])
            L.pop(i)
            break
    a +=1
    
if len(L) > 0:
    print(-1)
else:        
    li = li[::-1]
    for i in range(len(li)):
        print(li[i])

Solution (Python):
N=int(input())
B=["*"]+list(map(int,input().split()))

X=[]
for t in range(N):
    p=-1
    for k in range(1,(N-t)+1):
        if B[k]==k:
            p=k

    if p>=1:
        X.append(p)
        del B[p]
    else:
        print(-1)
        exit()

print("\n".join(map(str,X[::-1])))

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

Solution (Python):
import sys

n = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(n):
    for j in range(len(b), 0, -1):
        if b[j - 1] == j:
            ans.append(j)
            del b[j - 1]
            break
    else:
        print(-1)
        sys.exit()
ans.reverse()
for i in ans:
    print(i)

Solution (Python):
import sys

input = sys.stdin.readline


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

    is_ok = True
    for i, b in enumerate(B, 1):
        if i < b:
            is_ok = False
    if not is_ok:
        print(-1)
        exit()

    ans = []
    for _ in range(N):
        for i in reversed(range(len(B))):
            if B[i] == i + 1:
                break
        ans.append(B[i])
        del B[i]

    ans = ans[::-1]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

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

ans = []
for i in range(N):
  flag = True
  for j in range(N-i):
    n = N-i-j
    if B[n-1] == n:
      ans.append(n)
      B.pop(n-1)
      flag = False
      break
  if flag:
    break
    
if flag:
  print(-1)
else:
  ans.reverse()
  for i in range(N):
    print(ans[i])

Solution (Python):








def solve(n,b):
  a = []
  for i in range(n-1,-1,-1):
    flag = False
    for j in range(i,-1,-1):
      if b[j] == j+1:
        a.append(j+1)
        b.pop(j)
        flag = True
        break
    if not flag:
      return [-1]
  return reversed(a)



def main():
  N = int(input())
  b = list(map(int,input().split()))
  print(*solve(N,b),sep="\n")
  return

if __name__ == '__main__':
  main()

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    b=LI()
    ans=[]
    for _ in range(N):
        for i in range(len(b)-1,-1,-1):
            if b[i]==i+1:
                ans.append(b[i])
                b.pop(i)
                break
            
    if len(ans)==N:
        for i in range(N):
            print(ans[-1-i])
    else:
        print(-1)
        

main()

Solution (Python):
import bisect

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

As = []
while Bs:
  f = 0
  for i in range(len(Bs)-1,-1,-1):
    if Bs[i] == i + 1:
      f = 1
      As.append(Bs.pop(i))
      break
  if f == 0:
    print('-1')
    exit()
    
for a in As[::-1]:
  print(a)

Solution (Python):
def check_val(ind):
    if ind > len(b): return False 
    if b[ind-1] == ind:
        ans.append(ind)
        del b[ind-1]
        if ind not in b: set_b.remove(ind)
        return True
    else:
        return False


N,*b = map(int,open(0).read().split())
if b[0] != 1: 
    print(-1)
    exit()

set_b = sorted(set(b),reverse=True)
ans = []

while len(b) != 0:
    flg = False
    for i in set_b:
        flg = check_val(i)
        if flg: break
    
    if flg == False:
        print(-1)
        exit() 
else: 
    print(*ans[::-1],sep="\n")

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

ans = []
while B:
    flag = False
    idx = -1
    for i in range(len(B)):
        if B[i] == i+1:
            flag = True
            idx = i
    else:
        if flag:
            ans.append(B[idx])
            B.pop(idx)
        else:
            print(-1)
            exit(0)

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

Solution (Python):
n= int(input())
b= list(map(int,input().split()))
getnum = []
while len(b)>0:
    tempmax=-1
    for i,c in enumerate(b):
        if i+1==c:tempmax=i
    if tempmax==-1:
        print(-1)
        break
    else:
        getnum.append(b[tempmax])
        del b[tempmax]
else:
    for t in getnum[::-1]:print(t)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
b = LIST()
ans = deque()

while b:
    m = len(b)
    for i in range(m-1, -1, -1):
        if b[i] == i + 1:
            ans.appendleft(b.pop(i))
            break
    else:
        print(-1)
        exit()
for x in ans:
    print(x)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
b = LIST()
ans = deque()

while b:
    m = len(b)
    chk = False
    for i in range(m-1, -1, -1):
        if b[i] == i + 1:
            ans.appendleft(b.pop(i))
            chk = True
            break
    if chk == False:
        print(-1)
        exit()
for x in ans:
    print(x)

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

for i in range(n):
    tmp = []
    for j in range(len(b)):
        if j+1 == b[j]:
            tmp.append(b[j])
    if len(tmp) == 0:
        flag= 1
        break
    a.append(b.pop(tmp[-1]-1))

if flag == 0:
    for i in range(len(a)):
        print(a[-1-i])
else:
    print(-1)

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

ans = []
for i in range(N): 
    tgt = -1
    for i in reversed(range(len(B))):
        if B[i] == i+1:
            
            tgt = i
            break
    if tgt == -1:
        break
    ans.append(B[i])
    del B[i]

ans = ans[::-1]

if len(ans) == len(ORI_B):
    print('\n'.join(map(str, ans)))
else:
    print(-1)

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
l = []
while b:
    for i in range(len(b)-1,-1,-1):
        if b[i] == i + 1:
            del b[i]
            l += i + 1,
            break
    else:
        print(-1)
        exit()
for i in l[::-1]:
    print(i)

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

res = []
for i in range(N):
    for j in range(N-i-1, -1, -1):
        if B[j] == j+1:
            res.append(j+1)
            B = B[:j]+B[j+1:]
            break
    else:
        break

if len(res) == N:
    res.reverse()
    for r in res:
        print(r)
else:
    print(-1)

Solution (Python):

n, *b = map(int, open(0).read().split())
ans = []
for i in reversed(range(n)):
    for j in reversed(range(i + 1)):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            break
    else:
        print(-1)
        exit()
print(*reversed(ans), sep="\n")

Solution (Python):
n, *b = map(int, open(0).read().split())
l = []
while 1:
    for i in reversed(range(len(b))):
        if i + 1 == b[i]:
            del b[i]
            l += i + 1,
            break
    else:
        break
if b:
    print(-1)
    exit()
for i in l[::-1]:
    print(i)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
ans=[]
for i in range(n):
  if b[i]-1>len(ans):
    print(-1)
    break
  else:
    ans.insert(b[i]-1,b[i])
else:
  for i in range(n):
    print(ans[i])

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
c =[]
while b:
    a = 0
    for i in range(len(b)-1,-1,-1):
        if i+1 == b[i]:
            a = b.pop(i)
            c.append(a)
            break
    if a == 0:
        print(-1)
        exit()
for i in range(len(c)-1,-1,-1):
    print(c[i])

Solution (Python):






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





op = []
mylist = [x for x in b]
f = True
while len(mylist)>0:
    for i in reversed(range(len(mylist))):
        if mylist[i] == i+1:
            op.append(mylist.pop(i))
            break
    else:
        f = False
        break
if f:
    ans = list(reversed(op))
    for x in ans:
        print(x)
else:
    print(-1)

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

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations, islice




def solve():
    N = II()
    B = deque(LI())
    B.appendleft(0)
    
    ans = deque([])
    for i in range(N, 0, -1):
        tmp = deque([])
        
        for j in range(i, 0, -1):
            
            if B[j] == j:
                
                tmp2 = deque(islice(B, 0, j))
                tmp2.extend(tmp)
                
                
                B = tmp2
                ans.appendleft(j)
                break
            else:
                tmp.appendleft(B[j])
        else:
            print(-1)
            return

    printlist(list(ans), '\n')

if __name__ == '__main__':
    solve()