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(lambda x: int(x) - 1, input().split()))
res = []
for i in range(N):
    for j in range(len(B) - 1, -1, -1):
        if B[j] == j:
            res.append(B.pop(j))
            break
if len(B) == 0:
    for r in res[::-1]:
        print(r + 1)
else:
    print(-1)

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

ans = []

for i in range(n):
    tmp = -1
    for j,e in enumerate(b):
        if j + 1 == e:
            tmp = max(tmp, e)
    if tmp == -1:
        print(-1)
        exit()
    else:
        ans.append(tmp)
        b = b[:tmp-1] + b[tmp:]

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

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

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

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

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

ans = []
for _ in range(n):
    for i, bi in enumerate(b[::-1]):
        i = len(b) - i
        if i == bi:
            ans.append(b.pop(i-1))
            break
print(*(ans[::-1] if len(ans) == n else[-1]), sep='\n')

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

ans = []
for _ in range(n):
    for i, bi in enumerate(b[::-1]):
        if len(b) == bi + i:
            ans.append(b.pop(len(b) - i - 1))
            break
print(*(ans[::-1] if len(ans) == n else [-1]), sep='\n')

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

ans = []
for _ in range(n):
    for i, bi in enumerate(b[::-1]):
        i = len(b) - i
        if i == bi:
            ans.append(b.pop(i-1))
            break
print(*(ans[::-1] if len(ans) == n else[-1]), sep='\n')

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

a = []
flg = True
while b:
    for i in range(len(b), 0, -1):
        if b[i-1] == i:
            a.append(b.pop(i-1))
            break
        elif i == 1:
            flg = False
            break
    if not flg:
        break
a.reverse()
a = [str(i) for i in a]
print('\n'.join(a)) if flg else print(-1)

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 b[j]==j+1:
            ans.append(b.pop(j))
            break
ans=list(reversed(ans))

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

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

out = []

for i in range(N):
    cand = []
    for j in range(len(B)):
        if B[j] == j + 1:
            cand.append(j)
    if len(cand) > 0:
        candmax = max(cand)
        out.append(candmax + 1)
        del B[candmax]
    else:
        print(-1)
        exit()
print(*out[::-1])

Solution (Python):
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().rstrip().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

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

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

def main():
	N, = linput()
	vB = linput()
	
	vC = [b-i-1 for i,b in enum(vB)]
	vC.reverse()
	
	res = 0
	vR = []
	
	for _ in "*"*N:
		try:
			x = vC.index(0)
			vR.append(vB[N-x-1])
			vC[x] = -INF
			for j in range(x):
				vC[j] += 1
		except ValueError as e:
			print(-1)
			return
	
	
	
	
	print(*vR[::-1], sep="\n")

if __name__ == "__main__":
	main()

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

ans = []
while True:
    flag = False
    if len(b) == 0:
        break

    for i in range(len(b)):
        if i+1 == b[i]:
            idx = i
            flag = True
    if flag:
        tmp = b.pop(idx)
        ans.append(tmp)
    else:
        ans = [-1]
        break

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

Solution (Python):
from collections import deque

N = int(input())
b_li = list(map(int, input().split()))
a_li = deque()
while len(b_li) > 0:
    found = False
    for i in range(len(b_li) - 1, -1, -1):
        if b_li[i] == i + 1:
            found = True
            a_li.appendleft(b_li[i])
            del b_li[i]
            break

    if not found:
        print(-1)
        exit()

for a in a_li:
    print(a)

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

ans = []

while bb:
    imp = True
    for i,v in zip(range(len(bb),0,-1),bb[::-1]):

        if i==v:
            ans.append(v)
            del bb[i-1]
            imp = False
            break
    if imp:
        ans = [-1]
        break

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

Solution (Python):

"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    b_lsit = list(map(int, input().split()))

    flag = True
    answer_list = []
    while flag and b_lsit:
        
        for i in range(len(b_lsit)-1, -2, -1):
            if i == -1:
                flag = False
                break
            elif b_lsit[i] == i+1:
                answer_list.append(b_lsit.pop(i))
                break

    if flag:
        for b in answer_list[::-1]:
            print(b)
    else:
        print(-1)

    return

if __name__ == "__main__":
    main()

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil



import string

from bisect import bisect_left

