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 main():
    length = int(input())
    target = list(map(int, input().split()))
    max_num = max(target)
    answer = []
    for _ in range(length):
        for i in range(max_num - 1, -1, -1):
            if len(target) >= i + 1 == target[i]:
                target.pop(i)
                answer.append(i + 1)
                break
        else:
            print(-1)
            answer = []
            break
    if answer:
        for i in range(-1, -length - 1, -1):
            print(answer[i])


if __name__ == '__main__':
    main()

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


ans = []
while len(B) > 0:
    can_delete = False
    for i in range(len(B) - 1, -1, -1):
        if i + 1 == B[i]:
            ans.append(B[i])
            del B[i]
            can_delete = True
            break
    if not can_delete:
        break

if len(B) > 0:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


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


def check(B, cnt):
    n = len(B)
    for i in range(n):
        if B[n - i - 1] == (n - i):
            hand.append(B[n - i - 1])
            B = B[: n - i - 1] + B[n - i :]
            break
    if len(B) != n and len(B) > 0:
        return B
    else:
        return False


cnt = 1
while B:
    B = check(B, cnt)
    

if len(hand) < N:
    print(-1)
    sys.exit()
answer = hand[::-1]
for i in range(N):
    if answer[i] > i + 1:
        print(-1)
        sys.exit()
print(*answer, sep="\n")

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


ans=[]
for _ in range(n):
    for idx in range(1,len(b)+1)[::-1]:
        if idx==b[idx-1]:
            ans+=idx,
            del b[idx-1]
            break


if len(b)>0:
    print(-1)
    exit()

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

Solution (Python):
from collections import deque

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

if B[0] != 1:
    print(-1)
    exit()
if N == 1:
    print(1)
    exit()


B.pop(0)

ans = deque()
while B:
    tmp = -1
    for i,b in enumerate(B):
        if i == 0 and b == 1:
            tmp = i
        elif b == i + 2:
            tmp = i
    if tmp < 0:
        print(-1)
        exit()
    ans.appendleft(B.pop(tmp))

ans.appendleft(1)

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

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

for i in range(n):
    delete = max([a[j] if (j == a[j] - 1) else 0 for j in range(len(a))])
    if (delete == 0):
        print(-1)
        exit()
    else:
        ans.append(delete)
        a.pop(delete-1)

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

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

def solve(arr):
  ret = []
  while len(arr) > 0:
    before = len(arr)
    for i in reversed(range(len(arr))):
      if arr[i] == i + 1:
        ret.append(arr.pop(i))
        break
    if len(arr) == before:
      return None
  return list(reversed(ret))

A = solve(B)


if A == None:
  print(-1)
else:
  for a in A:
    print(a)

Solution (Python):





import itertools



import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

    res = [0] * n

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

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




if __name__ == '__main__':
    main()

Solution (Python):







n = int(input())
b = list(map(int,input().split()))
for i in range(n):
    if b[i] > i+1: 
        print(-1)
        exit()
ans = []
add = [0]*n
for cnt in range(n):
    for i in range(n-1,-1,-1):
        if b[i] == i+1:
            ans.append(b[i]-add[i])
            b[i] = -1
            for j in range(i+1,n):
                b[j] += 1
                add[j] += 1
            break
for i in range(n-1,-1,-1):
    print(ans[i])

Solution (Python):
N=int(input())
B=[int(i) for i in input().split()]
TF=[True for _ in range(N)]
I=list(reversed(range(N)))
ans=[]
d=0
while N!=d:
  
  flag=True 
  k=d
  for i in I:
    
    if TF[i]:
      if i+1-k==B[i]:
        TF[i]=False
        flag=False
        ans.append(i)
        d+=1
        break
    else:
      k-=1
  if flag:
    ans=-1
    break
if ans==-1:
  print(ans)
else:
  for i in reversed(ans): print(B[i])

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

tmp=-1
idx=0
count=1
flag=True
ans=[]
while(len(b)):
    
    if idx<len(b):
        if b[idx]==count:
            tmp=idx
            idx+=1
            count+=1
        else:
            idx+=1
            count+=1
    if idx>(len(b)-1):
        if tmp==-1:
            flag=False
            break
        else:
            
            ans.append(b[tmp])
            del b[tmp]
            tmp=-1
            idx=0
            count=1

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

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
f = True
res = []
while len(dat) > 0:
    t = -1
    for i in range(len(dat)):
        if i+1 == dat[i]:
            t = i
    if t == -1:
        f = False
        break
    res.append(dat[t])
    del dat[t]
