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):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [0 for i in range(N)]

  for i in range(N - 1, -1, -1):
    v = -1
    for j in range(i + 1):
      if B[j] == j + 1: v = j
    if v == -1: return [ -1 ]
    ans[i] = v + 1
    B.pop(v)
  return ans

print(*solve(), sep='\n')

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

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


b = []

for i in range(N, 0, -1):
  for j in range(i, 0, -1):
    if a[j-1] == j:
      b.append(j)
      del a[j-1]
      break
    else:
      pass
  else:
    b = [-1]
    break


b.reverse()

for i in b:
  print(i)

Solution (Python):
from collections import Counter
import sys
def zur(z, xx):
    c = 0
    k = 0
    i = 0
    while True:
        i += 1
        if i in xx:
            c += 1
        else:
            k += 1
        if k == z:
            return z + c

def xxxxx(z, xx):
    if z not in xx:
        return z
    while True:
        z -= 1
        if z == 0:
            print(-1)
            sys.exit()
        if z not in xx:
            return z

def mkxp(xs):
    xp = {}
    for i, x in enumerate(xs):
        i = i+1
        if x > i:
            print(-1)
            sys.exit()
        if x not in xp:
            xp[x] = list()
        xp[x].append(i)
    return xp

i = input()
xs = [int(x) for x in input().strip().split(" ")]
xp = mkxp(xs)


x = max(xs)
xo = []
xx = set()

while True:
    last = len(xs)
    if x == 0:
        break
    nxx = set()
    if x in xp:
        for i in xp[x]:
            xxx = zur(x + last - i, xx)
            xo.append((xxx, x))
            nxx.add(xxx)
        last -= len(xp[x])
    xx = nxx | xx
    xs = [int(i) for i in xs if i != x]
    xp = mkxp(xs)
    x -= 1

for i, x in sorted(xo, key=lambda x:x[0]):
    print(x)

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

stack = []
for i in range(N):
    tmp = []
    flag = True
    for j in range(len(B)):
        if B[j]==j+1:
            tmp.append(j)
    if tmp:
        tmp.sort(reverse=True)
        ans = tmp[0]
        B = B[:ans] + B[ans+1:]
        stack.append(ans+1)
    else:
        flag = False
        break
if flag:
    stack = stack[::-1]
    for i in stack:
        print(i)
else:
    print(-1)

Solution (Python):
import numpy as np

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

A=np.array(A)

global res

res=[0]*N

def test(A):
    if A.shape[0]==1:
        if A[0]==1:
            res[0]=1
            return 1
        else:
            return 0
    else:
        B=np.arange(len(A))+1
        C=max((A==B)*B)
        if C==0:
            return 0
        else:
            res[len(A)-1]=C
            return test(np.delete(A,C-1,0))

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

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    
    ans = []
    while B:
        for i in range(len(B)-1, -1, -1):
            if i+1 == B[i]:
                B.pop(i)
                ans.append(i+1)
                break
        else:
            break
    
    if B:
        return [-1]
    else:
        return reversed(ans)


def main():
    N = read_int()
    B = read_int_n()
    for r in slv(N, B):
        print(r)




if __name__ == '__main__':
    main()

Solution (Python):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ 0 ] * N

  for i in range(N - 1, -1, -1):
    v = -1
    for j in range(i + 1):
      if B[j] == j + 1: v = max(v, j + 1)
    if v == -1: return '-1'
    ans[i] = v
    B.pop(v - 1)
  return '\n'.join(map(str, ans))

print(solve())

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

flag=1
while flag:
    index=len(listB)-1
    while index > -1:
        if listB[index] == index+1:
            listA.append(listB[index])
            del listB[index]
            break
        index-=1
    if index == -1:
        print(-1)
        flag=0
        break
    if listB == []:
        break
listA.reverse()
if flag:
    for ans in listA:
        print(ans)

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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
A = []
while B:
    flag = True
    for i in reversed(range(len(B))):
        if B[i] == i + 1:
            flag = False
            A.append(B[i])
            B.pop(i)
            break
    if flag:
        print(-1)
        break
        
