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()))
q=[]
f=True
while(b and f):
    ma=len(b)
    for i in range(ma):
        tar=ma-i
        if b[ma-i-1]==tar:
            q.append(b.pop(ma-i-1))
            break
    else:
        f=False
        break
if f:
    for i in range(n):
        x=q.pop()
        print(x)
else:
    print(-1)

Solution (Python):
t = int(input())
a = []
a = list(map(int, input().split()))
answer = []

pos = True
while len(a) > 0:
    for i in range(len(a)-1, -1 ,-1):
        if a[i] == i+1:
            temp = a.pop(i)
            answer.append(temp)
            break
    else:
        pos = False
        break

if pos == True:
    for i in answer[::-1]:
        print(i)
else:
    print(-1)

Solution (Python):
size = int(input())
sequence = list(map(int, input().split()))

answer = []
while len(sequence):
  if not any(sequence[i] == i + 1 for i in range(len(sequence))):
    print(-1)
    exit()
  for i in reversed(range(len(sequence))):
    if sequence[i] == i + 1:
      answer.append(sequence[i])
      sequence.pop(i)
      break

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

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 += [b.pop(i)]
            break

    else:
        print(-1)
        exit()

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

Solution (Python):
N = int(input())
n = N
B = list(map(int,input().split()))
B = B[::-1]
A = []
for i in range(N):
    for m,b in enumerate(B):
        if (N-m == b):
            A.append(b)
            B.pop(m)
            N -= 1
            break
if len(A) == n:
    for a in A[::-1]:
        print(a)
else:
    print(-1)

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

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
T=True
L=[]
while(T):
    if len(B)==0:
        break
    t=False
    for i in range(len(B)-1,-1,-1):
        if i+1==B[i]:
            L.append(B.pop(i))
            t=True
            break
    if not t:
        T=False
if T:
    for i in L[::-1]:
        print(i)
else:
    print(-1)

Solution (Python):
n = int(input())
B = list(map(int, input().split()))
ANS = [-1 for _ in range(n)]

def findlast(str):
    for i in range(len(str))[::-1]:
        if str[i] == i+1:
            return i
    else:
        return -1

ok = True
for i in range(n)[::-1]:
    j = findlast(B)
    if j > -1:
        ANS[i] = B[j]
        B = B[:j] + B[j+1:]
    else:
        ok = False
if ok:
    for i in ANS:
        print(i)
else:
    print(-1)

Solution (Python):
import copy
N = int(input())
N2 = copy.copy(N)
bs = list(map(int, input().split()))
ans = []
flag = True
while bs:
    if not flag:
        break
    else:
        for i in range(N):
            if bs[-(i+1)] == N-i:
                if i != 0:
                    bs = bs[:-(i+1)]+bs[-i:]
                else:
                    bs = bs[:-(i+1)]
                ans.append(N-i)
                N -= 1
                break
        if bs:
            if bs[0] != 1:
                flag = False

if flag:
    for j in range(1, N2+1):
        print(ans[-j])
else:
    print(-1)

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

ans = []  
 
def check(bs, pre):
  tmp = pre[:]
  if len(bs) == 0:
    ans.append(tmp)
    return
  cand = []
  for i, b in enumerate(bs):
    if i + 1 == b:
      cand.append(i)
  if len(cand) == 0:
    return
  i = cand[-1]
  check(bs[:i] + bs[i+1:], [i + 1] + tmp)

check(bs, [])

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

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
ans = []
t = 0
while len(b) > 0:
    f = 1
    for k in range(len(b),-1,-1):
        if b[k-1]==k:
            f = 0
            b.pop(k-1)
            ans.append(k)
            break
    if f:
        print(-1)
        exit(0)
print(*ans[::-1], sep = "\n")

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

seq = []
while B:
	for n in range(len(B) - 1, -1, -1):
		if (n + 1) == B[n]:
			seq += [B.pop(n)]
			break
	else:
		print(-1)
		break
