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):
from collections import deque
import sys

N = int(input())

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

q = deque([])

q.append([b,[]])

dic = {}

while len(q) > 0:

    now = q.pop()

    nb = now[0]
    nc = now[1]

    for i in range(len(nb)):

        i = len(nb) - i - 1

        if (i+1) == nb[i]:

            nex = []
            nec = []
            for j in range(len(nb)):
                if j != i:
                    nex.append(nb[j])
            for j in range(len(nc)):
                nec.append(nc[j])
            
            nec.append(nb[i])
            

            s = " ".join(map(str,nex))
            if s in dic:
                continue
            dic[s] = 1

            if len(nex) == 0:
                nec.reverse()
                print (" ".join(map(str,nec)))
                sys.exit()

            q.append([nex,nec])
            break

print (-1)

Solution (Python):
n = int(input())
lst_b = list(map(int,input().split()))
lst_a = []
i = 0
while True:
    if len(lst_b) == 0:
        break
    else:
        for i in range(len(lst_b)-1,-1,-1):
            if lst_b[i] == i+1:
                lst_a.append(lst_b.pop(i))
                break
            elif i == 0:
                print(-1)
                exit()

lst_a.reverse()

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

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

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

l=[]
f=True
for i in range(1,N+1):
    if not f:
        break
    for j in range(N+1-i,0,-1):
        if b[j]==j:
            l.append(b.pop(j))
            break
        if j==1:
            f=False

if f:
    for k in l[::-1]:
        print(k)
else:
    print(-1)

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

a=[]
while b:
    f=True
    if len(b)==1:
        if b[0]!=1:
            print(-1)
            exit()
        else:
            a.append(b.pop())
        break
    for i in range(len(b)-1,-1,-1):
        if b[i]==i+1:
            temp=b.pop(i)
            a.append(temp)
            f=False
            break
    if f:
        print(-1)
        exit()

for i in range(N):
    print(a[-1*(i+1)])

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

ans = []
for i in range(n):
    tmp = -1
    for j, k in enumerate(b):
        if j + 1 == k:
            tmp = j
    if tmp == -1:
        print(-1)
        exit()
    else:
        ans.append(b.pop(tmp))
print(*ans[::-1], sep="\n")

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


    ok = True
    r = []
    while len(B) != 0:
        match = []
        for i, bi in enumerate(B):
            n = i+1
            if n == bi:
                match.append(i)

        if len(match) == 0:
            ok = False
            break

        t = match[-1]
        r.append(t)
        B.pop(t)
        match = []

    if ok:
        for ri in r[::-1]:
            print(ri + 1)
    else:
        print(-1)



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
M = 0
for i in range(N):
  if B[i] > i+1:
    M = -1
if M != -1:
  L = []
  for j in range(N):
    s = 0
    for k in range(len(B)):
      if B[k] == k+1:
        s = k
    L.insert(0, s+1)
    del B[s]
  for m in range(N):
    print(L[m])
else:
  print(M)

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))[::-1]:
        if b[j] == j+1:
            ans.append(b.pop(j))
            break
        if j == 0:
            print(-1)
            sys.exit()
    
for i in range(N)[::-1]:
    print(ans[i])

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = []
i = len(B) - 1
flag = True

while B != []:
    if i < 0:
        flag = False
        break

    if i + 1 == B[i]:
        A.append(B.pop(i))
        i = len(B) - 1
    else:
        i -= 1


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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))[::-1]
ans = []
for i in range(n):
  for k,v in enumerate(a):
    num = n - i - k
    if num == v:
      b = a.pop(k)
      ans.append(b)
      break
  else:
    ans = 0
    break
if not ans:
  print(-1)
else:
  for i in ans[::-1]:
    print(i)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = []
for x in a:
  if len(res) + 1 < x:
    print(-1)
    exit(0)
  res.insert(x - 1, x)
for r in res: print(r)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
b=[]
for i in range(n):
  for j in range(n-i)[::-1]:
    if l[j]==j+1:
      del l[j]
      b.append(j+1)
      break
  else:
    print(-1)
    exit()
