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):
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):
import sys
sys.setrecursionlimit(1000000)



'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  
print(sorted(a, key=itemgetter(0)))  
print(sorted(a, key=itemgetter(0, 2)))  
print(sorted(a, key=lambda x: x[0] * x[2]))  
print(sorted(a, reverse=True))  
a.sort()  
try: 
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
3
1 2 1
'''

test_data2 = '''\
2 3 0
4 5 6
7 8 9
-1 2 -5
'''

test_data3 = '''\
9
1 1 1 2 2 1 2 3 2
'''
td_num=3

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        
        n=int(f.readline())
        b=list(map(int,f.readline().split()))
        
else:
    for i in range(1):
        
        n=int(input())
        b=list(map(int,input().split()))
        

ans=[]

cnt=0
while cnt<100 and len(b)>0:
    m=len(b)
    cnt+=1
    flg=False
    for i in range(m):
        
        if b[m-1-i]==m-i:
            ans.append(b.pop(m-1-i))
            
            flg=True
            break
    if flg==False:
        break
if len(ans)==n:
    for i in range(n):
        print(ans[-i-1])
else:
    print(-1)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()
ans=[]
while len(arr)>0:
    chk=False
    maxtmp=0
    for i,j in enumerate(arr):
        
        if i+1==j:
            maxtmp=j-1
            chk=True
    p=arr.pop(maxtmp)
    ans.append(p)
    if chk==False:
        print(-1)
        exit()
    

k=reversed(ans)
for i,j in enumerate(k):
    print(j)

Solution (Python):


def myAnswer(N:int,B:list) -> None:
   ans = []
   for n,b in enumerate(B):
      if(n + 1 < b):
         print(-1)
         return
   
   while len(B) > 0:
      tmp = 0
      for n,b in enumerate(B):
         if(n + 1 == b):
            tmp = n
      ans.append(B[tmp])
      B.pop(tmp)
   for a in ans[::-1]:
      print(a)
   
def modelAnswer():
   return
def main():
   N = int(input())
   B = list(map(int,input().split()))
   myAnswer(N,B)
if __name__ == '__main__':
   main()

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=[]

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

Solution (Python):
def m():
    N = int(input())
    B = list(map(int, input().split()))
    ans = []
    while B:
        f = True
        for i in reversed(range(len(B))):
            if B[i] == i+1:
                B.pop(i)
                ans.append(i+1)
                f = False
                break
        if f: return print('-1')
    ans.reverse()
    for i in ans:
        print(i)
    return


m()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = IL()
ans = []
flag = 1
while flag:
  flag = 0
  for i in range(N)[::-1]:
    if i+1 == A[i]:
      ans.append(A[i])
      A = A[:i]+A[i+1:]
      N -= 1
      flag = 1
      break
if A:
  print(-1)
else:
  for a in ans[::-1]:
    print(a)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    ans = []
    while len(ans) < N:
        cnt = 0
        cnti = -1
        for i in range(N):
            if B[i] == 0:
                cnt += 1
            else:
                if B[i] == i - cnt + 1:
                    cnti = i
        if cnti == -1:
            print(-1)
            return
        else:
            ans.append(B[cnti])
            B[cnti] = 0

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


if __name__ == '__main__':
    main()

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

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

for num in lst[::-1]:
    print(num)

Solution (Python):
from collections import deque

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

result = deque([])
while b:
    for i in range(len(b) - 1, -1, -1):
        if b[i] == i + 1:
            result.appendleft(b.pop(i))
            break
    else:
        break

if not b:
    print('\n'.join(str(i) for i in result))
else:
    print(-1)

Solution (Python):
from collections import deque

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

result = deque([])
while b:
    t = len(result)
    for i in range(len(b) - 1, -1, -1):
        if b[i] == i + 1:
            result.appendleft(b.pop(i))
            break
    if len(result) == t:
        break

if not b:
    print('\n'.join(str(i) for i in result))
else:
    print(-1)

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
b = inl()
ans = []
for i in range(n):
    
    
    
    for j in range(n-i-1,-1,-1):
        if b[j]==j+1:
            ans.append(j+1)
            for k in range(j,n-i-1):
                b[k] = b[k+1]
            break
    if len(ans)<i+1:
        print(-1)
        exit()
ans.reverse()
for x in ans:
    print(x)

Solution (Python):
N = int(input())
B = list(map(lambda x: int(x) - 1, input().split()))
for i in range(N):
    if B[i] > i:
        print(-1)
        break
else:
    ans = []
    for _ in range(N):
        for i in range(len(B) - 1, -1, -1):
            if B[i] == i:
                ans.append(i)
                B = B[:i] + B[i + 1 :]
                break
    print("\n".join(map(lambda x: str(x + 1), ans[::-1])))

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):
def main():
    n, *b = map(int, open(0).read().split())

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

    print('\n'.join(map(str, m[::-1])))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, *b = map(int, open(0).read().split())

    m = []
    for k in range(1, n+1):
        for i in range(n - k, -1, -1):
            if b[i] == i + 1:
                b.pop(i)
                m.append(i+1)
                break

    if len(b) > 0:
        print(-1)
    else:
        print('\n'.join(map(str, m[::-1])))


if __name__ == '__main__':
    main()

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

Solution (Python):
def solve():
    N = input()
    a = ['']
    for i in input().split():
        a.insert(int(i)-1, i)
    print(*a[-1]and[-1]or a)

solve()

Solution (Python):
from queue import Queue

def solve():
    N = int(input())
    b = list(map(int, input().split()))
    idx = [i+1 for i in reversed(range(N))]
    
    l = []
    for i in range(N):
        for bi, j in zip(reversed(b), idx):
            if j == bi:
                l.append(str(j))
                break
        del idx[0], b[j-1]
    
    return '\n'.join(reversed(l)) if len(l) == N else -1

print(solve())

Solution (Python):

n, *b = map(int, open(0).read().split())
l = []
while True:
    F = 1
    for i, j in enumerate(b[::-1]):
        if len(b) - i == j:
            del b[len(b) - i - 1]
            l += j,
            F = 0
            break
    if F:
        break
if b:
    exit(print(-1))
for i in l[::-1]:
    print(i)

Solution (Python):
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")



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

    ans = []
    for _ in range(N):
        x = -1
        for j in range(len(B)):
            if B[j] == j + 1:
                x = j
        if x == -1:
            break
        ans.append(B.pop(x))
    
    if len(B) == 0:
        for i in reversed(range(N)):
            print(ans[i])
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
b=list(map(int,input().split()))
ans=[]
turn=N
while(b):
    last=-1
    for i in range(len(b)):
        if i+1==b[i]:
            last=i
    if last==-1:
        print(-1)
        exit()
    ans.append(last+1)
    del b[last]
    
print(*ans[::-1],sep='\n')

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

ans = []
l = len(b)
while l > 0:
    for i in range(l):
        ii = l - i
        if b[ii-1] == ii:
            ans.append(ii)
            del b[ii-1]
            l = l - 1
            break
    else:
        print(-1)
        exit(0)

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

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

a = []
for i in range(n):
    p = -1
    for j in range(len(b)-1, -1, -1):
        if b[j] == j + 1:
            p = j + 1
            break
    if p == -1:
        print(-1)
        exit()
    a.append(p)
    b.remove(p)

a.reverse()
print('\n'.join(map(str, a)))

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

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

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

ans = [0] * N
for i in range(N):
    for j in reversed(range(len(B))):
        if j == B[j] - 1:
            ans[i] = B[j]
            if len(B) > 0:
                B.pop(j)
            break

if 0 in ans:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
    if b[i] > i + 1:
        print(-1)
        exit()
L = []
i = 1
while i <= n:
    for j in range(1, len(b)+1):
        if b[j-1] == j:
            m = j
    L.append(m)
    b.pop(m-1)
    i += 1
for l in reversed(L):
    print(l)

Solution (Python):
N=int(input())
b=list(map(int,input().split()))
ans=[]
for i in range(N):
    n=len(b)
    cond=True
    for j in range(n):
        if n-j==b[n-j-1]:
            del b[n-j-1]
            ans.append(n-j)
            cond=False
            break
    if cond:
        ans=[-1]
        break
for a in range(len(ans)):
    print(ans[len(ans)-a-1])

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
    if b[i] > i + 1:
        print(-1)
        exit()
L = []
i = 1
while i <= n:
    for j in range(1, len(b)+1):
        if b[j-1] == j:
            m = j
    L.append(m)
    b.pop(m-1)
    i += 1
for l in reversed(L):
    print(l)

Solution (Python):
def f():
    res = []
    for i in range(n):
        pivot = -1
        for j in range(len(LIST)-1,-1,-1):
            if LIST[j] == j:
                pivot = j
                break
        if pivot == -1:
            print(-1)
            exit()
        res.append(pivot+1)
        LIST.pop(pivot)
    res = res[::-1]
    
    for v in res:
        print(v)



n = int(input())
LIST = list(map(lambda x:int(x)-1,input().split()))
f()

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

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

ans = []

for k in range(N):
    flag = True
    for i, b in enumerate(reversed(B)):
        if N - k - i == b:
            ans.append(B.pop(b-1))
            flag = False
            break
    if flag:
        print(-1)
        exit()

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

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, 0, -1):
    cp = np.arange(1, i + 1)
    diff = b - cp
    if np.where(diff == 0)[0].shape[0] == 0:
        print(-1)
        sys.exit()
    else:
        rem = (np.where(diff == 0)[0]).max()
        ans.append(b[rem])
        b = np.delete(b, rem, axis=0)

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

Solution (Python):
import sys


import math
import collections

import bisect

import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    a = na()

    ans = []
    while len(a) > 0:
        flg = True
        for i in range(len(a) - 1, -1, -1):
            if i + 1 == a[i]:
                ans.append(i + 1)
                del a[i]
                flg = False
                break
        if flg:
            print(-1)
            exit(0)

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


if __name__ == '__main__':
    main()

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

c = b[:]
ans = []
jdg = True

while c:
    temp = []
    for i in range(len(c)):
        if i + 1 - c[i] == 0:
            temp.append([c[i], i])
    if not temp:
        jdg = False
        break
    l = max(temp)
    c = c[:l[1]] + c[l[1]+1:]
    ans.append(l[0])

if jdg:
    ans.reverse()
    print(*ans, sep='\n')
else: print(-1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())



n = I()
B = LI()

ANS = []
for _ in range(n):
    for i in reversed(range(len(B))):
        if i+1 == B[i]:
            ANS.append(B.pop(i))
            break
    else:
        print(-1)
        exit()

ANS.reverse()
for ans in ANS:
    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():

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

        while len(B) > 0:
            flag = False

            for i in reversed(range(len(B))):
                if B[i] == i+1:
                    ans.append(B[i])
                    B.pop(i)
                    flag = True
                    break
            if not flag:
                return None

        return ans


    ans=main()
    if ans:
        for i in reversed(ans):
            print(i)
    else:
        print(-1)

resolve()

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

a = []

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

if len(a) != n:
    print(-1)
    exit()

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


def main():
    ans = []
    while B:
        for i in range(len(B), 0, -1):
            if i == B[i - 1]:
                ans.append(B.pop(i - 1))
                break
        else:
            print(-1)
            return
    print(*reversed(ans), sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


def main():
    ans = []
    while B:
        found = False
        for i in range(len(B), 0, -1):
            if i == B[i - 1]:
                ans.append(i)
                del B[i - 1]
                found = True
                break
        if not found:
            print(-1)
            return
    print(*reversed(ans), sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
from sys import exit

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

cnt = [0] * n
done = [False] * n
ans = [0] * n
for i in range(n):
  for j in range(n-1, -1, -1):
    if done[j]:
      continue
    if b[j] == cnt[j] + 1:
      ans[i] = b[j]
      for k in range(j+1, n):
        cnt[k] += 1
      done[j] = True
      break
        
for i in range(n):
  if not done[i]:
    print(-1)
    exit()
    
for i in range(n):
  print(ans[i])

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

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

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

ans_li = []
for i in range(n):
    for j in range(len(B)-1,0,-1):
        if j==B[j]:
            ans_li.append(B.pop(j))
            break
    else:
        print(-1);exit()
print('\n'.join(map(str,ans_li[::-1])))

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

def f(c):
    for i in reversed(range(len(c))):
        if c[i] == i+1:
            return (c[i], c[:i] + c[i+1:])
    return (-1, c)

ans = []
for i in range(n):
    (a, b) = f(b)
    if a == -1:
        print(-1)
        exit()
    ans.append(a)
    

print('\n'.join(map(str, reversed(ans))))

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

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

def dfs(s, ans):
    if len(s) == 0:
        print('\n'.join(map(str, reversed(ans))))
        exit()
        return
    for i in range(len(s)):
        
        
        if s[i] == i+1:
            s1 = s[:i] + s[i+1:]
            allok = True
            for j in range(len(s1)):
                if s1[j] > j+1:
                    allok = False
                    break
            
            if allok:
                ans.append(s[i])
                dfs(s1, ans)
    if len(ans) > 0:
        ans.pop()

dfs(b, [])

print('-1')

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


result=[]

for i in range(n):
    posi=-1
    for index,ss in enumerate(s):
        if ss==index+1:
            posi=index
    if posi==-1:
        print(-1)
        exit()
    else:
        result.append(s[posi])
        s.pop(posi)

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

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
b = LI()

ans = []
while b:
    n = len(b)
    flag = False
    for i in range(n)[::-1]:
        if b[i] == i+1:
            ans.append(i+1)
            flag = True
            break
    if not flag:
        print(-1)
        exit()
    b.pop(i)

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

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

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

Solution (Python):




import math
import sys
import bisect
import heapq  
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
b = list(map(int, input().split()))
ans = []
while b:
    ind = -1
    for i,c in enumerate(b):
        if i+1 == c:
            ind = i
    if ind == -1:
        print(-1)
        sys.exit()
    ans.append(b.pop(ind))
ans.reverse()
for tmp in ans:
    print(tmp)

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

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

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

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

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

n = ni()
a = na()

ok = True
ans = deque()

s = sum(a)
cur_n = n
while s:
    pos = 0
    flag = False
    i = n - 1
    j = cur_n - 1
    while i >= 0:
        if a[i] == 0:
            i -= 1
            continue
        if a[i] == j + 1:
            flag = True
            pos = i
            break
        j -= 1
        i -= 1

    if flag:
        ans.appendleft(a[pos])
        s -= a[pos]
        a[pos] = 0
        cur_n -= 1
    else:
        print(-1)
        exit()

print(*ans)

Solution (Python):


N,b = int(input()),list(map(int,input().split()))
a = list([])
judge = 1

for i in range(N):
    j = N-i
    while j>0 and b[j-1]!=j:
        j -= 1
    if j==0:
        judge = 0
        break
    else:
        b.pop(j-1)
        a.append(j)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *b = map(int, read().split())
ans = [0] * n
idx = 0
for i in range(n):
    for j, bb in enumerate(b):
        if j + 1 == bb:
            ans[i] = bb
            idx = j
    if ans[i] == 0:
        print(-1)
        exit()
    b.pop(idx)
print('\n'.join(map(str, ans[::-1])))

Solution (Python):
def main():
    from collections import deque
    N = int(input())
    B = deque(list(map(int, input().split())))
    result = deque([])
    for i in range(N):
        flag = False
        for j in range(len(B), 0, -1):
            b = B[j-1]
            if j == b:
                del B[j-1]
                result.append(b)
                flag = True
                break
        if not flag:
            print(-1)
            return
    for j in range(len(result)-1, -1, -1):
        print(result[j])
main()

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

ans = []
while b != []:
    flag = True
    for i in range(len(b)-1, -1, -1):
        if b[i]-i-1 == 0:
            flag = False
            ans.append(b.pop(i))
            break
    if flag:
        print(-1)
        exit()
for i in range(n-1, -1, -1):
    print(ans[i])

Solution (Python):
n = int(input())
B = list(map(int, input().split()))
ans = []
for _ in range(n):
    for i in reversed(range(len(B))):
        if B[i] == i+1:
            x = B.pop(i)
            ans.append(x)
            break
if len(ans) == n:
    print(*ans[::-1], sep='\n')
else:
    print(-1)

Solution (Python):
n = int(input())
B = list(map(int, input().split()))
A = []
for b in B:
    A.insert(b-1, b)
if all(A[i] <= i+1 for i in range(n)):
    C = []
    for a in A:
        C.insert(a-1, a)
    if B == C:
        print(*A, sep='\n')
    else:
        print(-1)
else:
    print(-1)