if f is False:
    print(-1)
else:
    res.reverse()
    print("\n".join(list(map(str, res))))

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

if __name__ == "__main__":
    main()

Solution (Python):
"""
index = j を満たすもののうち最大のものを消していく
→消した番号の逆順が答え
"""
n = int(input())
b = list(map(int, input().split()))

ans = []

while len(b) != 0:
    index = -1
    for j in range(len(b)):
        if j+1 == b[j]:
            index = j

    if index == -1:
        print(-1)
        exit()
    else:
        ans.append(b.pop(index))

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

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

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

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

L = []

while B:
    temp = []
    for i in range(len(B)):
        if B[i] == i+1:
            temp.append(i+1)
    if temp:
        L.append(max(temp))
        B.remove(max(temp))
    else:
        break

if B:
    print(-1)
else:
    L.reverse()
    for l in L:
        print(l)

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

def pin(type=int):
    return map(type,input().split())
     


                
def resolve():
    N=int(input())
    b=list(pin())
    ans=[]
    t=0
    for elem in range(N):
        for i in range(N-t,0,-1):
            if b[i-1]==i:
                ans.append(i)
                b.pop(i-1)
                t+=1
                break
    if len(ans)!=N:print("-1")
    else:
        for wa in reversed(ans):
            print(wa)
        


"""


"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
1 2 1"""
        output = """1
1
2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2
2 2"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """9
1 1 1 2 2 1 2 3 2"""
        output = """1
2
2
3
1
2
2
1
1"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Solution (Python):
n = int(input())
B = list(map(int, input().split()))
ret = []
enabled = True

def get_latest():
  for i in range(len(B)):
    if len(B) - i == B[len(B) - i - 1]:
      break
  else:
    global enabled
    enabled = False
  ret.append(B.pop(len(B) - i - 1))
  if B:
    get_latest()

get_latest()
if enabled:
  for i in range(n):
    print(ret[n - i - 1])
else:
  print(-1)

Solution (Python):
import sys
n = int(input())
b_ls = [int(i) for i in sys.stdin.readline().split()]
cnt = 0
res = []
while len(b_ls) > 0:
    flg = True
    for i in range(n - cnt - 1, -1, -1):
        if b_ls[i] == i + 1:
            cnt += 1
            res.append(i+1)
            b_ls.pop(i)
            flg = False
            break
    if flg:
        res = -1
        break
if res == -1:
    print(res)
else:
    for b in res[::-1]:
        print(b)

Solution (Python):
N = int(input())
blist = list(map(int, input().split()))
ans = []
for i in range(N):
    for index in range(N-i-1, -1, -1):
        if blist[index] == index + 1:
            ans.append(blist.pop(index))
            break
    else:
        print(-1)
        break
else:
    for num in ans[::-1]:
        print(num)

Solution (Python):
import sys

N = int(input())

Bs = [B - 1 for B in map(int, input().split())]

anss = []
for _ in range(N):
    iNow = -1
    for i in reversed(range(len(Bs))):
        if Bs[i] == i:
            iNow = i
            break
    else:
        print(-1)
        sys.exit()

    anss.append(iNow)

    Bs = Bs[:iNow] + Bs[iNow+1:]

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

Solution (Python):

n=int(input())
lists=list(map(int,input().split()))
flag=True
for i in range(n):
    if i+1<lists[i]:
        flag=False
        break
if not flag:
    print(-1)
else:
    
    ans=[]
    for i in range(n):
        for j in range(n-1-i,-1,-1):
            if lists[j]==j+1:
                ans.append(lists[j])
                del lists[j]
                break
    ans=ans[::-1]
    for some in ans:
        print(some)

Solution (Python):
N=int(input())
x=[0]
inp=input().split()
for k in range(N):
  x.append(int(inp[k]))
y=[]
OK=True
for k in range(N):
  ok=False
  for i in range(len(x)-1,0,-1):
    if x[i]==i:
      y.insert(0,i)
      del x[i]
      ok=True
      break
  if ok==False:
    print(-1)
    OK=False
    break
if OK==True:
  for k in range(len(y)):
    print(y[k])

Solution (Python):
def main():
    N=int(input())
    b=list(map(int,input().split()))
    result_inv=[]
    result_flag=True
    for _ in range(N):
        flag=False
        for i in range(len(b)):
            if i+1==b[i]:
                j=i
                flag=True
        if flag:
            a=b.pop(j)
            result_inv.append(a)
            flag=False
        else:
            result_flag=False
            break

    if result_flag:
        result=result_inv[::-1]
        for i in range(N):
            print(result[i])
    else:
        print(-1)