if flag == False:
    for a in reversed(A):
        print(a)

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

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

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

Solution (Python):
import numpy as np

def main():
	N=int(input())
	b=inputList()
	
	result=[]

	for i in range(N):
		key=-1
		for j in range(N-i):
			if(b[j]==j+1):
				key=j
		if(key==-1):
			print(-1)
			return
		result.append(key+1)
		del b[key]

	result=result[::-1]
	for elem in result:
		print(elem)

def inputList():
	a=list(map(int,input().split()))
	return a

def multisort(li,index):
	return sorted(li,key=lambda x: x[index])

if(__name__=='__main__'):
	main()

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')

Solution (Python):
N=int(input())
b=list(map(int,input().split()))
sa=[i-b[i-1] for i in range(1,N+1)]
ans=[0 for i in range(N)]
for i in reversed(range(1,N+1)):
    cnt=0
    for j in range(1,N+1):
        if ans[-1*j]==0:
            if cnt!=sa[i-1]:
                cnt+=1
            else:
                ans[-1*j]=b[i-1]
                break
if all(k!=0 for k in ans):
    for i in ans:
        print(i)
else:
    print("-1")

Solution (Python):
n = int(input())
ar = list(map(int, input().split()))
ans = [0 for i in range(n)]
fond = True
for i in range(n-1,-1,-1):
    mx = -1
    for j in range(i+1):
        if ar[j] == j+1:
            mx = max(mx, j+1)
    if mx == -1:
        fond = False
        break
    else:
        ans[i] = mx
        for j in range(mx-1, i):
            ar[j] = ar[j+1]

if fond:
    for i in range(n):
        print(ans[i])
else:
    print(-1)

Solution (Python):
import sys
import time
import copy

N = int(input())
b = [int(b) for b in input().split()]
h = {}

t1 = time.time()

def f(b):
  t2 = time.time()
  if t2 - t1 > 1.5:
    print(-1)
    sys.exit()
  
  key = "".join([str(x) for x in b])
  if key in h:
    return copy.copy(h[key])
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return copy.copy(h[key])
  
  for i in range(len(b)):
    i = len(b) - 1 - i
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return copy.copy(h[key])
  
  h[key] = []
  return copy.copy(h[key])

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

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

a = [0] * N

num = N
for _ in range(N):
    d = 0
    num -= 1
    for i, c in enumerate(b):
        if c == i + 1:
            d = c
    if d == 0:
        a = [-1]
        break
    a[num] = d
    del b[d - 1]

for c in a:
    print(c)

Solution (Python):
def ExNo():
	print(-1)
	exit(0)

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

A = [0] + A
n1 = n+1



from collections import defaultdict
D = defaultdict(int)
for i in A[1:]:
	D[i] += 1



for i in range(1, n1):
	if A[i]>i: ExNo()







if D[1]==0 : ExNo()




iSum=0
for i in range(1, n1):
	
	iSum += D[i]
	if iSum<i: ExNo()




B = A[1:]
C = []

iCount=0
while iCount < n:
	
	for i in range(len(A)-1, 0, -1):
		
		if i==A[i]:
			
			C = [A[i]] + C
			del A[i]
			break
	else:
		if len(A)>0:
			ExNo()
	iCount += 1



for i in C:
	print(i)

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

can = True
for i in range(1, n +1):
  if b[i - 1] > i:
    can = False
    break

if can:
  result = []
  while(len(b)):
    for i in range(len(b), 0, -1):
      if i == b[i - 1]:
        result.insert(0, i)
        b.pop(i - 1)
        break
  for a in result:
    print(a)
else:
  print(-1)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = []
while(b != []):
    for i in range(len(b), 0, -1):
        if i not in b:
            continue
        if b[i - 1] == i:
            ans.append(i)
            del b[i - 1]
            break
    else:
        print(-1)
        exit()
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)
    break