else:
	for t in seq[::-1]:
		print(t)

Solution (Python):

N = int(input())
b_list = list(map(int, input().split()))
out_list = []

for i in range(N):
    ng_checker = 1
    for j in range(N - i):
        if b_list[(N - i) - (j + 1)] == (N - i) - j:
            out_list.insert(0, b_list.pop((N - i) - (j + 1)))
            ng_checker = 0
            break
    if ng_checker == 1:
        print(-1)
        break
if ng_checker != 1:
    for i in out_list:
        print(i)

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


while b:
    flag=0
    buf=0
    for j in range(len(b)):
        if(b[j]==j+1):
            if(buf<j):
                buf=j
            flag=1         
    if (flag==0):
        print(-1)
        break
    s.append(b.pop(buf))
    
if (flag==1):
    for i in range(n):
        print(s[n-i-1],end='\n')

Solution (Python):
import copy

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


def dfs(arr, indexes):
    if len(arr) == 0:
        return indexes

    for idx, elm in enumerate(arr):
        if idx+1 < elm:
            return False

    for i in reversed(range(len(arr))):
        if i+1 == arr[i]:
            _indexes = copy.copy(indexes)
            _indexes.append(i)
            res = dfs(arr[:i] + arr[i+1:], _indexes)
            if res:
                return res
    return False


res = dfs(B, [])
if res:
    for i in reversed(res):
        print(i+1)
else:
    print(-1)

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


n = int(input())
s = list(input().split(" "))
ans =deque()
while len(s)>0:
    bool = 1
    for i in range(len(s))[::-1]:
        if int(s[i]) == i+1:
            si = s.pop(i)
            ans.append(si)
            bool = 0
            break
    if bool:
        print(-1)
        exit()
while ans:
    print(ans.pop())

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

Solution (Python):
import sys
n = int(input())
k =[]
x = list(map(int, input().split()))
x = x[::-1]
for i in range(n):
    for j,p in enumerate(x):
        if p == n-j:
            k.append(p)
            x.pop(j)
            n-=1

            break
    else:
        print(-1)
        sys.exit()
for i in k[::-1]:
    print(i)

Solution (Python):
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    cand = []
    if(B == []):
        return True
    if(max(B)>len(B)):
        return False
    for i in range(1,len(B)+1):
        if(i in B):
            if(B.index(i)+1<i):
                return False
            elif(B.index(i)+1==i):
                cand.append(i)

    for i in cand:
        if(dfs(B[:i-1]+B[i:],li)):
            li.append(i)
            return True

    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)

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

isExist = False
olist = []
while (True):
  if len(blist) == 0:
    isExist = True
    break
    
  changed = False
  for i in reversed(range(len(blist))):
    if blist[i] == i+1:
      olist.insert(0,blist.pop(i))
      changed = True
      break
      
  if not changed:
    break
    
if isExist:
  for index in olist:
    print(index)
else:
  print(-1)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
 
ops = []
while len(a):
  if not any(a[i] == i + 1 for i in range(len(a))):
    print(-1)
    exit()
  for i in reversed(range(len(a))):
    if a[i] == i + 1:
      ops.append(a[i])
      a.pop(i)
      break
 
for op in reversed(ops):
  print(op)

Solution (Python):

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


ans = []


def cond(_b):
	hist = [0]*(len(_b)+1)
	
	for i in range(0, len(_b)):
		if _b[i] > i + 1:
			return False
	
	return True



def dfs(_b, _ans):
	
	if not cond(_b):
		return False
	
	for i in range(0, len(_b)):
		
		if i + 1 == _b[i]:
			_b2 = _b[:]
			_ans2 = _ans[:]
			_ans2.append(_b2[i])
			_b2.pop(i)
			
			if dfs(_b2, _ans2) == True:
				return True
	
	if len(_b) == 0:
		
		_ans.reverse()
		for i in _ans:
			print(i)
		return True
		
	else:
		return False


