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()))
A = []
C = []
flag = True
j = 0
if max(B) > n:
  flag = False
if flag:
  while j < n:
    A = []
    for i in range(n-j):
      if B[i] == i+1:
        A.append(i+1)
    if A ==[]:
      flag = False
      break
    else:
      C.append(B[max(A)-1])
      del B[max(A)-1]
      j += 1
if flag:
  for k in range(1, n+1):
    print(C[-k])
else:
  print(-1)

Solution (Python):
def main():
    n = int(input())
    b = list(map(int, input().split()))
    ansl = []
    for i in range(n):
        f = False
        for j in range(n - i - 1, -1, -1):
            if b[j] == j+1:
                ansl.append(b.pop(j))

                f = True
                break

        if not f:
            print(-1)
            exit()
    for i in range(n - 1, -1, -1):
        print(ansl[i])


if __name__ == '__main__':
    main()

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

v = []
while b:
    x = -1
    for i in range(len(b)):
        if b[i] == i + 1:
            x = i

    if x == -1:
        print(-1)
        exit()

    v.append(b[x])
    del b[x]

for e in reversed(v):
    print(e)

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

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
    else:
        print(-1)
        exit()

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

Solution (Python):



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

    
    
    
    

    while b:
        index = -1
        candidate = -1

        
        for i, bi in enumerate(b, 1):
            if bi == i:
                index = i
                candidate = bi

        if index == -1:
            print(-1)
            exit()

        b.pop(index - 1)
        ans.append(candidate)

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


if __name__ == '__main__':
    main()

Solution (Python):
N, *B = map(int, open(0).read().split())

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

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

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
ans=[]
while B:
    tmp = -1
    for i,b in enumerate(B):
        if i+1 < b:
            print(-1)
            exit()
        elif i+1 == b:
            tmp = i
    ans.append(B[tmp])
    del B[tmp]
for a in reversed(ans):
    print(a)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=[]
  while True:
    if len(l)==0:
      break
    i=len(l)-1
    f=True
    for _ in range(len(l)):
      if l[i]==i+1:
        ans.append(l[i])
        l=l[:i]+l[i+1:]
        f=False
        break
      i-=1
    if f:
      print(-1)
      exit()
  ans.reverse()
  for x in ans:
    print(x)

main()

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

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


def check():
    ans=[]
    for i in range(n-1,-1, -1):
        for j in range(i, -1, -1):
            if j+1==b[j]:
                ans.append(b[j])
                del b[j]
                break
    if len(ans)==n:
        return ans
    else:
        return -1

ans=check()

if type(ans)==list:
    for i in ans[::-1]:
        print(i)
else:
    print(ans)

Solution (Python):


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

ans=[]
while b:
    lb=len(b)
    if lb==1:break
    idx=0
    for i in range(lb):
        if i==b[i]:
            idx=i
    if idx:
        ans.append(idx)
        b.remove(idx)
    else:
        print(-1)
        exit()

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

Solution (Python):
n=int(input())
b=[int(j) for j in input().split()]
ans=[]
while b:
    tmp=10**18
    for i in range(len(b))[::-1]:
        if b[i]==i+1:
            tmp=i
            break
    if tmp==10**18:
        print(-1)
        exit()
    else:
        ans.append(b[tmp])
        del b[tmp]

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

Solution (Python):
N, *B = map(int, open(0).read().split())
A = []
for b in B:
    if b - 1 > len(A):
        print(-1)
        quit()
    A.insert(b - 1, b)
print(*A, sep='\n')

Solution (Python):
N, *B = map(int, open(0).read().split())
A = []
for _ in range(N):
    for j in reversed(range(len(B))):
        if B[j] == j + 1:
            A.append(B.pop(j))
            break
    else:
        print(-1)
        quit()
print(*reversed(A), sep="\n")

Solution (Python):
N, *B = map(int, open(0).read().split())
A = []
for _ in range(N):
    for j in reversed(range(len(B))):
        if B[j] == j + 1:
            del B[j]
            A.append(j + 1)
            break
    else:
        print(-1)
        quit()
print(*reversed(A), sep="\n")

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

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(b.pop(j - 1))
            break
    else:
        break
    continue

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

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

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

    ans = []

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

    if B:
        print(-1)
    else:
        for a in reversed(ans):
            print(a)

sol()

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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

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

op = []
ok = True
while B and ok:
    for j in reversed(range(len(B))):
        if B[j] == j + 1:
            op.append(j + 1)
            B.pop(j)
            break
        if B[j] > j + 1:
            ok = False
            break

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

Solution (Python):
import sys