print(*b[::-1],sep="\n")

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

ans = [None] * N

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

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

Solution (Python):
def examA():
    N = I()
    B = LI()
    ans = [0]*N
    flag = False
    for i in range(N-1,-1,-1):
        for j in range(i,-1,-1):
            if j+1==B[j]:
                ans[i] = B[j]
                del B[j]
                break
        if ans[i]==0:
            print("-1")
            flag = True
            break
    if not flag:
        for v in ans:
            print(v)

from string import digits
import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


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

    A = []
    while B:
        for i in range(len(B)-1, -1, -1):
            if B[i] == i+1:
                A.append(B[i])
                del B[i]
                break

        else:
            print(-1)
            sys.exit()

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


main()

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

l = [n]
ans = []
for i in range(n):
    x = 0
    f = 0
    for j in range(i+1):
        if i+1-j in b[x:l[j]]:
            ans.append(i+1-j)
            l.append(b.index(i+1-j))
            b[l[-1]] = 0
            l.sort()
            f = 1
            break
        x = l[j]
    if f == 0:
        print(-1)
        exit()

for i in ans:
    print(i)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
b=True
ans=[]
for i in range(n):
  index=-1
  for j in range(n-i):
    if l[j]>j+1:
      b=False
      index=-1
      break
    if l[j]==j+1:
      index=j
  if index==-1:
    b=False
    break
  ans.append(l[index])
  del l[index]
if not b:
  print(-1)
else:
  for i in range(1,n+1):
    print(ans[-i])

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    key = 0
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
if b[0] != 1:
  flag = 1
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

Solution (Python):

import sys
from collections import deque 

def main():
    n, *b = map(int, sys.stdin.read().split())
    b = [None] + b

    for i in range(1, n+1):
        if b[i] > i:
            print(-1)
            exit()
    
    res = deque()
    while len(b) > 1:
        for i in range(len(b)-1, 0, -1):
            if b[i] == i:
                res.appendleft(b.pop(i))
                break
         
    print('\n'.join(map(str, res)))

if __name__ == '__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


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

    A = []
    while B:
        for i in range(len(B)-1, -1, -1):
            if B[i] == i+1:
                A.append(B[i])
                del B[i]
                break

        else:
            print(-1)
            sys.exit()

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


main()

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

sousa = []

for i in range(N,0,-1):
  for j in range(i,0,-1):
    if B[j-1] == j:
      sousa.append(j)
      del B[j-1]
      break
      
  if j <= 0:
    break
    
if len(B) > 0:
  print(-1)
  exit(0)


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

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

sousa = []

for i in range(N,0,-1):
  for j in range(i,0,-1):
    if B[j-1] == j:
      sousa.append(j)
      del B[j-1]
      break
      
  if j <= 0:
    break
    
if len(B) > 0:
  print(-1)
  exit(0)


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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans_list = []
for i in range(N):
    for k in range(len(B)-1, -1, -1):
        if B[k] == k+1:
            ans_list.append(B[k])
            del B[k]
            break
        if k == 0:
            print(-1)
            exit()
for k in range(len(ans_list)):
    print(ans_list[- 1 - k])

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

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

def solve() :
    ret = []
    while len(b) != 0 :
        M = -1
        for i in range(len(b)) :
            if i + 1 == b[i] :
                M = i
        
        if M == -1 :
            print(-1)
            return 
        
        ret.append(b.pop(M))
    
    for r in ret[::-1] :
        print(r)
        
solve()

Solution (Python):

import sys

input = sys.stdin.readline


sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
ans = []
i = N-1
while i != 0:
    x = len(B)
    for j in range(i,-1,-1):
        if B[j] == j+1:
            B.pop(j)
            ans.append(j+1)
            i -= 1
            break
    if x == len(B):
        break
if len(B) == 1 and B[0] == 1:
    ans.append(1)
    print(*ans[::-1],sep="\n")
else:
    print(-1)

