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
from collections import deque
input = sys.stdin.readline

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

for i, bi in enumerate(b):
    if i + 1 < bi:
        q = deque([])
        break
else:
    q = deque([(b, [])])
    
while len(q) > 0:
    b_tmp, seq = q.pop()
    if len(b_tmp) == 0: break
    for i, bi in enumerate(b_tmp):
        if i + 1 < bi: break
        elif i + 1 == bi:
            if i == 0: q.append((b_tmp[i + 1:], seq + [i + 1]))
            elif i == len(b_tmp) - 1: q.append((b_tmp[:i], seq + [i + 1]))
            else: q.append((b_tmp[:i] + b_tmp[i + 1:], seq + [i + 1]))
else:
    seq = [-1]

for i in seq[::-1]: print(i)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)


def rec(arr, l, lst):
    
    
    if l == 0:
        for p in lst[::-1]:
            print(p)
        exit()
        return

    for i in sorted(range(1, l + 1), reverse=True):
        
        if arr[i-1] == i:
            
            
            rec(arr[:i - 1] + arr[i:], l - 1, lst + [i])
        elif arr[i-1] > i:
            
            return
    return


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

rec(b, N, [])

print(-1)

Solution (Python):
def solve(N, Bs):
    ans = []
    while len(Bs):
        failed = True
        for i, b in enumerate(Bs[::-1]):
            i = len(Bs) - i
            if i == b:
                ans.append(Bs.pop(i - 1))
                failed = False
                break
        if failed:
            return "-1"
    return "\n".join(str(a) for a in ans[::-1])

if __name__ == "__main__":
    N = int(input())
    bs = list(map(int, input().split(" ")))
    print(solve(N, bs))

Solution (Python):

from collections import deque
n = int(input())
b = list(map(int, input().split()))

is_valid = True
for x in range(len(b)):
    if b[x] > x + 1:
        print(-1)
        is_valid =False
        break

if is_valid:
    generate = deque()
    while b:
        for x in reversed(range(len(b))):
            if (x + 1) == b[x]:
                i = b.pop(x)

                generate.appendleft(i)

                break

    for x in range(len(generate)):
        print(generate[x])

Solution (Python):
N = int(input())
blist = list(map(int,input().split()))
answer = []
current = []
flag = True
while flag:
    if len(blist) == 0:
        break
    if blist.index(max(blist)) + 1 < max(blist):
        flag = False
    else:
        current = [x for i, x in enumerate(blist) if x == i+1]
        current
        answer.append(blist.pop(max(current)-1))
if flag:
    for ans in answer[::-1]:
        print(ans)
else:
    print(-1)

Solution (Python):
n=int(input())
lst = list(map(int, input().split()))
ans=[]
if not(1 in lst):
    print(-1)
    quit()
while (1 in lst):
  l=len(lst)
  for i in range(l):
    if(lst[-i-1]==l-i):
      ans=[l-i]+ans
      del(lst[-i-1])
      break
  else:
    print(-1)
    quit()
if(len(ans)!=n):
    print(-1)
    quit()
for i in ans:
  print(i)

Solution (Python):
n = int(input())
ans = []
lis = list(map(int,input().split()))
num = 0
for i in range(n):
    li = []
    key = 0
    for j in range(n-i):
        if lis[n-i-j-1] != n-i-j or key != 0:
            li.insert(0,lis[n-i-j-1])
        else:
            ans.append(n-i-j)
            key = 1
    lis = li
if lis == []:
    for i in range(n):
        print(ans[-(1+i)])
else:
    print("-1")

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
def check_pos(L):
    num_L = len(L)
    ans = True
    for idx_L in range(num_L):
        if L[idx_L] > idx_L + 1:
            ans = False
            break
    return ans

if check_pos(B) == False:
    print(-1)
else:
    ans = []
    num_L = len(B)
    for i in range(num_L):
        idx = 0
        for j in range(len(B)):
            if B[j] == j + 1:
                idx = j
        ans.append(idx + 1)
        B.pop(idx)
    ans.reverse()
    for x in ans:
        print(x)

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

a_arr = []


while b_arr != []:
    tmp = -1
    for i in b_arr:
        if i-1 > len(b_arr)-1:
            print(-1)
            sys.exit()

        if b_arr[i-1] == i:
            tmp = max(i-1,tmp)

    a_arr.append(b_arr.pop(tmp))

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

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