def solve():
    n = int(input())
    ans = [0] * n
    a = [int(x) for x in input().split()]
    ok = 1
    cur = n - 1
    while ok and a:
        ok = 0
        i = len(a) - 1
        while i >= 0:
            if a[i] - 1 == i:
                ok = a[i]
                a.pop(i)
                break
            i -= 1
        ans[cur] = ok
        cur -= 1

    if a:
        print(-1)
    else:
        for e in ans:
            print(e)
t = 1

for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

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


ANS = []
flag = 0
while B != [0]:
    for j in range(len(B)-1, 0, -1):
        b = B[j]
        if b == j:
            ANS.append(B.pop(j))
            break
    else:
        flag = 1
        break
        
if flag:
    print(-1)
else:
    for ans in ANS[::-1]:
        print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    b = LI()

    
    ans = []
    while b:
        has_pop = False
        len_b = len(b)
        for i in range(len_b):
            j = len_b - 1 - i
            if b[j] == j + 1:
                b.pop(j)
                ans.append(j + 1)
                has_pop = True
                break
        if not has_pop:
            break

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

if __name__ == '__main__':
    resolve()

Solution (Python):
n, s = open(0)
a=['']
for i in s.split():
    a.insert(int(i)-1, i)
if a[-1] == "":
    print(*a)
else:
    print(-1)

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
ans=[]
for i in range(N):
   for j in reversed(range(N-i)):
      if j+1 == l[j]:
         ans.append(l[j])
         l.pop(j)
         break
      if j == 0:
         print("-1")
         exit()
ans=ans[::-1]
for i in ans:
   print(i)

Solution (Python):
N = int(input())
DUMMY = -1
B = [DUMMY] + list(map(int, input().split()))


def last_insert_elem():
    for b,i in zip(reversed(B), reversed(range(len(B)))):
        if b==i:
            return B.pop(i)
    return DUMMY

ans = []
for _ in range(N):
    e = last_insert_elem()
    if e == -1:
        print(-1)
        exit()
        
    ans.append(e)

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

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

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

Solution (Python):
n = int(input())
B = list(map(lambda x: x-1, map(int, input().split())))
ans = []
for i in range(n):
    for j in range(len(B)-1,-1,-1):
        if B[j]==j:
            ans.append(j+1)
            del B[j]
            break
        elif j==0:
            ans = -1
            break
    if ans==-1:
        break

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

Solution (Python):

import sys

n = int(input())
nums = [int(i) - 1 for i in input().split()]
ans = []
for i in range(n):
    for j in range(len(nums) - 1, -1, -1):
        if nums[j] == j:
            ans.append(j + 1)
            del nums[j]
            break
    else:
        print(-1)
        sys.exit()
for a in ans[::-1]:
    print(a)

Solution (Python):

import sys


def solve(N: int, b: "List[int]"):
    c = b[:] 
    ans = []
    while c:
        x = max(filter(lambda x: x[0] == x[1], enumerate(c, 1)), default=0)
        if not x:
            return [-1]
        ans.append(x[0])
        del c[x[0]-1]
    return ans[::-1]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    b = [int(next(tokens)) for _ in range(N)]  
    print(*solve(N, b), sep="\n")

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(n, 0, -1):
    ok = False
    for j in range(i, 0, -1):
        if b[j - 1] == j:
            ans.append(b.pop(j - 1))
            ok = True
            break
    if not ok:
        print(-1)
        exit()

for i in range(n):
    print(ans.pop())

Solution (Python):
from collections import deque

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

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

if not b:
    
    print(*result, sep='\n')
else:
    print(-1)

Solution (Python):
from collections import deque

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

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *


N = INT()
a = LIST()

ans = deque()
while a:
	for i in range(len(a)-1, -1, -1):
		if a[i] == i+1:
			ans.appendleft(a.pop(i))
			break
	else:
		print(-1)
		exit()

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

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

ans = []
while N > 0:
  ok = False
  for i in range(N)[::-1]:
    b = B[i]
    if b == (i+1):
      ans.append(b)
      ok = True
      k = i
      break
  
  if not ok:
    break
  else:
    newB = []
    for i in range(N):
      if i != k:
        newB.append(B[i])
    
    B = newB
    N -= 1

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

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(n):
    target = None
    for j in range(n-i):
        if int(b[j])==j+1:
            target = j
    if target is None:
        ans = -1
        break
    ans.append(target+1)
    b = b[:target] + b[target+1:]
