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):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    B = list(map(int, readline().split()))
    ans = []
    for _ in range(N):
        L = len(B)
        k = -1
        for i in range(L):
            if B[i]==i+1:
                k = i
        if k == -1:
            print('-1')
            sys.exit()
        else:
            ans.append(B.pop(k))
    for i in range(N)[::-1]:
        print(ans[i])

if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
import numpy as np

N = int(input())
B = list(map(int, input().split()))
Ans = deque()
Sa = np.zeros(N)
for a, b in enumerate(B):
    Sa[a] = a-b+1
while 0 in Sa:
    for i in range(N)[::-1]:
        if Sa[i] == 0:
            Ans.appendleft(B[i])
            Sa[i:] -= 1
            break
if len(Ans) != N:
    print(-1)
else:
    for i in range(len(Ans)):
        a = Ans.popleft()
        print(a)

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

for i,b in enumerate(B):
    if i + 1 < b:
        print(-1)
        exit()

N = len(B)
ans = []
for _ in range(N):
    for i,b in enumerate(B):
        if i+1 == b:
            t = i+1

    B.pop(t-1)
    ans.append(t)
for i in ans[::-1]:
    print(i)

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

ans = []

for i in range(N):
    L = -1
    for j in range(len(b)):
        if j+1 == b[j]:
            L = j

    if L != -1:
        ansi = b.pop(L)
        ans.append(ansi)

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

Solution (Python):
from collections import deque,Counter

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

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

print(*ans)

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

ans = [0] * n
for i in range(1,n+1):
    num = -1
    for j in range(n+1-i):
        if(b[j] == j+1):
            num = j
    if(num == -1):
        print(-1)
        exit()
    ans[-i] = num + 1
    del b[num]

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

Solution (Python):





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

ans = []
for _ in range(N):
    for i in range(len(B) - 1, -1, -1):
        if i + 1 == B[i]:
            ans.append(B[i])
            del B[i]
            break
    else:
        print(-1)  
        exit()
print(*reversed(ans), sep='\n')

Solution (Python):
N = int(input())
b = list(map(int,input().split()))
l = [0]*N
for i in range(N):
  for j in range(min(N,len(b))-1,-1,-1):
    if b[j] == j+1:
      b.pop(j)
      l[i] = j+1
      break
if b == []:
  l.reverse()
  for k in range(N):
    print(l[k])
else:
  print(-1)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = []
while b:
    for i, j in enumerate(reversed(b)):
        if j==len(b)-i:
            ans.append(j)
            del b[len(b)-i-1]
            break
    else:
        print(-1)
        break
else:
    for i in reversed(ans):
        print(i)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = []
while b:
    m = len(b)
    ok = False
    for i in range(m)[::-1]:
        if b[i] == i+1:
            a.append(b.pop(i))
            ok = True
            break

    if not ok:
        print('-1')
        exit()

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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(B.pop(j))
                break
        else:
            print(-1)
            break
    else:
        print('\n'.join(map(str,ans[::-1])))

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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(B.pop(j))
                break
        else:
            print(-1)
            break
    else:
        print('\n'.join(map(str,ans[::-1])))

if __name__=='__main__':
    main()

Solution (Python):

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

ans = []
removed = [False] * N

flag = True
while flag:
    flag = False
    
    idx_remove = -1
    idx = 0
    for i in range(N):
        if removed[i]:
            continue

        if idx + 1 == B[i]:
            idx += 1
            idx_remove = i

        else:
            idx += 1
    
    if idx_remove != -1:
        ans.append(B[idx_remove])
        removed[idx_remove] = True
        flag = True


if all(removed):
    for a in ans[::-1]:
        print(a)
else:
    print(-1)

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

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

Solution (Python):
import collections
def main():
    N = int(input())
    B = [0] + [int(_) for _ in input().split()]

    for i in range(1, N+1):
        if i < B[i]:
            print(-1)
            return
    dic = collections.defaultdict(int)
    for i in range(1, N+1):
        x = B[i]
        c = 0
        for j in range(i+1, N+1):
            if B[j] <= x:
                x += 1
                c += 1
        dic[B[i]+c] = B[i]
    out = [dic[key] for key in sorted(dic.keys())]
    print(*out, sep = '\n')
    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline  
sys.setrecursionlimit(10 ** 7)  


def dfs(N, a, i, procedure):
    if i == 0:
        return procedure

    for j in reversed(range(1, i+1)):
        if a[j-1] == j:
            l = a[:]
            del l[j-1]
            p = procedure[:]
            p.append(j)
            ret = dfs(N, l, i-1, p)
            if ret is not None:
                return ret
            break


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

    res = dfs(N, b, N, [])
    if res is None:
        print(-1)
    else:
        print(*res[::-1], sep="\n")


if __name__ == "__main__":
    main()

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

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

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

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

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

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