Solution (Python):
n=int(input())
import copy
b=list(map(int,input().split()))
c=copy.copy(b)
ans=[]
for _ in range(n):
	rem=-1
	cnt=0
	for j in range(n):
		if b[j]==j+1-cnt:
			rem=j
		if b[j]==0:
			cnt+=1
	if rem==-1:
		print(-1)
		exit()
	ans.append(rem)
	b[rem]=0
for i in range(n):
	p=ans[-i-1]
	print(c[p])

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

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

while(len(S)>0):
    c=10**10
    for i in range (len(S)):
        if(S[i]==i+1):
            c=i
    if(c==(10**10)):
        print("-1")
        exit()  
    LIST.append(S.pop(c))

for i in range(len(LIST)-1,-1,-1):
    print(LIST[i])

Solution (Python):

import copy
N = int(input())
b = list(map(int,input().split()))
flag = True
ans = copy.copy(b)
for i in range(N):
    check = i + 1 - b[i]
    if check < 0:
        flag = False
        break
    elif check > 0:
        ans.insert(b[i]-1,ans.pop(i))

if flag:
    for i in ans:
        print(i)
else:
    print('-1')

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

    ans = []

    i = N-1
    while i >= 0:
        if b[i] == i + 1:
            ans.append(b[i])
            del b[i]
            i = len(b) - 1
        else:
            i -= 1

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

if __name__ == '__main__':
    solve()

Solution (Python):

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

for i in range(N):
    tmp = -1
    for j in range(N - i):
        if b[j] == j + 1:
            tmp = j
            
    if tmp != -1:
        a.append(b.pop(tmp))

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

Solution (Python):
import math
import heapq
import sys
from collections import Counter




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

a=[]

for i in range(1,N+1):
    for k in reversed(range(len(b))):
        
        if k+1==int(b[k]):
            a.insert(0,b.pop(k))
            break