A = []
for _ in range(N):
    for i in range(len(B) - 1, -1, -1):
        if i + 1 == B[i]:
            p = B.pop(i)
            A.append(p)
            break
        
A.reverse()
if B != []:
    print(-1)
else:
    for a in A:
        print(a)

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

while True:
    if not Bs:
        break
        
    b_len = len(Bs)
    for B in Bs[::-1]:
        if Bs[b_len -1] == b_len:
            ans.append(Bs[B-1])
            del Bs[B-1]
            break
        else:
            b_len -= 1
    else:
        flg = False
        print("-1")
        break

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

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

def calc(X):
    if len(X) == 0:
        return [0, []]
    Y = [x for x in X]
    m = -1
    for i in range(len(Y)):
        if i+1 == Y[i]:
            m = i
    if m < 0:
        return [-1]
    
    del Y[m]
    r = calc(Y)
    if r[0] < 0:
        return [-1]
    
    return [0, r[1] + [m+1]]
    
r = calc(A)
if r[0] < 0:
    print(-1)
else:
    print(*r[1])

Solution (Python):
num = int(input())
Seq = list(map(int, input().split()));
revSeq = reversed(Seq)
answer = []

able = True;

for i in range(num):
    if i+1<Seq[i]:
        able = False;
        break;

if able==False:
    print(-1);
else:
    while len(Seq)>0:
        for i in reversed(range(num)):
            if i+1==Seq[i]:
                answer.append(Seq[i]);
                del Seq[i];
                num-=1;
                break;

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

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

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)


def A():
    n = I()
    b = LI()
    ans = []
    d = max(b)
    i = 0
    while b:
        j = len(b)-1
        while j >= 0:
            if b[j] > j+1:
                print(-1)
                quit()
            elif b[j] == j+1:
                ans.append(b[j])
                b.pop(j)
                break
            j -= 1
    for i in ans[::-1]:
        print(i)

def B():
    n = I()
    if n%2:
        ans = []
        for i in range(1,n+1):
            for j in range(1,n+1):
                if j != n-i and j != i:
                    ans.append((min(i,j),max(i,j)))
        ans = list(set(ans))
        print(len(ans))
        ans.sort()
        for i in ans:
            print(*i)
    else:
        ans = []
        for i in range(1,n+1):
            for j in range(1,n+1):
                if j != n+1-i and j != i:
                    ans.append((min(i,j),max(i,j)))
        ans = list(set(ans))
        print(len(ans))
        ans.sort()
        for i in ans:
            print(*i)

def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    A()

Solution (Python):
import sys

input = sys.stdin.readline
n = int(input())
b_list = list(map(int, input().split()))
ans_list = []
for i in range(n):
    flag = 0
    tmp = 0
    for j in range(n-i):
        if j == b_list[j]-1:
            tmp = j
            flag = 1
    if flag == 0:
        ans_list.append(-1)
        break
    else:
        num = b_list.pop(tmp)
        ans_list.append(num)
if ans_list[-1] == -1:
    print(-1)
else:
    for a in ans_list[::-1]:
        print(a)

Solution (Python):
input = [input() for i in range(2)]

N = int(input[0])
b = input[1].split(" ")
b = list(map(int,b))
output = []




for i in range(N,0,-1):
    
    for j in range(i-1,-1,-1):
        
        if j + 1 == b[j]:
            
            output.append(b.pop(j))
            
            break

if b == []:
    for i in range(len(output)-1,-1,-1):
        print(output[i])
else:
    print(-1)

Solution (Python):

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

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

if len(ans) == N:
    print(*ans[::-1], sep='\n')
else:
    print(-1)

Solution (Python):
N=int(input())
B=list(map(int,input().split(' ')))
able=True
ans=[]
if [1 if B[i]<=(i+1) else 0 for i in range(N)].count(0)!=0:
	able=False
	print('-1')
if able:
	while True:
		if len(B)==0:
			break
		else:
			goodposition=0
			for i in range(len(B)):
				if B[i]==(i+1):
					goodposition=i
			ans.append(str(B.pop(goodposition)))
	for a in ans[::-1]:
		print(a)

Solution (Python):
from sys import exit