if not dfs(b,[]):
	print(-1)

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

remove_list = []
while b != []:
    
    can_remove = False
    remove_index = 0
    for i, e in reversed(list(enumerate(b))):
        
        if i + 1 == e:
            remove_list.append(e)
            can_remove = True
            remove_index = i
            break
        
    if not can_remove:
        break
    else:
        del b[remove_index]

if b != []:
    print(-1)
else:
    for e in reversed(remove_list):
        print(e)

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

Solution (Python):
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
while True:
    b = len(ar)
    s = "N"
    for i in range(b-1,-1,-1):
        if ar[i] == i+1:
            s = "Y"
            br.append(ar[i])
            del ar[i]
            break
    if s == "N":
        print(-1)
        exit()
    if len(ar) == 0:
        break
for i in range(a-1,-1,-1):
    print(br[i])

Solution (Python):
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:
            ans.append(j)
            b.pop(j-1)
            break
    else:
        print(-1)
        break
else:
    for i in ans[::-1]:
        print(i)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n)]

def f(a,b,n):
     for i in range(n):
          flag = True
          for j in range(n-i-1,-1,-1):
               if a[j] == j+1:
                    a = a[:j]+a[j+1:]
                    b[n-i-1] = j+1
                    flag = False
                    break
          if flag:
               print("-1")
               return
     for i in range(n):
          print(b[i])
     return
     
f(a,b,n)

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

ans = []
while(b):
    position = -1
    for i,x in enumerate(b):
        order = i + 1
        if order == x:
            position = i
    if position == -1:
        print(-1)
        exit()
    ans.append(b.pop(position))

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

Solution (Python):

from sys import stdin




def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
b_list = _li()

ans = []
for i in range(N, 0, -1):
    cand = []
    for j in range(i):
        if b_list[j] == (j+1):
            cand.append(j)
    if len(cand) == 0:
        print(-1)
        exit()
    else:
        a = b_list.pop(cand[-1])
        ans.append(a)

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

Solution (Python):
n = int(input())
b = [int(i) for i in input().split()] 
a = []
for i in range(n):
    for j in range(len(b), 0, -1):
        if b[j-1] == j:
            del b[j-1]
            a.append(str(j))
            break
if len(a) != n:
    print(-1)
else:
    print("\n".join(list(reversed(a))))

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

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print(ans[len(ans) - i - 1])
        exit()
    for i in range(len(a) - 1, -1, -1):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])
            break


f(b, [])
print(-1)

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

noanswer=0
while len(b)>0:
  for i in range(len(b)-1,-1,-1):
    if b[i]==i+1:
      a.append(b.pop(i))
      break
    if i==0:
      noanswer=1
  if noanswer==1:
    print(-1)
    break

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

Solution (Python):
n=int(input())
B=[int(i) for i in input().split()]
Ans=[]
for i in range(n-1):
  N=[j+1 for j in range(n-i)]
  b=-1
  for k in range(n-i):
    if B[k]==N[k]:
      b=k
  if b==-1:
    break
  else:
    Ans.append(b+1)
    B=B[:b]+B[b+1:]
if B!=[1]:
  print(-1)
else:
  print(*([1]+Ans[::-1]),sep="\n")

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

for i in range(n):
    if ans == -1:
        break
    
    for j in range(n):
        if b[j] == n-j:
            ans = b.pop(j)
            ans_set[n-1] = ans
            n -= 1
            break
            
        elif b[j] > n-j:
            ans = -1
            print(ans)
            break

        if n == 0:
            break

if ans != -1:
    for k in ans_set:
        print(k)

Solution (Python):
import sys
if __name__ == "__main__":
    N = int(input())
    A = [0] * N
    B = list(map(int,input().split()))
    for n in range(N-1,-1,-1):
        i = n
        while(1):
            if B[i] == i+1:
                A[n] = B.pop(i)
                break
            i -= 1
            if i < 0:
                print(-1)
                sys.exit()
    for a in A:
        print(a)

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