if len(a)==N:
    for i in a:
        print(int(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(1,len(b)+1):
        if b[-j]==len(b)+1-j:
            ans.append(b[-j])
            del(b[-j])
            break

if len(b)!=0:
    print(-1)
    exit()

ans.reverse()

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

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


ans = []
i = len(b)-1
while(1):
    if i == -1:
        print("-1")
        exit()
    if b[i] == i + 1:
        
        ans.append(b.pop(i))
        if len(b) == 0:
            break
        i = len(b)-1
    else:
        i -= 1



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

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

def solve(inlist):
    if inlist == []:
        return []
    else:
        p = max([ i for i, v in enumerate(inlist,1) if i == v ])
        new_list = [ v for i, v in enumerate(inlist,1) if i != p ]
        return solve(new_list) + [p]

if all([ v <= i for i, v in enumerate(num,1) ]):
    for i in solve(num):
        print(i)
else:
    print(-1)

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

def solve(inlist):
    if inlist == []:
        return []
    else:
        p = 0
        for i, v in enumerate(inlist):
            if v-1 == i:
                p = i
        new_list = [ v for i, v in enumerate(inlist) if i != p ]
        return solve(new_list) + [p+1]

if all([ v <= i for i, v in enumerate(num,1) ]):
    for i in solve(num):
        print(i)
else:
    print(-1)

solve(num)

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

ans=[-1]*N
for i in reversed(range(N)):
  for j in reversed(range(1,i+2)):
    br=0
    if b[j-1]==j:
      ans[i]=j
      b.pop(j-1)
      br=1
      break
  if br==0:
    print(-1)
    exit()
      
for i in ans:
  print(i)

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

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

        else:
            ans = [-1]
            break

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


if __name__ == "__main__":
    main()

Solution (Python):
class Node:
    def __init__(self, prev, val, next):
        self.prev = prev
        self.val = val
        self.next = next


NIL = 0
START = -1
END = -2


class List:
    def __init__(self, li):
        li.append(END)
        self.li = [Node(NIL, START, NIL)]
        for e in li:
            node = Node(self.li[-1], e, NIL)
            self.li[-1].next = node
            self.li.append(node)

        self.l = len(self.li) - 1
        self.ans = []

    def step(self):
        i = self.l
        u = self.li[-1]
        while u.val != START:
            if u.val == i:
                u.prev.next = u.next
                u.next.prev = u.prev
                self.ans.append(u.val)
                self.l -= 1
                return True

            else:
                u = u.prev
                i -= 1

        self.ans = [-1]
        return False

    def solve(self):
        for _ in range(self.l - 1):
            if not self.step():
                break

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


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

    l = List(b)
    l.solve()


if __name__ == "__main__":
    main()

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

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

Solution (Python):


N = int(input().split()[0])
b_list = list(map(int, input().split()))
w_list = b_list[:]


is_ok = True
ans_list = []



while w_list:
    kouho_list = [i for i, w in enumerate(w_list) if w == i + 1]
    if not kouho_list:
        is_ok = False
        break

    
    
    kouho_list = list(reversed(kouho_list))
    ans_list.append(w_list.pop(kouho_list[0]))

if is_ok:
    ans_list = [str(x) for x in reversed(ans_list)]
    ans = "\n".join(ans_list)
else:
    ans = -1
print(ans)

Solution (Python):
N = int(input())
N0 = N
B = list(map(int,input().split()))
ans = []
i = N-1
while i >= 0:
    if B[i] == i+1:
        ans.append(i+1)
        B.pop(i)
        N -= 1
        i = N-1
    else:
        i -= 1
if len(ans) == N0:
    for a in reversed(ans):
        print(a)
else:
    print(-1)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = []
for i in range(n):
    for j in range(len(a))[::-1]:
        if a[j] == j+1:
            res.append(a[j])
            del a[j]
            break
    else:
        print(-1)
        quit()
for i in range(n)[::-1]:
    print(res[i])

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = []
for i in range(n):
    for j in range(len(a))[::-1]:
        
        if a[j] > j+1:
            print(-1)
            quit()
        elif a[j] == j+1:
            res.append(a[j])
            del a[j]
            break
    
for i in range(n)[::-1]:
    print(res[i])

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

    ans = list()

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

            if j is 0:
                print(-1)
                exit()
    for i in reversed(range(N)):
        print(ans[i])

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

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

Solution (Python):

import copy



mod=10**9+7
def factorial(x): 
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): 
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): 
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    
    
    
    
    
    
    
    
    
    n = int(input())
    b = list(map(int,input().split()))
    key=0
    for i in range(n):
        if b[i]<=i+1:
            True
        else:
            key=1
            break
    if key==1:
        print(-1)
    else:
        ans=[]
        while b!=[]:
            for i in range(len(b)):
                if b[len(b)-1-i]==len(b)-i:
                    ans.append(b.pop(len(b)-1-i))
                    break
        ans.reverse()
        for i in range(len(ans)):
            print(ans[i])

main()

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

        if j==0:
            print(-1)
            exit()
for i in reversed(range(n)):
    print(ans[i])

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

for i in range(N, 0, -1):
    for j in range(len(b) - 1, 0, -1):
        if j == b[j]:
            answer.append(j)
            b.remove(j)
            break
    else:
        print(-1)
        exit()
else:
    print('\n'.join(map(str, reversed(answer))))

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

while len(b) > 0:
    for i, v in zip(b[::-1], range(len(b), 0, -1)):
        if i == v:
            removed.append(b.pop(i - 1))
            break
    else:
        removed = [-1]
        break

for r in removed[::-1]:
    print(r)

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

Solution (Python):
import copy

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


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

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

print(*reversed(A),sep="\n")

Solution (Python):
def main():
    n = int(input())
    b = list(map(int,input().split()))
    f = []
    res = []
    while b:
        for i in range(len(b)):
            if i+1 == b[i]:
                f.append(i)
        if f:
            tg = max(f)
        else:
            print(-1)
            return False
        res.append(tg+1)
        b.pop(tg)
        f.clear()
    
    res.reverse()
    for r in res:
        print(r)

main()