ans = []

count = 0

while len(ball)>0:
    count += 1
    for i in range(len(ball)-1,-1,-1):
        
        if i+1 ==ball[i]:
            move = ball.pop(i)
            ans.insert(0,move)
            break
    if count ==100000:
        break
    

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

Solution (Python):
from collections import deque

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

op=[0]*N

for i in range(N-1,-1,-1):
    for j in range(len(b)-1,-1,-1):
        if b[j]==j+1:
            op[i]=j+1
            break
    
    if op[i]==0:
        print(-1)
        exit(0)

    b=[b[i] for i in range(op[i]-1)]+[b[i] for i in range(op[i],len(b))]

for op1 in op:
    print(op1)

Solution (Python):

import sys

def main():
    N = int(input())
    b = list(map(int, input().split()))
    ans = []
    for i in range(N):
        pos = 0
        for j in range(N-i):
            tmp = j+1 - b[j]
            if tmp < 0:
                print(-1)
                exit()
            elif tmp == 0:
                pos = j
        ans.append(b.pop(pos))
    for a in ans[::-1]:
        print(a)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
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]:
                res.append(B[j])
                B.pop(j)
                break
        else:
            print(-1)
            exit()

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


if __name__ == '__main__':
    resolve()

Solution (Python):
from _collections import deque
n=int(input())
B=list(map(int,input().split()))
ANS=deque([])
cnt=0
while len(B)>0 and cnt<10**5:
    for i in reversed(range(len(B))):
        if i+1==B[i]:
            B=B[:i]+B[i+1:]
            ANS.appendleft(i+1)
            break
    cnt+=1
if len(B)==0:
    for a in ANS:
        print(a)
else:
    print(-1)

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

result =[]
while len(a) > 0:
    ok = False
    for i in range(len(a)-1, -1, -1):
        if i+1 == a[i]:
            result.append(a[i])
            a.pop(i)
            ok = True
            break
    if not ok:
        result = [-1]
        break
for i in result[::-1]: print(i)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
L = [0 for _ in range(N)]
flg = True
for i in range(N):
  cnt = -1
  for j in range(N-i, 0, -1):
    if j == A[j-1]:
      cnt = j
      break
  if cnt == -1:
    flg = False
    break
  else:
    L[N-i-1] = cnt
    for j in range(cnt, N-i):
      A[j-1] = A[j]
if flg:
  for i in range(N):
    print(L[i])
else:
  print(-1)

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

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

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

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

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

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

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

Solution (Python):
def solve(remains, nums):
    if (len(remains)) == 0:
        [print(num) for num in nums[::-1]]
        exit()
    n_remain = None
    n_num = None
    for i, num in enumerate(remains):
        if i + 1 == num:
            n_remain = remains[:i] + remains[i + 1:]
            n_num = nums + [i + 1]
    if n_remain is None:
        return False
    solve(n_remain, n_num)


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

solve(B, [])
print(-1)

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

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

ans = []
fault = False
for _ in range(N):
    for cursol in range(len(b) - 1, -1, -1):
        if b[cursol] == cursol + 1:
            ans.append(b.pop(cursol))
            break
    else:
        fault = True
if fault:
    print(-1)
else:
    ans.reverse()
    for el in ans:
        print(el)

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:
            del(b[i])
            ans.append(i+1)
            break
    else:
        if b:
            print(-1)
            exit()

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

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

Solution (Python):
INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque
from math import factorial

def main():
    n = int(input())
    B = list(map(int,input().split()))
    flag = True
    ans = []
    for i in range(n):
        idx = -1
        for j in range(n - i):
            if B[j] == j + 1:
                idx = j
        if idx == -1:
            flag = False
            break
        ans.append(idx + 1)
        B = B[:idx] + B[idx + 1:]

        if not flag:
            break
    
    print('\n'.join(map(str,ans[::-1])) if flag else -1)
if __name__=='__main__':
    main()

Solution (Python):
from collections import deque
n=int(input())
b=list(map(int,input().split()))
a=[]
while b:
    maxpoint=0
    for i in range(len(b)):
        if i+1==b[i]:
            maxpoint=max(maxpoint, i+1)
    if maxpoint==0:
        print(-1)
        exit()
    else:
        a.append(maxpoint)
        b=b[:maxpoint-1]+b[maxpoint:]

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

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

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

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

Solution (Python):
import sys

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


def solve():
    N = int(rl())
    b = list(map(int, rl().split()))
    
    ans = []
    for _ in range(N):
        j = -1
        for i in range(len(b)):
            if b[i] == i + 1:
                j = i
        if j == -1:
            print(-1)
            exit()
        del b[j]
        ans.append(j + 1)
    ans.reverse()
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()

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