else:
  ans = []
  while len(b) > 1:

    c = len(ans)
    f = b[0]
    for i in range(1, len(b))[::-1]:
      if b[i] == i + 1:

        ans.append(b.pop(i))
        break
    else:
      for i in range(1, len(b)):

        if f >= b[i]:
          ans.append(b.pop(i-1))
          break
        elif n - c == b[i]:
          ans.append(b.pop(i))
          break
        elif i == len(b) - 1:
          ans.append(b.pop(-1))
          break
        else:
          f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])

Solution (Python):
n,a,b,ans=int(input()),[],list(map(int,input().split())),0
for i in range(n):
  if i+1<b[i]:ans=-1
def num(list):
  x=list[:]
  maxp=x.index(max(x))
  if maxp==max(x)-1:return maxp
  else:return num(x[:maxp])
if ans==-1:print(-1)
else:
  while len(b)!=0:
    p=num(b)
    a.insert(0,b[p])
    del b[p]
for i in a:print(i)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)),reverse=True)
if 1 not in s_b:
  print(-1)
  exit()
ans=[]
for itr in range(n):
  for j in s_b:
    if len(b)>=j:
      if b[j-1]==j:
        b.pop(j-1)
        ans.append(j)
        break
    if j==1:
      print(-1)
      exit()
ans.reverse()
for i in range(n):
  print(ans[i])

Solution (Python):

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

a = []
for i in range(N):
	x = b[i]
	if x > (i+1):
		print(-1)
		exit()

	a.insert(x-1, x)
else:
	for x in a:
		print(x)

Solution (Python):
import numpy as np
inpl = lambda: list(map(int,input().split()))
N = int(input())
b = np.array(inpl(),dtype=np.int)

d = np.array(range(1,N+1),dtype=np.int) - b
if len(np.where(d < 0)[0]) > 0:
    print(-1)
    exit()

ans = np.empty(N,dtype=np.int)
for i in range(N):
    z = np.where(d == 0)[0]
    if len(z) == 0:
        print(-1)
        exit()
    else:
        k = z[-1]
        d[k] = -1
        for n in range(k+1,N):
            if d[n] > 0:
                d[n] -= 1
        ans[N-1-i] = b[k]

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

Solution (Python):



N = int(raw_input())

b = map(int, raw_input().split(' '))
if 1 not in b:
    print -1
    exit()
a = []

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


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


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

Solution (Python):
N = int(input().strip())
res = [int(b) for b in input().strip().split()]
flag = True
commands = []
for n in range(N):
    index = -1
    for i, c in enumerate(res):
        if(i + 1 == c):
            index = i
    if(index == -1):
        flag = False
        break
    commands.append(index)
    res.pop(index)

if(flag):
    for c in commands[::-1]:
        print(c+1)
else:
    print(-1)

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

b = []
for _b in list(map(int, input().split())):
    if _b > len(b) + 1:
        print('-1')
        exit()
    b.insert(_b - 1, str(_b))

print('\n'.join(b))

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

A = []
for i in range(1,N+1):
  if(B == []):
    break
  for b in B:
    if(1 <= b <= i):
      A.insert(b-1, b)
      B.remove(b)
    break

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

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

def f():
    bN_ = [a - (n + 1) for n, a in enumerate(bN)]
    bN_.reverse()
    
    bN.reverse()

    l = []
    while bN_:
        i_0 = [i for i, a in enumerate(bN_) if a == 0]
        if not i_0:
            return [-1]

        i = i_0[0]
        
        for j in range(i):
            bN_[j] += 1
        bN_.pop(i)
        a = bN.pop(i)
        
        l.append(a)
    return l
    
    
    
    
    
    
    
    
    
    

for i in list(reversed(f())):
    print(i)

Solution (Python):
import sys


fin = sys.stdin.readline

N = int(fin())
b_list = [int(elem) for elem in fin().split()]

if any(b > i + 1 for i, b in enumerate(b_list)):
    print(-1)
    exit(0)

procedure = []
for i in range(N):
    b = b_list[i]
    distance = i + 1 - b
    procedure.insert(i - distance, b)