Solution (Python):
N = int(input())
array = input().split()
flag = True
lst = [0]
for i in range(1, N+1):
        x = int(array[i-1])
        if len(lst) < x:
            flag = False
            break
        lst.insert(x, x)

if flag:
    for i in lst[1:]:
        print(i)
else:
    print(-1)

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()

ans = []

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

print(' '.join([str(_) for _ in reversed(ans)]))

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

def a():
    A = []
    while len(B) > 0:
        lb = len(B)
        for i in range(len(B)-1, -1, -1):
            if i == B[i]-1:
                A.append(B[i])
                t = B.pop(i)
                break
        if len(B) == lb:
            return -1
    return A

aa = a()
if aa != -1:
    for i in aa[::-1]:
        print(i)
else:
    print(-1)

Solution (Python):


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

while l:
    if pre==l:
        print(-1)
        exit()
    pre.clear()
    pre+=l
    for i in range(len(l))[::-1]:
        if l[i]==i+1:
            ans.append(l.pop(i))
            break

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

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())

T = []

for i in A:
    if len(T) >= i - 1:
        T.insert(i - 1, i)
    else:
        print -1
        quit()

for i in T:
    print i

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

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

len = n
for j in range(n-1,-1,-1):
    len -= 1
    for i in range(min(j,len),-1,-1):

        if b[i]== i+1:
            ans.append(i)
            b.pop(i)
            break
                
ans.reverse()
if not b:
    for i in range(n):
        print(ans[i] + 1)
else:
    print(-1)

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

ans = []
for _ in range(n):
    
    check = 0
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            del b[i]
            ans.append(i+1)
            check = 1
            break
    if check == 0:
        print(-1)
        exit()

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

Solution (Python):
import sys

sys.setrecursionlimit(10**7)

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

used = [False] * n
res = []


def f(index):
    for j in range(n):
        for i in reversed(range(index, n)):
            if not used[i] and ls[i] == sum(used[:i]) + 1:
                used[i] = True
                res.append(ls[i])
                f(i)
        if sum(used[index:]) == n - index:
            break


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

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

ans = []
while(len(B) > 0):
  for i in range(len(B)):
    if B[i] > i+1:
      print(-1)
      exit()
    if B[i] == i+1:
      a = i+1
  ans.append(a)
  if a == 1:
    B = B[a:]
  elif a == len(B):
    B = B[:a-1]
  else:
    B = B[:a-1]+B[a:]
for i in range(len(ans)):
  print(ans[-i-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(b.pop(i))
            break
    else:
        ans = [-1]
        break

ans.reverse()
print(*ans, sep="\n")

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
res = []
while 0 < len(B):
    index = None
    for i, b in enumerate(B, 1):
        if i == b:
            index = i
    if index is None:
        print(-1)
        exit()
    else:
        res.append(B[index-1])
    del B[index-1]
for x in res[::-1]:
    print(x)

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

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

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

Solution (Python):
N = int(input())
bs = list(map(int, input().split()))
js = []
for i in range(N):
  k = -1
  for j in reversed(range(N-i)):
    if bs[j] == j+1:
      k = j
      break
  if k < 0:
    break
  js.append(k)
  bs.pop(j)
if not len(js) == N:
  print(-1)
  exit()
for j in reversed(js):
  print(j+1)

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

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

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

def solve(A):
  res = []
  while len(A) > 0:
    k = -1
    i = 0
    while i < len(A):
      if A[i] == (i+1):
        k = i
      i += 1
    if k == -1:
      return -1
    res.append(k+1)
    A = A[:k] + A[k+1:]
  return res[::-1]

res = solve(A)
if res == -1:
  print(res)
else:
  print("\n".join(map(str,res)))

Solution (Python):
n=int(input())
b=[int(i) for i in input().split()]
c=[]
for _ in range(n):
  for i in range(len(b)-1,-1,-1):
    if i+1==b[i]:
      del b[i]
      c.append(i+1)
      break
  else:
    print(-1)
    exit()
for i in c[::-1]:
  print(i)