Solution (Python):
N,*B = map(int, open(0).read().split())
ans = [0]*N
for i in range(N):
  for j in range(len(B)-1,-1,-1):
    if B[j]==j+1:
      ans[N-1-i] = j+1
      B = B[:j]+B[j+1:]
      break
if B==[]:
  print('\n'.join(map(str,ans)))
else:
  print(-1)

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

ans = []

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

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

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

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
num=[]
for i in range(n):
    num.append([b[i],0]) 
flag=True
ans=[]
remove=0 
remove_sum=[0]*n
while flag and remove<=n-1:
    remove_ind=-1
    for i in range(n):
        if num[i][1]==0:
            if i-remove_sum[i]==num[i][0]-1:
                remove_ind=i
    if remove_ind!=-1:
        num[remove_ind][1]=1
        remove+=1
        ans.append(num[remove_ind][0])
        for j in range(remove_ind+1,n):
            remove_sum[j]+=1
    else: 
        flag=False
if flag:
    ans=ans[::-1]
    for i in range(n):
        print(ans[i])
else:
    print(-1)

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

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

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
ans=[]
flg=True
while len(b)>0 and flg:
  n1=len(b)
  i=n1
  flg=False
  while i > 0:
    if b[i-1]==i:
      ans.append(b[i-1])
      b1=b[:i-1]
      b1[len(b1):len(b1)]=b[i:]
      b=b1
      i=-1
      flg=True
    else:
      i-=1

if flg==False:
  print(-1)
  
  exit()
for _ in range(n):
  print(ans.pop())

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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.pop(i))
            break

    else:
        print(-1)
        exit()

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

Solution (Python):

def solve():
    N = int(input())
    b = list(map(int, input().split()))
    del_list = []

    while True:
        del_index = -1
        for k in range(len(b)):
            if b[k] == k + 1:
                del_index = max(del_index, k)
        if del_index < 0:
            break
        else:
            del_list.append(b[del_index])
            b.pop(del_index)

    if len(b) > 0:
        print(-1)
    else:
        for key in del_list[::-1]:
            print(key)

solve()

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

res = []
while len(B) > 0:
    idx = -1
    for i in range(len(B) - 1, -1, -1):
        if i + 1 == B[i]:
            idx = i
            break
    if idx == -1:
        print(-1)
        exit(0)
    else:
        res.append(B[idx])
        tmp = []
        for i, b in enumerate(B):
            if i != idx:
                tmp.append(b)
        B = tmp

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

Solution (Python):
n = int(input())
b =input().split()
ans = []
while len(b) > 0:
    ng = True
    
    for i in range(len(b)-1,-1,-1):
        if b[i] == str(i+1):
            ans.append(i+1)
            b = b[:i]+b[i+1:]
            
            
            ng = False
            break
    if ng:
        print(-1)
        exit(0)
if len(ans) == 0:
    print(-1)
else:
    ans = ans[::-1]
    print(*ans)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    ans = []
    while len(v) > 0:
        flag = False
        for j in reversed(range(len(v))):
            
            if j+1 == v[j]:
                ans.append(v[j])
                del v[j]
                flag = True
                break
        if not flag:
            print(-1)
            return
    for c in reversed(ans):
        print(c)

if __name__ == '__main__':
    main()

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

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



def solve(N,B):
    ans = []
    for _ in range(N):
        m = max(B)
        if m > len(B):
            return [-1]
        for i in range(m,0,-1):
            if B[i-1]==i:
                B.pop(i-1)
                ans.append(i)
                break
        else:
            return [-1]
    return ans
ans = solve(N,B)

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

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = []
index = 0
count = 0
while count <= 10000 and len(b) > 0:
    index = len(b) - 1
    while index >= 0:
        if index + 1 == b[index]:
            ans.append(b[index])
            del b[index]
            index = len(b) - 1
            continue
        index -= 1
        count += 1
if len(ans) == n:
    ans.reverse()
    for i in range(n):
        print(ans[i])
else:
    print(-1)

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

if __name__ == "__main__":
    main()

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    b = list(map(int, input().split()))
    ans = []
    for i in range(n):
        if (i + 1) < b[i]:
            print(-1)
            exit(0)
    for i in range(n):
        for j in range(len(b) - 1, -1, -1):
            if b[j] == (j + 1):
                ans.append(b[j])
                del b[j]
                break
        if len(b) != (n - i - 1):
            print(-1)
            exit(0)
    ans.reverse()
    for i in ans:
        print(i)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]



def main():
    N = ii()
    B = li()

    '''
    flag = [0]*N
    l = N
    i = ind = N-1
    while True:
        if S[ind] == i:
            flag[ind] = 0

        while flag[i]:
            i -= 1
        ind = i
    '''
    ans = []
    for i in range(N):
        flag = 1
        for j in reversed(range(N-i)):
            if B[j] == j+1:
                a = B.pop(j)
                ans.append(a)
                flag = 0
                break
        if flag:
            print('-1')
            exit()

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

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
*l, = map(int, input().split())

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

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