if __name__=="__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    B = [int(i) for i in input().split()]
    ans = []
    while B:
        for i in range(len(B))[::-1]:
            if B[i] == i+1:
                ans.append(B[i])
                del B[i]
                break
        else:
            return print(-1)
    print(*ans[::-1], sep="\n")


if __name__ == '__main__':
    main()

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


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

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


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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1
ans = []
for _ in range(N):
    M = len(A)
    for i in range(M - 1, -1, -1):
        if A[i] > i:
            print(-1)
            exit()
        if A[i] == i:
            ans.append(A[i] + 1)
            A.pop(i)
            break
    if len(ans) == N:
        break
ans.reverse()
for a in ans:
    print(a)

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

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

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

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

cant = 0
stack = []
for i in range(n, 0, -1):
        tmp = len(a)
        for j in range(len(a)-1, -1, -1):
                if j+1==a[j]:
                        if j>i: cant = 1
                        a.pop(j)
                        stack.append(j+1)
                        break
        if len(a)==tmp: cant = 1

if cant: print(-1)
else:
        for i in stack[::-1]: print(i)

Solution (Python):
N,*B=map(int, open(0).read().split())
res=[]
while B:
    C=[i-b for i,b in enumerate(B,1)]
    if any(c<0 for c in C):
        print(-1)
        break
    D=[i for i,c in enumerate(C) if c==0]
    if D:
        res.append(D[-1]+1)
        B=B[:D[-1]]+B[D[-1]+1:]
    else:
        print(-1)
        break
else:
    print(*res[::-1], sep="\n")

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

Solution (Python):








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

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

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

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

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

ops = []

for i in range(N, 0, -1):
    for j in range(i - 1, -1, -1):
        if b[j] == j:
            ops.append(j)
            b = b[:j] + b[j + 1:]
            break
    else:
        ops = [-2]
        break

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

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

for i in range(n):
    for j in range(n-i)[::-1]:
        k = j+1
        if b[j] == k:
            del b[j]
            ans.append(k)
            break
    else:
        ans = [-1]
        break

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

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
used=[0]*n
ans=[]
for _ in range(n):
    for i in range(len(A)-1,-1,-1):
        if A[i]==i+1:
            ans.append(i+1); count += 1
            
            del A[i]
            break
ans.reverse()

print(*ans if count == n else [-1],sep="\n")

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

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

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

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    ans = []
    for i in range(N):
        l = len(a)
        for i in reversed(range(l)):
            if a[i] == i+1:
                p = a.pop(i)
                ans.append(p)
                break
                
    if a != []:
        print(-1)
    else:
        for i in range(N):
            print(ans[-1-i])

if __name__ == "__main__":
    main()

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

ans = []
for k in range(n):
    for i in range(n-1-k, -1, -1):
        if bl[i] == i+1:
            a = bl.pop(i)
            ans.append(a)
            break
    else:
        print(-1)
        exit()

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

Solution (Python):



n = int(input())
b_lis = list(map(int, input().split()))
ans = []
while b_lis:
    tmp = -1
    for i, v in enumerate(b_lis):
        if v == i + 1:
            tmp = i
    if tmp >= 0:
        ans.append(tmp + 1)
        b_lis = b_lis[:tmp] + b_lis[tmp + 1 :]
    else:
        print(tmp)
        exit()

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

Solution (Python):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = []

while li:
    now = 10**10
    for i,j in enumerate(li,1):
        if i == j:
            now = i
    if now == 10**10:
        print(-1)
        exit()
    lin.append(now)
    li.pop(now-1)

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

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

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

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

while len(b) > 0:
    m = -1
    for i in range(len(b)):
        if b[i] == i + 1:
            m = i
    if m == -1:
        break
    else:
        s.append(b.pop(m))

if m == -1:
    print(-1)
else:
    print(*reversed(s), sep='\n')

Solution (Python):
n = int(input())
lst = list(map(int,input().split()))
stock = []
flg = True
for i in range(n):
    tmp = -100
    for j in range(len(lst)):
        if lst[j] == j+1:
            tmp = max(tmp, j)
    if tmp == -100:
        flg =  False
        break
    else:
        stock.append(lst[tmp])
        lst = lst[:tmp]+lst[tmp+1:]
if not flg:
    print(-1)
else:
    for x in stock[::-1]:
        print(x)

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

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

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