N = int(input())
b = [int(n) for n in input().split()]
test = [i for i in range(1,N+1)]
ans = []
i = N
while(i != 0):
    
    if b[i-1] == i:
        ans.append(b[i-1])
        del b[i-1]
        i = len(b)
    else:
        i-=1
    if len(b) == 0:
        for l in range(len(ans)-1,-1,-1):
            print(ans[l])
        exit()

print(-1)




exit()

Solution (Python):
import numpy as np




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

res = []

while len(b) > 0:
    seq = np.arange(1, len(b) + 1)
    same = np.where(np.array(b) == seq)[0]
    if len(same) == 0:
        print(-1)
        exit()
    else:
        maximum = same[-1]
    res.append(str(b.pop(maximum)))

print("\n".join(res[::-1]))

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

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

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

for i in L:
  print(i)

Solution (Python):

import sys
import math
import numpy as np
import itertools



n = int(input())

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

for i in range(n):
    if b[i]>i+1:
        print("-1")
        exit()

a =[]
for i in range(n):
    a.append(i+1-b[i])
answer=[]
for i in range(n-1,-1,-1):
    for j in range(i,-1,-1):
        if a[j] == 0:
            answer.insert(0,j+1)
            a.pop(j)
            break
        else:
            a[j] -= 1


for i in range(n):
    print(answer[i])

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


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

    if flag_1:
        print(-1)
        flag_2=0
        break

if flag_2:
    for i in range(n-1, -1, -1):
        print(result[i])

Solution (Python):
input()
l=list(map(int,input().split(" ")))
N=len(l)
r=[]
for i,x in enumerate(l):
  if x-1 > i:
    r=None
    break
  r.insert(x-1,x)

if r==None:
  print(-1)
else:
  for z in r:
    print(z)

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

result = []

for j in range(0, N):
    b_length = len(b)
    for i in range(0, b_length):
        if b[b_length - 1 - i] == b_length - i:
            result.append(str(b[b_length - 1 - i]))
            b.pop(b_length - 1 - i)
            break

if len(result) < N:
    print(-1)
else:
    result.reverse()
    for r in result:
        print(r)

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

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

def pos(b):
    n = len(b)
    res = False
    for i in range(1,n+1):
        if b[-i] == n+1-i:
            b.pop(-i)
            return True,n+1-i,b
    return False,0,b 

ans = []
for i in range(N):
    possible,j,b = pos(b)
    if not possible:
        print(-1)
        break
    ans.append(j)
if possible:
    for i in range(N-1,-1,-1):
        print(ans[i])

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

Solution (Python):
N = int(input())
bList = [int(x) for x in input().split()]
numset = list(set(bList))
numset.sort(reverse=True)

result = []
for i in range(N, 0, -1):
    okflg = False
    for num in numset:
        kouho = [i+1 for i, x in enumerate(bList) if x == num]
        if num in kouho:
            del bList[num-1]
            result.append(num)
            okflg = True
            break
    if not okflg:
        print('-1')
        quit()

for x in result[::-1]:
    print(x)

Solution (Python):


import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

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

can_solve = True
ans = []
for _i in range(N):
    
    for i in range(len(B)-1,-1,-1):
        b = B[i]
        if i + 1 == b:
            B.pop(i)
            ans.insert(0, b)
            break
    else:
        can_solve = False
        break
if can_solve:
    print("\n".join(map(str,ans)))
else:
    print(-1)

Solution (Python):
def list_input():
    return list(map(int,input().split()))
def map_input():
    return map(int,input().split())
def map_string():
    return input().split()
    
def solve(b):
	res = [0]*(len(b))
	m = max(b)
	
	
	
	
	c = []
	for i in range(len(b)):
		if b[i] == m:
			ind = len(b)-i-2+m
			if(ind < 0 or ind >= len(b)):
				print(-1)
				exit()
			res[ind] = m
		else:
			c.append(b[i])		
	if(c):
		bitch = solve(c)
		j = 0
		for i in bitch:
			while res[j] != 0:
				j += 1
			res[j] = i
	return res			


n = int(input())    
a = list_input()
ans = solve(a)      
for i in ans:
	print(i)