def option_index(blist):
  option_num = -1 
  option_i = None
  for i in range(len(blist)):
    if i + 1 == blist[i]:
      if option_num < blist[i]:
        option_i = i 
        option_num = blist[i]
  return option_i

N = int(sys.stdin.readline())
blist = list(map(int, sys.stdin.readline().split()))
ans = []
while len(blist)>0:
  result = option_index(blist)
  if result is not None:
    ans = [blist[result]] + ans
    blist.pop(result)
  else:
    print(-1)
    exit()

print("\n".join(map(str,ans)))

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

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

ans = []
while len(B) > 0:
    tmp = []
    for i,b in enumerate(B):
        if i+1 == b:
            tmp.append(b)
    if tmp == []:
        print(-1)
        exit()
    else:
        x = max(tmp)
        ans.append(x)
        B.remove(x)
ans.reverse()
for i in ans:
    print(i)

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

ans = list()
for k in reversed(range(N)):
    hit = False
    for l in reversed(range(1, k + 2)):
        if B[l - 1] == l:
            B = B[:l - 1] + B[l:]
            hit = True
            ans.append(l)
            break
    if not hit:
        print(-1)
        exit(0)

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

Solution (Python):
n,*B=map(int,open(0).read().split())
a=[]
while n:
	f=1
	for i,b in enumerate(B[::-1]):
		if b==n-i:
			n-=1
			a+=[B.pop(b-1)]
			f=0
			break
	if f:
		print(-1)
		exit()
print(*a[::-1],sep="\n")

Solution (Python):

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

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

l = l[::-1]

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

Solution (Python):
n = int(input())
s = list(input().split())
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)




if len(s) == 0:
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")

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


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


check_lst = [False] * N 

ans_lst = [] 


index = N - 1
while len(ans_lst) != N: 
    if check_lst[index] == False and b[index] == check_lst[:index].count(True) + 1: 
        ans_lst.append(b[index])
        check_lst[index] = True
        index = N - 1
    else:
        index -= 1

for i in ans_lst:
    print (i)

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


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


check_lst = [False] * N 

ans_lst = [] 
index = N - 1
while len(ans_lst) != N:
    if check_lst[index] == False and b[index] <= check_lst[:index].count(True) + 1:
        ans_lst.append(b[index])
        check_lst[index] = True
        index = N - 1
    else:
        index -= 1

for i in ans_lst:
    print (i)

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

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

def F(arr):
    
    L = len(arr)
    x = None
    for i,y in enumerate(arr[::-1]):
        if L - i == y:
            x = y
            break
    if x is None:
        return None,None
    return x, arr[:x-1] + arr[x:]

answer = []
while B:
    x, B = F(B)
    if x is None:
        answer = [-1]
        break
    answer.append(x)
answer = answer[::-1]

print('\n'.join(map(str,answer)))

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
tmp = b[:]
ans = []
i = N-1
while i >= 0:
    if tmp[i] == 1:
        tmp[i] = float('inf')
        ans.append(b[i])
        while i < N:
            tmp[i] -= 1
            i += 1
    i -= 1
if len(ans) == N:
    for i in ans:
        print(i)
else:
    print(-1)

Solution (Python):

def main():
    
    n = int(input())
    B = list(map(int, input().rstrip().split()))
    ans = []
    while len(B) > 0:
        for i in range(len(B) - 1, -1, -1):
            if B[i] == i + 1:
                ans += [B.pop(i)]
                break
        else:  
            print(-1)
            return
    print(*ans[::-1], sep="\n")


if __name__ == "__main__":
    main()

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

while bn:
    for i in range(len(bn))[::-1]:
        if i+1 == bn[i]:
            ans.append(bn[i])
            del bn[i]
            break
    else:
        break
if bn:
    print(-1)
else:
    [print(i) for i in ans[::-1]]

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

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

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

ans = []

while bn:
  lst = []
  for i in range(len(bn)):
    if i+1 == bn[i]:
      lst.append(i)
  if not lst:
    print(-1)
    exit(0)
  ans.append(bn.pop(lst[-1]))
[print(i) for i in ans[::-1]]

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

ans = []

while len(bn)>0:
  lst = []
  for i in range(len(bn)):
    if i+1 == bn[i]:
      lst.append(i)
  if len(lst) == 0:
    print(-1)
    exit(0)
  ans.append(bn.pop(lst[-1]))
for i in ans[::-1]:
  print(i)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = []
flg = 0
for i in range(N) :
    for j in range(len(A)-1,-1,-1) :
        k = j+1
        if k == A[j] :
            ans.append(k)
            A = A[:j]+A[j+1:]
            break
    else :
        print(-1)
        flg = 1
        break