for j in range(N):
    for i in range(len(b)):
        if b[i] == i+1:
            l.append(i)
    if len(l) == 0:
        k += 1
        break
    ans.append(b[max(l)])
    del b[max(l)]
    l = []
if k > 0:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

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

if len(b) > 0:
    print(-1)
else:
    for x in reversed(ans):
        print(x)

Solution (Python):
from sys import stdin
import numpy as np

import fractions as math





N = int(stdin.readline().rstrip().split()[0])
B = [int(x) for x in stdin.readline().rstrip().split()]

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

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

Solution (Python):

n = int(input())
bs_input = tuple(int(i) for i in input().split())




def valid(list_):
    return all(i >= l - 1 for i, l in enumerate(list_))


def can_remove(list_, i):
    
    if list_[i - 1] != i:
        return False

    
    if not valid(list_[:(i - 1)] + list_[i:]):
        return False

    return True


def remove(list_, i):
    return list_[:(i - 1)] + list_[i:]

reconstruct = []

bs = list(bs_input)
for i in range(n):
    if not valid(bs):
        reconstruct = []
        break
    for j in range(n - i):
        if can_remove(bs, bs[j]):
            reconstruct.insert(0, bs[j])
            bs = remove(bs, bs[j])
            break


if reconstruct == [] or len(reconstruct) != n:
    print(-1)
else:
    print('\n'.join(str(i) for i in reconstruct))

Solution (Python):
import sys

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

ans = []

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

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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().split()]

impossible = False
A = []
match = -1

for i in range(N):
    for j in range(len(B)):
        if B[j] == j + 1:
            match = j
    if match == -1:
        impossible = True
        break
    else:
        A.append(B.pop(match))
        match = -1

if impossible:
    print(-1)
else:
    for i in range(N):
        print(A.pop(-1))

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

ops = []
for i in range(n):
  for j, b in enumerate(reversed(bs)):
    if n - i - j == b:
      bs.pop(n-i-j-1)
      ops.append(n-i-j)
      break
  if len(bs) == n-i:
    break
if len(ops) == n:
  print(*reversed(ops), sep="\n")
else:
  print(-1)

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

if b[0] > 1:
    print(-1)

else:
    a = []

    while len(b)>0:
        n = len(b)
        br = True
        for i in range(n):
            if  n-i == b[n-1-i]:
                a.append(n-i)
                b.remove(n-i)
                br = False
                break
        if br:
            break

    if br:
        print(-1)
    else:
        for _ in range(len(a)):
            print(a.pop())

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

for i in range(n-1, -1, -1):
  for j in range(i, -1, -1):
    if b[j] == (j + 1):
      r.append(b[j])
      del b[j]
      break
  else:
    flag = False
    break

if flag:
  r.reverse()
  for i in r:
    print(i)
else:
  print('-1')

Solution (Python):

def main():
    num = int(input())
    data = list(map(int, input().split()))
    max_num = max(data)

    ans_data = []

    while data != []:
        for i in range(max_num)[::-1]:
            if i >= len(data):
                continue
            if data[i] == i + 1:
                ans_data.append(i + 1)
                data.pop(i)
                break
        else:
            break

    if len(data) == 0:
        for ele in ans_data[::-1]:
            print(ele)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

ans = []
for _ in range(n):
    for i, e in enumerate(reversed(b)):
        if e == len(b) - i:
            ans.append(b.pop(len(b) - i - 1))
            break
        else:
            continue

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

Solution (Python):
import sys

def main():
  if 'get_ipython' not in globals():  
    
    N = int(input())
    b = [int(i) for i in input().split()] 
  else:
    
    
    b = [1,1,1,2,2,1,2,3,2]
    N = len(b)

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

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

Solution (Python):
input = raw_input

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