Solution (Python):
def solve():
    n=int(input())
    b=[int(i) for i in input().split()]
    ans=[]
    for i in range(n):
        flag=False
        for i in range(len(b),0,-1):
            if b[i-1]==i:
                ans.append(i)
                del(b[i-1])
                flag=True
                break
        if flag==False:
            print(-1)
            return
    for i in ans[::-1]:
        print(i)

solve()

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

a_list = []
while(1):
    flag_i = -1
    for i in range(n):
        if i+1 == b_list[i]:
            a = b_list[i]
            flag_i = i
    if flag_i == -1:
        break
    a_list.append(a)
    b_list.pop(flag_i)
    n -= 1

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

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
def DP(L):
	if L==[]:
		return 1,[]
	ret=[]
	for i in range(len(L))[::-1]:
		if L[i]==i+1:
			tL=L[:]
			del tL[i]
			f,dp=DP(tL)
			if f==1:
				return 1,[i+1]+dp
			else:
				break
	return -1,[]
f,dp=DP(B)
if f==1:
	for d in dp[::-1]:
		print(d)
else:
	print(-1)

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=[]
for _ in range(n):
  for i in range(1,n+1):
    if A[-i]==n-i+1:
      ANS.append(A[-i])
      del A[-i]
      n-=1
      break
    

for i in ANS[::-1]:
  print(i)

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

Solution (Python):




N = int(input())
b = []
for n,i in enumerate(input().split()):
    b.append(n+1 - int(i))
r = []

for i in range(N):
    for j in range(len(b)):
        if b[-1-j] == 0:
            r.insert(0,len(b)-j)
            del b[-1-j]
            break
        else:
            b[-1-j] -= 1

        if j==len(b)-1:
            print(-1)
            exit()

for i in r:
    print(i)

Solution (Python):
from collections import deque

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

qa = deque([]) 

while len(b) >= 1:
    t = False
    for i in range(len(b), 0, -1):
        if b[i-1] == i:
            b.pop(i-1)
            qa.appendleft(i)
            t = True
            break
    if not(t):
        print(-1)
        break

if t:
    for i in range(len(qa)):
        print(qa[i])

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

ans = []
for i in range(N):
    f = False
    for j in range(N - i - 1, -1, -1):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            f = True
            break
    if not f:
        print(-1)
        break
else:
    for a in reversed(ans):
        print(a)

Solution (Python):
""" AtCoder """

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

a = []

for i in b:
    if i > len(a) + 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()))

answer = [0]*N

def p(b):
  global answer
  
  if sum([1 if i+1==bi else 0 for i,bi in enumerate(b)]) >= 1  and sum([1 if i+1<bi else 0 for i,bi in enumerate(b)]) == 0 :
    x = max([i+1 if i+1==bi else 0 for i,bi in enumerate(b)])
    answer[len(b)-1] = x
    del b[x-1]
    if b:
      p(b)
    return 
  else:
    answer = False
    return
  
p(b)

if answer:
  for _ in answer:
    print(_)
else:
  print('-1')

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

a = []
possible = True
while(len(b) > 0 and possible):
    possible = False
    for i in range(len(b)-1, -1, -1):
        if b[i] == i + 1:
            a = [b.pop(i)] + a
            possible = True            
            break

if possible:
    for a_ in a:
        print(a_)
else:
    print(-1)

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


anslist = []
for i in range(len(b)):
    if i - b[i] + 1 >= 0:
        anslist = anslist[0:i - b[i] + 1] + [b[i]] + anslist[i - b[i] + 1::]

        
    else:
        anslist = False
        break

if not anslist:
    print(-1)
else:
    for i in anslist[::-1]:
        print(i)

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

Solution (Python):
N=int(input())
num_list=list(map(int,input().split()))
length=len(num_list)
result=[]
for trial in range(0,length):
    for i in range(0,len(num_list)):
        
        if(num_list[len(num_list)-1-i]==(len(num_list)-i)):
            del num_list[len(num_list)-1-i]
            
            result=[len(num_list)-i+1]+result
            break
if(len(result)==length):
    for l in range(0,len(result)):
        print(result[l])
else:
    print(-1)

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

Solution (Python):

import sys


def rec(N, b):
    if N == 0:
        return []
    buf = -1
    for i in range(N):
        if b[i] > i+1:
            return [-1]
        if b[i] == i+1:
            buf = i
    if buf == -1:
        
        print("ありえない")
        return [-1]
    a = b.pop(buf)
    return rec(N-1, b) + [a]