print(*procedure, sep="\n")

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
c=[]
while len(b)>0:
    for i in range(len(b)-1,-1,-1):
        if 0<b[i][1]<=len(b) and 0<b[i][0]<=len(b) and b[i][0]==b[i][1]:
            c.append(b[i][1])
            d.pop(b[i][0]-1)
            b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
            break
    else:
        print(-1)
        break
else:
    for i in c[::-1]:
        print(i)

Solution (Python):
import sys

n = int(input())

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

def dfs(b_sub, ans):
  if len(b_sub) == 0:
    for a in ans[::-1]:
      print(a)
    sys.exit()
  takeable = []
  for i, item in enumerate(b_sub):
    if i+1 == item:
      takeable.append(i)
  if len(takeable) == 0:
    print(-1)
    sys.exit()
  for item in takeable[::-1]:
    tmp = b_sub
    taken = tmp.pop(item)
    ans.append(taken)
    dfs(tmp, ans)
  
print(dfs(b, []))

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
l=[]
while len(b)>0:
    for i in reversed(range(len(b))):
        flag=False
        if b[i]==i+1:
            l.append(i+1)
            del b[i]
            flag=True
            break
        else:
            pass
    if flag:
        continue
    else:
        break

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

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

ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')

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

Solution (Python):
N = int(input())
lst = list(map(int, input().split()))
ans = []
for i in range(N, 1, -1):
    for j in range(i, 0, -1):
        if(lst[j-1] == j):
            ans.insert(0, j)
            del lst[j-1]
            break

if(lst[0] == 1):
    ans.insert(0, 1)
if(len(ans) == N):
    for i in ans:
        print(i)
else:
    print("-1")

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)):
        if b[len(b)-j-1] == len(b) - j:
            a.append(len(b)-j)
            b.pop(len(b)-j-1)
            break
    if len(a) != i+1:
        print(-1)
        exit()


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

Solution (Python):



import sys

N = int(input())
x = list(map(int, input().rstrip().split(' ')))

output = [-1] * N
for i in range(N):
    generated_order = x[-i-1] - 1
    
    count_empty = 0
    flag_insert = False
    for j in range(N):
        if output[j] == -1 and count_empty == generated_order:
            output[j] = x[-i-1]
            flag_insert = True
            break
        elif output[j] == -1:
            count_empty += 1
    
    if flag_insert == False:
        print(-1)
        sys.exit()
        
for i in output:
    print(i)

Solution (Python):
import sys,itertools,copy
input = sys.stdin.readline
N=int(input().strip())
Bn=[int(x) for x in input().strip().split()]
ans=[]
v=[]
def isok(l,Bn=Bn):
    cnt=len(Bn)-1
    flag=True
    for i,n in enumerate(reversed(l)):
        while cnt>=0:
            if n == Bn[cnt]:
                cnt-=1
                break
            elif Bn[cnt] < len(l)-i:
                flag=False
                break
            else:
                cnt-=1
        else:
            flag=False
        if not flag:
            return False
    else:
        return True

for i in range(1,N+1):
    flag=False
    for ii in range(i,0,-1):
        test=copy.deepcopy(ans)
        test.insert(ii-1,ii)
        if isok(test):
            ans.insert(ii-1,ii)
            v.append(ii)
            flag=True
            break
    if not flag:
        v=[-1]
        break

for a in v:
    print(a)

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

ans = []
def solve(b,i):
    if i == 0:
        return True
    for j in range(i-1,-1,-1):
        if b[j] > j+1:
            return False
        if b[j] == j+1:
            p = b[:j] + b[j+1:]
            if solve(p,i-1):
                ans.append(j+1)
                return True

    return False

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

Solution (Python):

def chousa(b):
    poped = ["x"]*len(b)
    a = []
    isnt_sorted = len(b)
    for i,v in enumerate(b[::-1]):
        if len(b)-i < v:
            print(-1)
            return

    while isnt_sorted:
        for i,v in enumerate(b[::-1]):
            if v == 1 and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break
            elif len(a) >= v-1 and a[v-2][0] < len(b)-i and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break

        print(v)