done = []
for i in range(N):
    idx = -1
    for j in range(len(b)-1,-1,-1):
        if b[j] == j+1:
            idx = j
            break
    if idx == -1:
        print(-1)
        exit()
    done.append(b.pop(j))

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

Solution (Python):
N=int(input())
_b=list(map(int,input().split()))
ix=[]
while len(_b)!=0:
    pp=[i for i in range(len(_b)) if _b[i]==i+1][-1:]
    if len(pp)==0:
        print(-1)
        exit(0)
    p=pp[0]
    _b.pop(p)
    ix.append(p)
ix.reverse()
for i in ix:
    print(i+1)

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

def solve(b):
    if len(b) == 0:
        return []
    if any(i+1 < b[i] for i in range(len(b))):
        return None
    erasable = [i+1 for i in range(len(b)) if i+1 == b[i]]
    if len(erasable) == 0:
        return None
    i = erasable[-1]  
    a = solve(b[:i-1] + b[i:])
    if a != None:
        return [i] + a
    return None

a = solve(b)
if a == None:
    print(-1)
else:
    a.reverse()
    print('\n'.join(map(str, a)))

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

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

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

if len(B) != 0:
    print("-1")
else:
    print("\n".join(map(str,o[::-1])))

Solution (Python):
from collections import deque

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

l = []

a = deque(l)

while b:
    memo = []
    for i in range(len(b)):
        if b[i]-1 == i:
            memo.append(i)
    if memo ==[]:
        print(-1)
        exit()
    a.appendleft(memo[-1]+1)
    b = b[:memo[-1]] + b[memo[-1]+1:]

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

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

ans = []

for i in range(n):
    for j in range(n-i, 0, -1):
        if bs[j-1] == j:
            ans.append(j)
            del bs[j-1]
            break
if len(ans) == n:
    ans = ans[::-1]
    for a in ans:
        print(a)
else:
    print(-1)

Solution (Python):



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

    result = []
    for j in range(n):
        for i in range(n - j, 0, -1):
            if b[i-1] == i:
                result.append(i)
                del b[i-1]
                break
    if len(result) == n:
        result.reverse()
        for v in result:
            print(v)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

if(sum(1 for i in range(1, N+1) if b[i-1] > i)):
    ret = [-1]

else:
    M = max(b)
    ret = []
    while len(b):
        for j in range(min(M, len(b)), 0, -1):

            if j == b[j-1]:
                ret += [b[j-1]]
                del b[j-1]
                break

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

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

ans_list = []
bit = B[:]

for _ in range(100):
    for i in range(N)[::-1]:
        if bit[i] == 1:
            ans_list.append(B[i])
            for j in range(i,N):
                if bit[j] > 0:
                    bit[j] -= 1
            break

if set(bit) == {0}:
    pass
else:
    ans_list = [-1]

for ans in ans_list:
    print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

m = max(B)
f = False
ans = []
for _ in reversed(range(N)):
    for j in reversed(range(len(B))):
        if B[j] == j+1:
            ans.append(B.pop(j))
            f = True
            break
    if f:
        f = False
        continue
    else:
        print(-1)
        exit()
print("\n".join(map(str, reversed(ans))))

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i])

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

flag = True
ans = list()
while flag and len(B):
    for i in range(len(B) - 1, -1, -1):
        if B[i] == i + 1:
            del B[i]
            ans.append(i + 1)
            break
    else:
        flag = False
        break

if not flag:
    print(-1)
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i])

Solution (Python):
n = int(input())
a = [int(i) - 1 for i in input().split()]
ans = []
while len(a):
    key = -1
    for i, j in enumerate(a):
        if i == j:
            key = i
    if key == -1:
        break
    else:
        a.remove(key)
        ans.append(key + 1)

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

Solution (Python):
import copy
N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
  n = len(b)
  f = False
  for i in range(n):
    if b[n-i-1] == n-i:
      ans.append(b.pop(n-i-1))
      f = True
      break
  if not f:
    print('-1')
    break
  if len(ans) == N:
    ans.reverse()
    for v in ans:
      print(v)
    break