def solve(N, b):
    for x in rec(N, b):
        print(x)
    return




def main():
    N = int(input())
    b = [int(x) for x in input().split()]
    solve(N, b)


if __name__ == '__main__':
    main()

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

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

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

def dfs(B,LEN,ANS):
    
    if LEN==0:
        for a in ANS[::-1]:
            print(a)
        sys.exit()
    for i in range(LEN-1,-1,-1):
        if B[i]==i+1:
            C=B[:i]+B[i+1:]
            dfs(C,LEN-1,ANS+[i+1])

dfs(B,N,[])
print(-1)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ansL=[]
c=0
f=0
for j in range(n):
  for i in range(len(l)-1,-1,-1):
    if l[i]==i+1:
      ansL.append(l.pop(i))
      c+=1
      break
if c!=n:
  print(-1)
else:
  for k in range(len(ansL)-1,-1,-1):
    print(ansL[k])

Solution (Python):



import sys
from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator


def IA(): return [int(x) for x in input().split()]


def IM(N): return [IA() for _ in range(N)]


N = int(input())
B = IA()

sys.setrecursionlimit(500)


def f(b, n):
    if n == 0:
        return []
    for i, x in enumerate(b, 1):
        if i < x or n < x:
            return None
    for i, x in enumerate(b, 1):
        if i == x:
            ret = f(tuple(b[:i-1] + b[i:]), n-1)
            if ret is not None:
                return ret + [i]
    return None


ans = f(B, N)
if ans:
    print(*ans, sep="\n")
else:
    print(-1)

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

if sum([(x > idx + 1) for (idx, x) in enumerate(b)]) >= 1:
  print(-1)
else:
  list_ = []
  while len(b) > 0:
    for idx, c in enumerate(b):
      if idx+1 == c:
        del_idx = idx
    list_.append(b.pop(del_idx))

  for c in list_[::-1]:
      print(c)

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
B=IL()
ans=[]
while True:
    flag=False
    for i in range(len(B)):
        if len(B)-i==B[-1-i]:
            ans=[B[-i-1]]+ans
            flag=True
            B.remove(B[-i-1])
            break
    if not flag:
        break
if len(ans)!=n:
    print(-1)
else:
    for i in range(n):
        print(ans[i])

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

def main():
    n = N
    S = []
    while B:
        tmp = -1
        for i in range(n):
            if B[i] == i+1:
                tmp = B[i]
                j = i
        if tmp == -1:
            return -1
        else:
            S.append(B.pop(j))
            n -= 1
    return S[::-1]

res = main()
if res == -1:
    print(-1)
else:
    for i in range(N):
        print(res[i])

Solution (Python):
saiaku=0

n=int(input())
b_list=input().split(' ')

for bl in range(len(b_list)):
    b_list[bl]=int(b_list[bl])


junretu=[]
nagasa=len(b_list)

sakasa=[]

for kaisu in range(nagasa):
    maxn=0
    swit=0
    for i in range(nagasa):
        if b_list[i]==i+1:
            maxn=i 
            swit=1
            
    sakasa.append(maxn+1)
    b_list=b_list[:maxn]+b_list[maxn+1:]
    nagasa=len(b_list)
    if swit==0:
        saiaku=1
    

if saiaku==0:
    shin=[]
    for sks in range(len(sakasa)):
        print(sakasa[len(sakasa)-sks-1])
    """
    for sks in range(len(sakasa)):
        shin.append(sakasa[len(sakasa)-sks-1])
    print(shin)
    """
else:
    print(-1)

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

procedure = [-1]*n
tmp_n = n
for m in range(n-1,-1,-1):
	for i in range(tmp_n-1, -1, -1):
		if b[i] == i+1:
			procedure[m] = i+1
			del b[i]
			tmp_n -= 1
			break
	else:
		print(-1)
		exit()

for i in range(n):
	print(procedure[i])

Solution (Python):
def limited_insertion(N: int, B: list)->list:
    
    if N == 1:
        return [1] if B[0] == 1 else []
    
    
    
    for i in range(N, 0, -1):
        if i == B[i-1]:
            
            
            
            rec = limited_insertion(N-1, B[:i-1] + B[i:])
            if len(rec) > 0:
                return rec + [i]
            else:
                return []

    return []