if not flg :
    print(*ans[::-1],sep="\n")

Solution (Python):



import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

ans = []
n = int(input())
b = list(map(int,input().split()))
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)
        quit()
ans = ans[::-1]
for i in range(n):
    print(ans[i])

Solution (Python):

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

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()
    b = LI()
    ans = []
    for j in range(n):
        for i in range(len(b))[::-1]:
            if b[i] == i+1:
                x = b.pop(i)
                ans.append(x)
                break
    if b:
        print(-1)
    else:
        print(*ans[::-1],sep = "\n")
    return


def B():
    n = I()

    return


def C():
    n = I()

    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return


if __name__ == "__main__":
    A()

Solution (Python):

N = int(input())
*B, = map(int,input().split())
ans = []
while B:
    a = max([0] + [j for i,j in enumerate(B,1) if i==j])
    if a==0:break
    B.pop(a-1)
    ans.append(a)
if B:print(-1)
else:print(*ans[::-1],sep="\n")

Solution (Python):
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)

"""

def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
a = iprow()
ans = []
for i in range(n):
    for p in range(len(a)-1,-1,-1):
        if p+1 == a[p]:
            ans.insert(0,p+1)
            a.pop(p)
            break
if len(a):
    print(-1)
else:
    for i in ans:
        print(i)

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
b = list(li())

num_ofst = [[bi, (i+1) - bi] for i, bi in enumerate(b)]
ans = []

ok = True
while ok and num_ofst:
    cur = -1
    cur_idx = -1
    for i in range(len(num_ofst)-1, -1, -1):
        if num_ofst[i][1] == 0:
            cur = num_ofst[i][0]
            cur_idx = i
            break

        else:
            num_ofst[i][1] -= 1

    if cur != -1:
        num_ofst = num_ofst[:i] + num_ofst[i+1:]
        ans.append(cur)
    else:
        ok = False

if ok:
    print("\n".join(map(str, ans[::-1])))
else:
    print(-1)

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

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

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

Solution (Python):
N=int(input())
b=list(map(int,input().split()))
ans=[]
for k in range(N):
    for i in range(len(b)):
        if b[len(b)-1-i]==len(b)-i:
            x=b.pop(len(b)-1-i)
            ans.insert(0,x)
            break
if len(b)==0:
    for p in range(N):
        print(ans[p])
else:
    print(-1)

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    b = [int(i) for i in input().split()]
    l = []
    b_len = len(b)

    for _ in range(b_len):
        for i in range(len(b)-1, -1, -1):
            if b[i] == i+1:
                l.append(b.pop(i))
                break
        else:
            print(-1)
            sys.exit()

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


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin, exit
from collections import deque

N = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]
ans = deque([])

while N > 0:
    index = N - 1
    while index >= 0:
        if b[index] == index + 1:
            ans.appendleft(b[index])
            b1 = b[:index]
            b2 = b[index + 1:]
            b = b1 + b2
            N -= 1
            break
        index -= 1
        if index == -1:
            print(-1)
            exit()

print(*ans)

Solution (Python):
import numpy as np
import sys

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

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

for i in ans:
    print(i)

Solution (Python):
import sys
from collections import deque, defaultdict
import copy
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


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

tejun = []
for iteration in range(N):
    judge = 0
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            judge = 1
            tejun.append(copy.deepcopy(b[i]))
            del b[i]
            break
    if judge == 0:
        break

if judge == 0:
    print(-1)
else:
    for i in range(len(tejun)-1, -1, -1):
        print(tejun[i])

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

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

if impossible:
    print("-1")
else:
    pass
    ans = []
    while b:
        
        for i in reversed(range(len(b))):
            if b[i] == i+1:
                ans.append(b.pop(i))
                break
    for i in reversed(range(n)):
        print(ans[i])

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


while True:
    lenX=len(X)
    for i in range(lenX):
        if X[lenX-i-1] == lenX-i:
            del X[lenX-i-1]
            ans.append(lenX-i)
            break
    else:
        break

ans.reverse()

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

Solution (Python):
import numpy as np

def cal(output_lst, b_lst):
    for i in range(N):
        t = -1
        for j in range(N-i):
            if b_lst[j] == j+1:
                t = j
        if t == -1:
            return False
        output_lst.append(b_lst.pop(t))
    return True


N = int(input())

output_lst = []


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

judge = cal(output_lst, b_lst)
output_lst.reverse()

if judge:
    for low in output_lst:
        print(low)
else:
    print(-1)
            

print()

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

ans = []
while not b == []:
  lenb = len(b)
  for i, v in enumerate(reversed(b)):

    if (lenb - i) == v:
      del b[lenb - i - 1]
      ans.append(lenb - i)
      break
  else:
    print(-1)
    exit()

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

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

res = []
for _ in range(N):
    flag = False
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            res.append(b.pop(i))
            flag = True
            break
    if flag == False:
        print(-1)
        exit()

res.reverse()
for i in range(N):
    print(res[i])

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

b_list = [0] + b_list

result = []
def func():
    global b_list
    global result

    for i in range(len(b_list)-1,-1,-1):
        if i==0:

            b_list = []
            break
        if b_list[i] == i:

            result.append(i)
            del b_list[i]
            break

    if len(b_list) > 1:
        func()

func()

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

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

ans = []
while b:
    
    next = -1
    for i, n in enumerate(b):
        if i + 1 == n:
            next = i
    if next == -1:
        ans = []
        break
    else:
        ans.append(b.pop(next))

if ans:
    ans = ans[::-1]
    for s in ans:
        print(s)
else:
    print(-1)

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

ans = []
while b:
    
    next = -1
    for i, n in enumerate(b):
        if i + 1 == n:
            next = i
    if next == -1:
        ans = []
        break
    else:
        ans.append(b.pop(next))

if ans:
    ans = ans[::-1]
    for s in ans:
        print(s)
else:
    print(-1)

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

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

Solution (Python):
N = int(input())
*B, = map(int, input().split())
now = max(B)
ops = []
while N > 0:
    temp = (-1, -1)
    for i, b in enumerate(B):
        if b <= N and b == i + 1:
            temp = max(temp, (b, i))
    if temp != (-1, -1):
        _, i = temp
        ops.append(B.pop(i))
    N -= 1
if B: print(-1)
else: print(*list(reversed(ops)), sep='\n')

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

answer_list = []
for i in range(N-1, -1, -1):
  answer = False
  for index, j in list(reversed(list(enumerate(b)))):
    if index == j-1:
      answer = True
      answer_list.append(j)
      b.pop(index)
      break
  if not answer:
      print(-1)
      exit()

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

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
b = [x for x in reversed(b)]
ans = []
for _ in range(N):
    for i, bb in enumerate(b):
        
        if (len(b) - i) == bb:
            b.pop(i)
            ans.insert(0, bb)
            break
        elif (len(b) - i) < bb:
            print(-1)
            exit()
for a in ans:
    print(a)

Solution (Python):
N = int(input())
B = [int(i) for i in input().split()]
S = []
i = 0
while i < N:
  for j in range(len(B))[::-1]:
    if B[j] == j+1:
      S.append(j+1)
      B = B[:j] + B[j+1:]
      break
  i += 1
if B:
  print(-1)
else:
  for k in range(N)[::-1]:
    print(S[k])

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

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

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

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

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

if anslist.count(110)>0:
    print(-1)
else:
    for i in (reversed(anslist)):
        print(i)

Solution (Python):
from fractions import gcd

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    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 b[j] == j+1:
                ans.append(j+1)
                b = b[:j] + b[j+1:]
                break
        if len(b) + i + 1 != n:
            print(-1)
            return
    ans = ans[::-1]
    for i in range(n):
        print(ans[i])

main()

Solution (Python):
n = int(input())
b = [int(i) for i in input().split()]
flag = True
for i in range(n):
    if b[i] > i+1:
        flag = False
        break

if not flag:
    print(-1)
else:
    ans = []
    while len(b) > 0:
        for m in range(max(b), 0, -1):
            if b[m-1] == m:
                ans.append(b[m-1])
                del b[m-1]
                break
    ans = ans[::-1]
    print(*ans, sep="\n")

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

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

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

Solution (Python):
from sys import exit, stdin
N = int(stdin.readline().rstrip())
B = [int(_) for _ in stdin.readline().rstrip().split()]
def solve():
    ans = []
    for _ in range(N):
        pivot = -1
        for j in range(len(B)-1, -1, -1):
            if B[j] == j+1:
                pivot = j
                break
        if pivot == -1:
            print(-1)
            exit()
        ans.append(pivot+1)
        B.pop(0+pivot)
    ans.reverse() 
    for v in ans:
        print(v)
solve()

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

ans = []
for _ in range(200):
    if len(b) == 0:
        for i in reversed(ans):
            print(i)
        break
    for i, v in enumerate(reversed(b)):
        if len(b)-i == v:
            ans.append(len(b)-i)
            del b[len(b)-i-1]
            break
    else:
        print(-1)
        break