def main():
    N = int(input())
    b = list(map(int,input().split()))
    chousa(b)
if __name__ == "__main__":
    main()

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

lis=[]
hantei = True
for _ in range(N):
    s = False
    for j,k in enumerate(b[::-1]):
        if len(b)-j== k:
            lis.append(b.pop(len(b)-j-1))
            s =True
            break
    if not s:
        hantei =False

lis = [str(i)for i in lis]

if hantei:
    for i in lis[::-1]:
        print(i)
else:
    print(-1)

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
bc = b[::-1]
a = []
while bc:
    for i in range(len(bc)):
        if bc[i] == len(bc)-i:
            a.append(bc[i])
            bc.pop(i)
            break
    else:
        print(-1)
        exit()
        
a = a[::-1]
for k in a:
    print(k)

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

for j in range(N):
  n = list(range(1,len(b)+1))
  n_tmp = [x - y for (x, y) in zip(n,b)]
  if min(n_tmp) >= 0:
    tmp = sorted(list(set(b)),reverse = True)
    for i in tmp:
      if i == b[i-1]:
        ans.insert(0,b[i-1])
        b.pop(i-1)
        break
  else:
    print('-1')
    break
else:
  for k in range(N):
    print(ans[k])

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

ans=[]


for i in range(N):
    
    j = False
    for k in range(len(b)-1,-1,-1):
        if b[k] == k + 1:
            j = True
            del b[k]
            ans.append(k+1)
            break
    if not j:
        print(-1)
        import sys
        sys.exit()

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

Solution (Python):
_ = input()
data = list(map(int, input().split()))

result = []
pos = min(len(data), max(data)) - 1

while pos >= 0:
    if data[pos] == pos + 1:
        x = data.pop(pos)
        
        result.append(x)
        if len(data) == 0:
            break
        pos = min(len(data), max(data)) - 1
    else:
        pos -= 1

if len(data) == 0:
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)

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

Solution (Python):



num = int(input())
b_list = list(map(int,input().split(" ")))
a_list = []

for i in range(num):
	n = num -i
	while n != 0:
		if b_list[n-1] == n:
			val = b_list.pop(n-1)
			a_list.insert(0,val)
			break
		else:
			n -= 1
if len(a_list) == num:
	for w in a_list:
		print(w)
else:
	print("-1")

Solution (Python):
def BFS(Bs,del_idx,result):
    if Bs==[1]:
        return result
    
    if del_idx!=None:
        del Bs[del_idx]


    for i,b in enumerate(Bs):
        if b>i+1:
            return None
        
    for i,b in enumerate(Bs):
        if i+1==b:
            DBs=Bs.copy()
            result.append(i+1)
            out=BFS(DBs,i,result)
            if out:
                return out
            else:
                del result[-1]

    return None


def Solve():
    output=[]
    N=int(input())
    Bs=[int(x) for x in input().split()]
    return BFS(Bs,None,[])
        

        
result=Solve()
if result:
    result.reverse()
    for r in result:
        print(r)
else:
    print(-1)

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

def search_num(num):
  try:
    nn = b.index(num)
    if nn + 1 == num:
      b.remove(num)
      return num
    else: return search_num(num-1)
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1

if n != len(b):
  print('-1')
else:
  for i in range(n, 0, -1):
    num = search_num(i+1)
    if num == -1:
      print('-1')
      break
    else:
      pool.append(str(num))
      if i == 1:
        for i in (reversed(pool)):
          print(i)
        break

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

valid = True
for i,a in enumerate(b,1):
    if i < a :
        valid = False
if valid :
    out = []
    while len(b) > 0:
        m = 0
        for i,a in enumerate(b,1):
            if i == a :
                m = i
        out.append(m)
        b.pop(m-1)
else:
    out = [-1]

for s in out[::-1]:
    print(s)

Solution (Python):
from collections import defaultdict as dd
N = int(input())
B = list(map(int, input().split()))

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

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

Solution (Python):
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []
check = 0

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        check = 1
        break