for i in range(N):
  c = len(b)
  for j in range(c):
    if b[c-j-1]==c-j:
      d.append(b.pop(c-j-1))
      break
      
if b==[]:
  for num in d[::-1]:
    print(num)
else:
  print(-1)

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

ans = []
flg = True
for x in range(n):
    memo = -1
    for i in range(len(b)):
        if b[i] == i+1:
            memo = i
    if memo == -1:
        flg = False
        break
    ans.append(memo+1)
    b.pop(memo)

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

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

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

    ans.reverse()
    for a in ans:
        print(a)


main()

Solution (Python):
from collections import deque
N = int(input())
b = [int(x) - 1 for x in input().split()]
d = deque()
while b:
  popped = -1
  for i in range(len(b))[::-1]:
    if b[i] == i:
      d.appendleft(i + 1)
      popped = b.pop(i)
      break
  if popped == -1:
    print(-1)
    exit()
print(*d, sep="\n")

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    
    N = int(input())
    b_list = [int(item) for item in input().split()]
    a = collections.deque()

    is_True = True

    while is_True:
        stack = collections.deque()
        for i in range(len(b_list)):
            if i+1 == b_list[i]:
                
                stack.append(b_list[i])
                
        if len(stack) == 0:
            is_True = False
            a = [-1]
        else:
            temp = stack.pop()
            a.append(temp)
            del b_list[temp-1]
            

        if len(b_list) == 0:
            is_True = False

    for i in reversed(a):
        print(i)
if __name__ == "__main__":
    resolve()

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

ans=[]
while q:
    n=len(q)
    for i in range(0,n):
        if q[n-i-1]==n-i:
            ans.append(n-i)
            if i==0:
                q=q[:n-1]
                break
            else:
                q=q[:n-i-1]+q[n-i:]
                break
    else:
        print(-1)
        break
else:
    for i in range(0,N):
        print(ans[-i-1])

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
ans = []
for m in range(n-1,-1,-1):
    for i in range(m,-1,-1):
        if b[i] == i+1:
            ans.append(i+1)
            del b[i]
            break
if b:
    print(-1)
else:
    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(N-i):
        if b[N-i-j-1] == N-i-j:
            res.append(N-i-j)
            b = b[:N-i-j-1] + b[N-i-j:]
            break
    else:
        print(-1)
        exit()
print(*res[::-1], sep = '\n')

Solution (Python):
N = int(input())
nums = list(map(int,input().split()))
ans = []
for _ in range(N):
    ma = -1
    ma_ind = -1
    l = len(nums)

    for i in range(l):
        if nums[i] == i + 1:
            ma_ind = i
    if ma_ind == -1:
        print(-1)
        exit(0)
    temp = nums.pop(ma_ind)
    ans.append(temp)
ans.reverse()
print("\n".join(map(str,ans)))

Solution (Python):
from collections import deque
N=int(input())
b=list(map(int,input().split()))
flag=0
op=deque()


while len(b)>0:
    for i in range(len(b)-1,-1,-1):
        if b[i]==i+1:
            
            op.appendleft(b.pop(i))
            flag=1
            break
    if flag==0:
        break
    flag=0
    

if len(b)==0:
    for i in range(N):
        print(op.popleft())
else:
    print("-1")

Solution (Python):
import sys

n = int(sys.stdin.readline())
b = list(map(int, sys.stdin.readline().split()))
ans = []

for i in range(n):
    temp = 0
    for j in range(len(b)):
        if j+1 == b[j]:
            temp = max(temp, b[j])
    if temp == 0:
        ans = [-1]
        break
    ans.insert(0, temp)
    b.pop(temp-1)

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

Solution (Python):
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  b = input_list()
  sb = list(sorted(list(set(b)), reverse=True))
  a = []
  def get(sb, b):
    for x in sb:
      if x > len(b):
        continue
      if b[x-1] == x:
        return x-1
    return -1
  for i in range(n):
    index = get(sb, b)
    if index == -1:
      print(-1)
      exit(0)
    a.append(b[index])
    del b[index]
  
  for v in a[::-1]:
    print(v)
      
  
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(n):
    f = True
    for j in range(len(A)):
        if A[len(A)-1-j] == len(A)-j:
            f = False
            B.append(len(A)-j)
            del A[len(A)-j-1]
            break
    if f: break
if len(A) > 0:print(-1)
else: print(*B[::-1], sep="\n")

Solution (Python):
N = int(input())
arr = list(map(int,input().split()))
ans = []
for i in arr:
    if len(ans) >= i - 1:
        ans.insert(i-1,i)
    else:
        print(-1)
        exit()
for i in ans:
    print(i)