if __name__ == "__main__":
    N = int(input())
    B = [int(s) for s in input().split()]
    A = limited_insertion(N, B)
    if len(A) == 0:
        print(-1)
    else:
        for a in A:
            print(a)

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
B = len(b)
ans = []
can_t = 0
for i in range(B):
	if can_t == 0:
		judge = 0
		j = 0
		while judge == 0:
			if len(b)- 1 - j < 0:
				can_t = 1
				judge = 1
			elif b[len(b)-j-1] == len(b)-j:
				judge = 1
				ans.append(len(b)-j)
				del b[len(b)-1-j]
			else:
				j += 1

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

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

while(b):
    targ = -1
    for i in range(len(b)):
        
        if b[i] == i+1:
            targ = i
    if targ == -1:
        break
    
    ans.append(b[targ])
    b.pop(targ)


if targ == -1:
    print(-1)
else:
    for i in range(len(ans)):
        print(ans[-1*(1+i)])

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


def solve(b, a):
  
  if len(b) == 0:
    return a

  
  for bb, ii in zip(b, range(1, len(b)+1)):
    if bb > ii:
      return None

  for bb, ii in zip(b, range(1, len(b)+1)):
    if bb == ii:
      
      a_cp = a[:]
      a_cp.append(bb)
      b_cp = b[:]
      b_cp.pop(ii-1)
      ans = solve(b_cp, a_cp)
      if ans is not None:
        return ans

answer = solve(b, [])
if answer == None:
  print(-1)
else:
  for aa in reversed(answer):
    print(aa)

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

b_cur = b
sol = []
while b_cur:
    for i in reversed(range(len(b_cur))):
        if b_cur[i] == i+1:
            sol.append(b_cur[i])
            b_cur = b_cur[:i] + b_cur[i+1:]
            break
    else:
        sol = False
        break
if sol:    
    for i in reversed(sol):
        print(i)
else:
    print(-1)

Solution (Python):


import sys
import math
import collections

N,= map(int, sys.stdin.readline().rstrip().split(" "))
bs = map(int, sys.stdin.readline().rstrip().split(" "))

countdict = collections.defaultdict(list)
for i, b in enumerate(bs):
    countdict[b].append(i+1)


def find_one():
    for i in range(101, 0, -1):
        if i in countdict:
            for j in range(len(countdict[i])):
                if countdict[i][j] == i:
                    del countdict[i][j]
                    return i

def change_pos(pos):
    for counts in countdict.values():
        for i in range(len(counts)):
            if counts[i] > pos:
                counts[i] -= 1

results = []
while True:
    res = find_one()
    if res is None:
        break
    results.append(res)
    change_pos(res)

rest = sum(len(counts) for counts in countdict.values())
if rest > 0:
    print(-1)
else:
    for i in reversed(results):
        print(i)

exit(0)

Solution (Python):
from math import *



n=int(input())
a=list(map(int,input().rstrip().split(" ")))

l=[]

prev=n
new=0
while(prev!=new):
	prev=len(a)

	for i in range(len(a)-1,-1,-1):
		if(i+1==a[i]):
			l.append(a[i])
			a.pop(i)
			break
	new=len(a)

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

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

while len(a) < n and judge != 1:
    c = 0
    for i in range(len(b)):
        if b[i] == i+1:
            c = b[i]
    if c == 0:
        judge = 1
        break
    else:
        a.append(c)
        b.remove(c)

a = a[::-1]
if judge == 1:
    print(-1)
else:
    for i in range(n):
        print(a[i])

Solution (Python):




def main():
    n = int(input())
    lb = list(map(int, input().split()))
    ret = []
    for i in range(n):
        for j in range(n-i, 0, -1):
            if lb[j-1] == j:
                ret.append(lb.pop(j-1))
                break
        else:
            print("-1")
            return
    print("\n".join(map(str, ret[::-1])))



if __name__ == '__main__':
    main()

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
b=rl()

def ANS():
    ans = []
    for i in range(N):
        rm_i = -1
        for j in range(N-i):
            if b[j] == (j+1):
                rm_i = j
            if j==(N-i-1) and rm_i==-1:
                return -1
        ans.append(b.pop(rm_i))
    return ans
    
res = ANS()
if res==-1:
    print('-1')
else:
    for r in res[::-1]:
        print(r)