if check == 0:
    for i in range(N):     
        for j in range(N-i, 0, -1):
            
            if b_list[j-1] == j:
                answer_list.append(b_list[j-1])
                b_list.pop(j-1)
                
                break

    answer_list.reverse()


    for i in range(N):
        print(answer_list[i])

Solution (Python):
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

N = int(input())
max = 0
b = [int(x) for x in input().split()]
flag = [0 for x in range(N)]
for i in b:
    if i > max:
        max = i
submax = max
ans = []
while b != []:
    if ((submax-1) == my_index(b,submax)):
        ans.append(b.pop(submax-1))
        submax = max
    else :
        submax = submax-1
        if b[0] != 1:
            print(-1)
            exit()

for x in range(len(ans)):
    print(ans.pop(len(ans)-1))

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

ans = []

k = 0

while True:
    a = -1
    for k in range(len(b)):
        if b[k] == k+1:
            a = k

    if a == -1:
        ans = [-1]
        break
    else:
        b.pop(a)
        ans.append(a+1)
        if len(b) == 0:
            break
            
for a in ans[::-1]:
    print(a)

Solution (Python):
n = int(input())
b = list(int(x) for x in input().split())
revans = []
flg = True
cond = True

while(flg):
    removable = []
    for i, item in enumerate(b):
        if item == i+1:
            removable.append(i)

    if removable == []:
        flg = False
        cond = False
        break

    revans.append(b.pop(max(removable)))

    if b == []:
        flg = False

if cond:
    for item in reversed(revans):
        print(item)
else:
    print(-1)

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

Solution (Python):
import copy

n = int(input())

goal = list(map(int, input().split(" ")))

output = -1

procReverse = []

temp_goal = copy.copy(goal)

for _ in range(n):
  index = list(range(1,len(temp_goal)+1))
  for i in range(len(temp_goal)-1, -1, -1):
    
    if index[i] == temp_goal[i]:
      procReverse.append(temp_goal[i])
      temp_goal.pop(i)
      break
  else:
    print(-1)
    break
else:
  for i in range(n-1, -1, -1):
    print(procReverse[i])

Solution (Python):
import sys

n=int(input())
chara = list(map(int,input().split()))
chara.append(-1)
manu = [0]*n  

for i in range(n,0,-1):
    saga=0
    for j in range (i-1,-1,-1):
        if chara[j]==j+1:
            for k in range (j,n):
                chara[k]=chara[k+1]

            manu[i-1]=j+1
            saga=1
            break
    if saga==0:
        print(-1)
        sys.exit()


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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
TF = [False]*N
L = []
s = 0
lenstr = N-1
for i in range(N):
  cnt = 0
  tr = 0
  for j in range(N-1,-1,-1):
    if TF[j] == False:
      if lenstr-cnt-tr+i <= N-1:
        if B[lenstr-cnt-tr+i] == lenstr-cnt+1:
          TF[lenstr-cnt-tr+i] = True
          L.append(lenstr-cnt+1)
          lenstr -= 1
          break
        else:
          cnt += 1
      else:
          print(-1)
          exit()
    else:
      tr += 1
if len(L) == N:
  for i in range(N):
    print(L[N-i-1])
else:
  print(-1)

Solution (Python):
import sys

stdin = sys.stdin

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

n=ni()
b=na()
ans=[]
def solve(li):

	for i in range(1,len(li)+1):
		if li[len(li)-i]==len(li)-i+1:
			a=li.pop(len(li)-i)
			ans.append(a)
			return solve(li)

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

Solution (Python):



import sys
import math


n = int(input())


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

def add(list:[],i):
    list.insert()




ret=[]

for i in range(n):
    bb = b[i]
    
    if len(ret)+1 < bb:
        print('-1')
        quit()
    ret.insert(bb-1,bb)


ss = []
for i in ret:
    print(i)

Solution (Python):

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

res = []
for i in range(n):
    b = bl[i]
    if i<b-1:
        print(-1)
        exit()
    res.insert(b-1,b)

for r in res:
    print(r)