else:
    ans = "\n".join(map(str, ans[::-1]))
print(ans)

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

for i in range(n):
    if i+1<b[i]:
        print(-1)
        exit(0)


from collections import deque

d=deque([])

while len(d)<n:
    tmp=b
    for j in range(len(tmp)-1,-1,-1):
        if j+1==tmp[j]:
            d.append(tmp[j])
            break

    b.pop(j)


for _ in range(n):
    v=d.pop()
    print(v)

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

ans = []
while B:
    for i,v in enumerate(B[::-1]):
        if len(B)-i == v:
            a = B.pop(len(B)-i-1)
            ans.append(a)
            break
    else:
        break
if not B:
    print(*ans[::-1],sep='\n')
else:
    print(-1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    B = list(map(int, input().split()))

    res = []
    while B:
        for i in reversed(range(len(B))):
            if B[i] == i + 1:
                b = B.pop(i)
                res.append(b)
                break
        else:
            print(-1)
            exit()
    print(*res[::-1], sep="\n")


if __name__ == '__main__':
    resolve()

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
ans=[]
while True:
    l=len(b)
    temp=[]
    flag=0
    for i in range(l-1,-1,-1):
        if flag==1 or b[i]!=i+1: temp.append(b[i])
        else:
            ans.append(i+1)
            flag=1
    b=temp[::-1]
    if len(b)==l:
        print(-1)
        exit()
    elif len(b)==0: break
for val in ans[::-1]: print(val)

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

for i in range(n):
    if l[i] > i+1:
        print(-1)
        exit()

ans = []
while len(l) > 0:
    for i, x in enumerate(l[::-1]):
        if len(l) - i == x:
            ans.append(x)
            l.pop(len(l)-i-1)
            break
for i, x in enumerate(ans[::-1]):
    print(x)

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

ans = []

while b:
    f = True
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            b.remove(i+1)
            ans.append(i+1)
            f = False
            break
    if f: 
        ans = '-1'
        break
if ans == '-1':
    print(ans)
else:
    for a in ans[::-1]:
        print(a)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    b = in_nl()

    ans = []
    while True:
        ind = -1
        for i in range(len(b)):
            if i+1 == b[i]:
                ind = i
        if ind != -1:
            b.pop(ind)
            ans.append(ind+1)
            if len(b) == 0:
                break
        else:
            break

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





if __name__ == '__main__':
    main()

Solution (Python):
import sys
from copy import deepcopy
N = int(input())
b = [int(i) for i in input().split()]

ans = []
for i, x in enumerate(b):
    if x > i+1:
        print(-1)
        sys.exit()
while len(b) != 0:
    for i, x in enumerate(b[::-1]):
        if len(b)-i == x:
            ans.append(x)
            b.pop(len(b) - i - 1)
            break
print(*ans[::-1], sep='\n')

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)



class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


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

x = [0 for i in range(n)]
ans = []
while True:
    flag = True
    for i in reversed(range(n)):
        if x[i] > 0:
            continue
        cnt = sum(x[:i])
        
        
        
        if b[i] == cnt + 1:
            x[i] = 1
            ans.append(b[i])
            flag = False
            break
    if len(ans) == n:
        break
    if flag:
        break


if len(ans) < n:
    print(-1)
else:
    for i in ans:
        print(i)

Solution (Python):
N = int(input())
B = list(map(lambda x: int(x)-1, input().split()))

ans = []
for i in range(N):
    erase = -1
    for c in reversed(range(len(B))):
        if B[c] == c:
            erase = c
            break
    
    if erase == -1:
        print(-1)
        exit()
    else:
        ans.append(erase)
        B.pop(erase)

for _ in ans[::-1]:
    print(_+1)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
for i in range(N):
    b[i] -= 1
lis = []
for i in range(N):
    flg = False
    for j in reversed(range(N-i)):
        if b[j] == j:
            lis.append(j+1)
            del b[j]
            flg = True
            break
    if flg == False:
        print(-1)
        exit()