c = sorted(b)

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

ans = []

for i in range(n):
    s = b[i]
    ans.insert(s-1, s)

print(*ans)

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

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

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

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

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

	return 0


A = solve(a,[])
if A == 0:
	print(-1)
else:
	for a in A[::-1]:
		print(a)

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
    else:
        print(-1)
        break
else:
    for a in ans[::-1]:
        print(a)

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
    else:
        print(-1)
        break
else:
    for a in ans[::-1]:
        print(a)

Solution (Python):
def solve(n, b):
    a = []
    while b:
        m = len(b)
        tj = -1
        for j in range(m, 0, -1):
            if b[j-1] == j:
                tj = j
                break
        if tj == -1:
            return -1
        else:
            a.append(tj)
            b = b[:tj-1] + b[tj:]
    return "\n".join(map(str, a[::-1]))

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

Solution (Python):
import math
import bisect
import collections
import itertools
import heapq
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd 
def lcm(a,b):return (a*b) // math.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def comb(l, n): return itertools.combinations(l, n) 
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
b = iln()
ans = []
for _ in range(N):
    if len(b) == 0: break
    matched = -1
    for j in range(0, len(b)):
        if b[j] == j+1: matched = j
    if matched != -1:
        ans.append(b.pop(matched))
    else:
        ans.clear()
        break
if len(ans) > 0:
    for _ in range(len(ans)):
        print(ans.pop())
else:
    print(-1)

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

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

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

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
i = n - 1
ans = []
while i > -1 and n != 0:
    if b[i] == i + 1:
        ans.append(b.pop(i))
        n -= 1
        i = n - 1
    else:
        i -= 1
if n == 0:
    ans.reverse()
    print(*ans, sep='\n')
else:
    print(-1)

Solution (Python):
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
B = rl()
l = []
for i in range(N):
    if i + 1 < B[i]:
        print(-1)
        exit()

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

"""
・任意の i に対して A[i] <= i が必要
・このときできる。次のようにすればよい
・A[i] = i となる 最大の i を取り除く（i=1が満たすので存在）。帰納法がまわってできる。
"""

bl = all(x <= i for i,x in enumerate(A,1))
if not bl:
    print(-1)
    exit()

answer = []
while A:
    I = [i for i,x in enumerate(A) if i + 1 == x]
    i = I[-1]
    answer.append(i + 1)
    A = A[:i] + A[i+1:]

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

Solution (Python):
res = []
def f(l):
    n = len(l)
    for i in range(n)[::-1]:
            if l[i] == i:
                res.append(i+1)
                l.pop(i)
                break
    return l

N = int(input())
a = [int(_)-1 for _ in input().split()]

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

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

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

def f(b):
  i=len(b)-1
  while i>=0 and b[i]!=i+1:
    i-=1
  if i>=0:
    del b[i]
    return i, b
  else:
    return -1, []

j, b_=f(b)
while j>=0:
  a=[j]+a
  j, b_=f(b_)
  
if len(a)==N:
  for i in range(N):
    print(a[i]+1)
else:
  print(-1)

Solution (Python):


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

    answer = []
    while b:
        for i in range(len(b)-1,-1,-1):
            if b[i] == i+1:
                answer.append(b[i])
                b.pop(i)
                break
        else:
            print(-1)
            return
    for i in range(N-1,-1,-1):
        print(answer[i])
    return 

if __name__ == '__main__':
    main()

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

Solution (Python):

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

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

    
    if is_end:
        print(-1)
        exit()

for n in reversed(buf):
    print(n)

Solution (Python):
from collections import deque
import itertools

N=int(input())
b=[-1]+list(map(int,input().split()))
ans=deque([])
for i in range(N):
    i=len(b)-1
    while i>0:
        if b[i]==i:
            ans.appendleft(str(i))
            b=list(itertools.chain(b[:i],b[i+1:]))
            break
        i-=1
    else:
        break
if len(b)==1:
    print("\n".join(ans))
else:
    print(-1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    if a[i]>i+1:
        print(-1)
        exit()
def order(a):
    if a == [1]:
        return [1]
    else:
        x = order(a[:-1])
        y = a[-1]
        x.insert(y-1,y)
        return x
print(*order(a),sep="\n")

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


ans = []
for i in range(N):
    for j in reversed(range(len(b))):
        if b[j] == j+1:
            b.pop(j)
            ans.append(j+1)
            break
ans.reverse()
if len(b) == 0:
    for a in ans:
        print(a)
else:
    print(-1)

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