Solution (Python):
def limited_insertion(N: int, B: list) -> list:
    op = []
    for i in range(N-1, -1, -1):
        for j in range(i, -1, -1):
            b = B[j]
            if i+1 < b:
                
                return []
            if j+1 == b:
                
                B = B[:j] + B[j+1:]
                op.append(b)
                break
        else:
            
            return []
    return reversed(op)


if __name__ == "__main__":
    N = int(input())
    B = [int(s) for s in input().split()]

    ans = limited_insertion(N, B)
    if ans:
        for a in ans:
            print(a)
    else:
        print(-1)

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

def check(b):
    for i in range(len(b))[::-1]:
        if i+1 == b[i]:
            return i
    return -1

ans = []
for i in range(n):
    ind = check(b)
    if ind >= 0:
        ans.append(ind+1)
        b = b[:ind] + b[ind+1:]
    else:
        print(-1)
        exit()
for i in ans[::-1]:
    print(i)

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

Solution (Python):
def a(arg):
    for i in range(len(arg)):
        if (i + 1 == int(arg[i])):
            a = i
        if (i + 1 < int(arg[i])):
            return -1

    return int(arg.pop(a))

_ = input()
arg = input().split()

l = []
while (len(arg) > 0):
    b =  a(arg)
    if (b == -1):
        print(-1)
        break
    l.append(b)

if (len(arg) == 0):
    l.reverse()
    for i in l:
        print(i)

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

res = []
while True:
    if len(b) == 0:
        break
    flg = True

    for i in range(len(b)):
        k = len(b)-i-1
        if k == b[k]-1:
            a = b.pop(k)
            res.append(a)
            flg = False
            break

    if flg:
        print(-1)
        exit()

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

Solution (Python):
n=int(input())
a=list(map(int,input().split(" ")))
c=[]
for k in range(n):
  b=[j for j,i in enumerate(a) if i==j+1]
  if b==[]:
    print(-1)
    k=n
    break
  else:
    c.insert(0,a.pop(b[-1]))
if k==n-1:
  for i in c:
    print(i)

Solution (Python):
N = int(input())
b = [int(i) for i in input().split(' ')]
seq = []
while True:
  if len(b) == 0:
    print('\n'.join(seq[::-1]))
    break
  i = -1
  for j in range(len(b)):
    if b[j] == j + 1:
      i = j
  if i == -1:
    print('-1')
    break
  seq.append(str(i + 1))
  b = b[:i] + b[i+1:]

Solution (Python):
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    if not ok:
        break
    out.append(bs[change_i])
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)

Solution (Python):
import sys

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

ans = list()

for ii in reversed(range(n)):
    for jj in reversed(range(ii+1)):
        if b[jj] == jj + 1:
            ans.append(b.pop(jj))
            
            break

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

for ii in reversed(range(n)):
    print(ans[ii])

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

while len(b) > 0 and n-1 >= 0:
    if b[n-1] == n:
        b.pop(n-1)
        a.insert(0, n)
        n = len(b)
        continue
    n -= 1

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

Solution (Python):
listOutput = list()
listInput = list()
nNum = int(input())
strInput = input()
listInput = strInput.split()



while (len(listInput) > 0) and ((nNum - 1) >= 0):
    if int(listInput[nNum - 1]) == nNum:
        listOutput.insert(0, nNum)
        del listInput[nNum - 1]
        nNum = len(listInput)
        continue
    
    nNum -= 1


if len(listInput) == 0:
    while(len(listOutput) > 0):
        print(listOutput.pop(0))
else:
    print('-1')

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

ans = []
while len(b) > 0:
  for i in range(len(b)-1, -1, -1):
    if i+1 == b[i]:
      ans.append(b.pop(i))
      poped = True
      break
  else:
    print(-1)
    sys.exit()

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