for i in reversed(range(N)):
    print(lis[i])

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

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

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
rev = []
for i in range(n): 
    cand = []
    for j in range(len(b)):
        if b[j] != j+1:
            if cand:
                continue
            break
        else:
            cand.append(j+1)
    if not cand:
        print(-1)
        exit()
    rev.append(cand[-1])
    b.pop(cand[-1]-1)
ans = reversed(rev)
for k in ans:
    print(k)

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

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

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

l=[]
flg=0

for i in range(n-1,-1,-1):
  
  flg=0
  for j in range(i,-1,-1):
    
    if j+1==b[j]:
      flg=1
      l.append(b.pop(j))
      break
  if flg==0:
    break

if flg==0:
  print(-1)
else:
  for i in range(n-1,-1,-1):
    print(l[i])

Solution (Python):



def main():
    N = int(input())
    B = list(map(int,input().split()))
    ret = []
    while len(B)>0:
        for j in range(len(B)-1,-1,-1):
            if B[j]==j+1:
                ret.append(j+1)
                B.pop(j)
                break
            if j==0 and B[j]!=(j+1):
                print(-1)
                exit()
    print('\n'.join(map(str,ret[::-1])))


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

res = []
for _ in range(N):
    tmp = -1
    for i, b in enumerate(B):
        if i + 1 == b:
            tmp = i
    if tmp == -1:
        print(-1)
        exit()
    res.append(B.pop(tmp))

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

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

ansl = []
while len(b) != 0:
	tmp = 0
	for i in range(len(b)):
		targ = i+1-b[i]
		if targ == 0:
			tmp = i
	ansl.append(str(b[tmp]))
	b.pop(tmp)

ansl.reverse()
print("\n".join(ansl))

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

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

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

ans.reverse()

for ans_i in ans:
    print(ans_i)

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

ans = []

for i in range(N):
    pop = -1
    for j, v in enumerate(b):
        if j+1 == v:
            pop = j
    if pop == -1:
        print(-1)
        exit()
    ans.append(b.pop(pop))
for i in ans[::-1]:
    print(i)

Solution (Python):


import math



from collections import deque




n=int(input())
b=list(map(int,input().split()))
ans=[]
while True:
    f=False
    for i in range(len(b)-1,-1,-1):
        if b[i]!=i+1:
            continue
        else:
            ans.append(b[i])
            b.pop(i)
            f=True
            break
    if not b:
        break
    if not f:
        print(-1)
        exit()
for i in range(n):
    print(ans[n-1-i])

Solution (Python):
class node():
    def __init__(self, data, child=None):
        self.child = child
        self.data = data

class head():
    def __init__(self, data):
        self.child = None
        self.length = 0
        for i in data:
            self.add(i)

    def add(self, i):
        self.child = node(i, child=self.child)
        self.length += 1
    
    def remove(self):
        idx = self.length
        root = self
        child = self.child
        while child is not None:
            if child.data == idx:
                root.child = child.child
                self.length -= 1
                return child.data
            idx -= 1
            root = child
            child = root.child

        return False

n = int(input())
data = list(map(int, input().split()))
linked = head(data)
ans = []
while True:
    step = linked.remove()
    if step is False:
        break
    ans.append(step)

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

Solution (Python):
from fractions import gcd

def mi():
    return map(int, input().split())

def main():
    N = int(input())
    b = list(mi())
    a = []
    for i in range(N):
        bl = False
        for j, v in enumerate(b):
            if v == j+1:
                t = j
                bl = True
        if bl:
            a.append(b.pop(t))
        else:
            print(-1)
            return
    
    for v in reversed(a):
        print(v)



if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
L=list(map(int,input().split()))
for i in range(n):
    if L[i]>i+1:
        print(-1)
        exit()
def mal(x):
    if len(x)==0:
        return []
    else:
        t=max(x)
        i=x.index(t)
        k=i-1
        while k>i-t:
            if x[k]>t-i+k:
                t=x[k]
                i=k
            k -= 1
        after=x[:i-t+1]
        before=x[i-t+1:]
        before.remove(t)
        return mal(before)+[t]+mal(after)
ans=mal(L)

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

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

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

ans.reverse()

for ans_i in ans:
    print(ans_i)

Solution (Python):






from collections import deque,defaultdict











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
b = readInts()
ans = []
for i 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(pivot)
print(*ans[::-1],sep='\n')

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    B = list(map(int, input().split()))

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


if __name__ == '__main__':
    resolve()