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 = [int(x) - 1 for x in input().split()]

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

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

Solution (Python):
import sys


n = int(input())
b = list(map(int, input().split()))
ope = []
i = n
while i > 0:
    flag = 0
    j = i
    while j > 0:
        if b[j - 1] == j:
            b.pop(j - 1)
            i -= 1
            ope.insert(0, j)
            flag = 1
            break
        j -= 1
    if flag == 0:
        print(-1)
        sys.exit()
for i in ope:
    print(i)

Solution (Python):




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

    ans = [-1] * N
    for i in range(N):
        cur = -1
        for j in range(len(B)):
            if B[j] == j + 1:
                cur = B[j]

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

        ans[N-i-1] = cur
        B.pop(cur-1)

    for i in ans:
        print(i)


if __name__ == '__main__':
    main()

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

result = []
for i in range(len(b)):
    for j in reversed(list(range(len(b)))):
        if b[j] == j + 1:
            result.append(b.pop(j))
            break
if len(b) != 0:
    print(-1)
    exit(0)

for result_i in reversed(result):
    print(result_i)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)



'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  
print(sorted(a, key=itemgetter(0)))  
print(sorted(a, key=itemgetter(0, 2)))  
print(sorted(a, key=lambda x: x[0] * x[2]))  
print(sorted(a, reverse=True))  
a.sort()  
try: 
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
3
1 2 1
'''

test_data2 = '''\
2 3 0
4 5 6
7 8 9
-1 2 -5
'''

test_data3 = '''\
9
1 1 1 2 2 1 2 3 2
'''
td_num=3

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        
        n=int(f.readline())
        b=list(map(int,f.readline().split()))
        
else:
    for i in range(1):
        
        n=int(input())
        b=list(map(int,input().split()))
        

ans=[]

cnt=0
while cnt<100 and len(b)>0:
    m=len(b)
    cnt+=1
    flg=False
    for i in range(m):
        
        if b[m-1-i]==m-i:
            ans.append(b.pop(m-1-i))
            
            flg=True
            break
    if flg==False:
        break
if len(ans)==n:
    for i in range(n):
        print(ans[-i-1])
else:
    print(-1)

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

while(1):
    count = len(b)
    if(count == 0):
        break
    for i in reversed(range(count)):
        if(b[i] == i + 1):
            a.append(b.pop(i))
            answer_flag = 1
            break
    if(answer_flag):
        answer_flag = 0
        continue
    flag = 1
    break

if(flag == 1):
    print('-1')
else:
    for i in reversed(range(N)):
        print(a[i])

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

for i in range(n, 0, -1):
    for j in range(i, 0, -1):
        if B[j-1] == j:
            A.append(j)
            del B[j-1]
            break
    else:
        print(-1)
        break
else:
    A = A[::-1]
    for i in range(n):
        print(A[i])

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

result = []
for bi in B:
    if bi - 1 > len(result):
        print(-1)
        quit()
    result.insert(bi - 1, bi)

for ri in result:
    print(ri)

Solution (Python):
def find(sequence):
    result_list = []
    for i in range(len(sequence)):
        for j in reversed(list(range(len(sequence)))):
            if sequence[j] == j + 1:
                result_list.append(sequence.pop(j))
                break
    if len(sequence) != 0:
        return [-1]
    return result_list


if __name__ == "__main__":
    n = input()
    sequence = input()
    data = [int(item) for item in sequence.split(" ")]
    print("\n".join(map(str, reversed(find(data)))))

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

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

res = [-1]*n

ind = [i for i in range(1,n+1)]

cnt = 0
while cnt != n:
    
    judge = False
    for i in range(n-1,-1,-1):
        if ind[i] == b[i]:
            ind[i] = -1
            res[n-1-cnt] = b[i]
            cnt += 1
            judge = True
            break
        else:
            ind[i] -= 1
    if not judge:
        print(-1)
        exit()
for e in res:
    print(e)

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


inv_output = list()
for i in range(N, 0, -1):
  for j in range(i, 0, -1):
    if B[j - 1] == j:
      inv_output.append(B.pop(j - 1))
      break
  else:
    print(-1)
    break
else:
  for i in inv_output[::-1]:
    print(i)

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

a = []
n = N
while len(b):
    index = -1
    for i in range(n):
        if i+1 == b[i]:
            index = i
    if index > -1:
        a.insert(0, b.pop(index))
        n -= 1
    elif index == -1:
        print(index)
        quit()

for e in a:
    print(e)

Solution (Python):
"""
A - Limited Insertion
"""
import numpy as np

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







def make_idx(tmp_list):
    return np.arange(1, len(tmp_list)+1, 1)[::-1]

b_list = b_list[::-1]
idx_list = make_idx(b_list)
rm_list = []

while len(b_list):
    for idx, b in zip(idx_list, b_list):
        if idx==b:
            b_list = b_list[::-1]
            b_list.remove(b)
            rm_list.append(b)
            b_list = b_list[::-1]
            break
        elif idx-b<0:
            print(-1)
            exit()
    idx_list = make_idx(b_list)
    
for r in rm_list[::-1]:
    print(r)

Solution (Python):
import sys
sys.setrecursionlimit(10**5)

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

Solution (Python):
def find(A):
    stack=[]
    while A:
        
        index=-1
        for i in range(len(A)):
            if A[i]==i+1:
                index=i
        
        if index!=-1:
            
            stack+=[index+1]
            A=A[:index]+A[index+1:]
        else:
            return -1
    return stack   
        
        
N=int(input())
A=list(map(int,input().strip().split(' ')))

temp=find(A)

if temp==-1:
    print(temp)
    
else:
    while temp:
        print(temp.pop())

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

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

Solution (Python):


IS = lambda: int(input())
IA = lambda: [int(x) for x in input().split()]

N = IS()
B = IA()

def f(b, n):
    ans = []
    while b:
        for i in range(len(b), 0, -1):
            j = i - 1
            if i == b[j]:
                ans.append(i)
                b = b[:j] + b[j+1:]
                break
        else:
            return None
    return list(reversed(ans))

ans = f(B, N)
if ans:
    print(*ans, sep="\n")
else:
    print(-1)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    n = II()
    b = LI()
    b = b[::-1]
    ans = deque([])
    while len(b) != 0:
        for num, i in enumerate(b):
            if n - num == i:
                ans.appendleft(i)
                n -= 1
                del b[num]
                break
        else:
            print(-1)
            return
    for i in ans:
        print(i)
    return


def B():
    return


def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    A()

Solution (Python):
input();a=['']
for i in input().split():a.insert(int(i)-1,i)
print(*a[-1]and[-1]or a)

Solution (Python):
input();a=[""]
for i in input().split():a.insert(int(i)-1,i)
print(*[-1]if a[-1]else a)

Solution (Python):

n = int(input())
a = []
b = list(map(int, input().split()))
flag = True
for _ in range(n):
    add = 0
    for j in range(1, len(b)+1):
        if j == b[j-1]:
            add = max(add, j)
    if add == 0:
        flag = False
        break
    a.append(add)
    del b[add-1]
if flag:
    for i in range(len(a)):
        print(a[-i-1])
else:
    print(-1)

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

b.reverse()
ans = []
while b:
    check = 0

    tmp = 0
    for i in b:
        if i == len(b) - tmp:
            ans.append(b.pop(tmp))
            check = 1
            break

        tmp += 1

    if check == 0:
        check = 2
        break


if check == 2:
    print(-1)
else:
    ans.reverse()
    for i in ans:
        print(i)

Solution (Python):
N=int(input())
b=[int(i) for i in input().split()]
A=True
a=[]
for _ in range(N):
  ans=0
  for j in range(len(b)):
    if j+1==b[j]:
      ans=max(ans,j+1)
  if ans==0:
    A=False
    break
  a.append(ans)
  del b[ans-1]
    
a=a[::-1]
if A:
  for i in a:
    print(i)
else:
  print(-1)

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
flag = True
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:
        flag = False
        break
if flag:
    for i in range(N-1, -1, -1):
        print(ans[i])
else:
    print(-1)

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

ans = []
while len(ans) < n:
  pop_i = -1
  for i in range(len(b)):
    if b[i] == i+1:
      pop_i = i
  if pop_i >= 0:
    b.pop(pop_i)
    ans.append(pop_i+1)
  else:
    print(-1)
    break
else:
  for i in range(n)[::-1]:
    print(ans[i])

Solution (Python):
a=[0]*int(input())
for i in input().split():a.insert(int(i)-1,i);a.pop()
print(*[a,[-1]][0in a])

Solution (Python):
import copy
N = int(input())
A = list(map(int, input().split()))
B = []
for _ in range(N):
    cand = []
    for i, a in enumerate(A):
        if a == i + 1:
            cand.append(i)
    if len(cand) > 0:
        ind = cand[-1]
        B.append(A[ind])
        del(A[ind])
    else:
        print(-1)
        exit()
if len(B) < N:
    print(-1)
else:
    B.reverse()
    for b in B:
        print(b)

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

ans = []

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

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

Solution (Python):
n,*a=map(int,open(0).read().split());b=[0]*n
for i in a:b.insert(i-1,i)
print(*[b[:n],[-1]][0in b[:n]])

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

for j in range(n):
    for i in range(len(b), 0, -1):
        try:
            if b[i-1] == i:
                b.pop(i-1)
                ans.append(i)
                break
        except: pass 
            
if len(b) == 0:
    [print(ans[-i-1]) for i in range(n)]
else:
    print(-1)

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

Solution (Python):
n,*a=map(int,open(0).read().split());b=[0]*n
for i in a:b.insert(i-1,i)
print(*[[-1],b[:n]][sum(a)==sum(b[:n])])

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
s=[]
flag=1
while len(l)!=0:
    flag=0
    for i in range(len(l),0,-1):
        if i==l[i-1]:
            p=l[i-1]
            s.append(p)
            l.pop(i-1)
            flag=1
            break
    if flag==0:
        ans=-1
        break

if flag==1:
    ans=reversed(s)
    ans=list(ans)
    for i in ans:
        print(i)
else:
    print(ans)

Solution (Python):
INF = 999999999999999999L
EPS = 1e-12

def read():
    return raw_input().strip()

def read_ints():
    return map(int,read().split())

n = int(read())
arr = read_ints()

ans = []

while len(arr) > 0:
    remove = -1 
    for i in range(len(arr)):
        if arr[i] == i+1:
            remove = i 
            
    if remove == -1:
        break 
        
    ans.append(arr[remove])
    del arr[remove]
    
if len(ans) == n:
    for x in reversed(ans):
        print x 
else:
    print -1

Solution (Python):
n,*a=map(int,open(0).read().split());b=[0]*n
for i in a:b.insert(i-1,i)
print(*[[-1],b[:n]][sum(a)==sum(b[:n])],sep='\n')

Solution (Python):
from collections import deque

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











ans = deque()

q = deque(enumerate(b, 1))
r = deque()

flg = False
while q:
    idx, bb = q.pop()
    
    if idx == bb:
        ans.appendleft(bb)
        if len(ans) == N:
            flg = True
            break
        q.extend(r)
        r = deque()
    else:
        r.appendleft((idx - 1, bb))

if flg:
    for aa in ans:
        print(aa)
else:
    print(-1)

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

result = []
for i in range(N):
    for j in range(N - i - 1, -1, -1):
        if j + 1 == B[j]:
            result.insert(0, B.pop(j))
            break
    else:
        print(-1)
        quit()

for ri in result:
    print(ri)

Solution (Python):
n,*b=map(int,open(0).read().split());a=[]
while b:j=max(i*(i==v)for i,v in enumerate(b,1));b.pop(j-1);a=j<1and[-1]or[j]+a
print(*a)

Solution (Python):
n,*b=map(int,open(0).read().split());a=[]
while b:j=max(i*(i==v)for i,v in enumerate(b,1));b.pop(j-1);a=j<1and[-1]or a+[j]
print(*a[::-1])

Solution (Python):
import copy
N=int(input())
b=[int(i) for i in input().split()]
 
c = copy.copy(b) 
a = [0]*N
a_n = N-1
 
for n in range(N)[::-1]:
  for i in range(len(c))[::-1]:
    if c[i]==i+1:
      a[a_n] = c.pop(i)
      
      a_n = a_n-1
      break
 
if n-1 != a_n:
  print(-1)
  exit()
else:
  for i in range(N):
    print(a[i])

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



can_make = True
com_list = []
while len(b) > 0 :
    insert_list = []
    for i in range(len(b)):
        if b[i] == i+1:
            insert_list.append(i)
    if not insert_list:
        can_make = False
        break
    com_list.append(b[insert_list[-1]])
    del b[insert_list[-1]]

if can_make:
    for x in reversed(com_list):
        print(x)
else:
    print(-1)

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

Solution (Python):
n,*b=map(int,open(0).read().split())
a=[]
while b:
  j=max(i*(i==v)for i,v in enumerate(b,1))
  b.pop(j-1)
  a+=[j]
  if j<1:a=[-1]
print(*a[::-1])

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

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

Solution (Python):
N = int(input())
b = [int(i) for i in input().split()]
ans = []
for i in range(len(b)):
    removed = False
    for j in reversed(range(len(b))):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            removed = True
            break
    if not removed:
        print(-1)
        exit()
print('\n'.join(map(str, reversed(ans))))

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

while i <= len(b):
    test = b[-i]
    if test == len(b)-i+1:
        b.pop(-i)
        ans.append(test)
        i = 1
        continue
    elif i == len(b):
        print(-1)
        exit()
    else:
        i += 1

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

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

a = []
i = len(b) - 1
while(i >= 0):
    if(i + 1 == b[i]):
        pick = b[i]
        b.remove(pick)
        a = [pick] + a
        i = len(b)
    i -= 1

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
l=[]
while len(x):
    index=-1
    for i,a in enumerate(x):
        if a==i+1:
            index=i
    if index == -1:
        print(-1)
        break
    l.append(x.pop(index))
else:
    for i in reversed(l):
        print(i)

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

l = []
count = 0

for j in range(n):
    for i in reversed(range(len(b))):
        if b[i] == i+1:
            l.append(b.pop(i))
            count += 1
            break
if count != n:
    print(-1)
else:
    for i in reversed(range(n)):
        print(l[i])

Solution (Python):
n,*b=map(int,open(0).read().split())
a=[]
while b:
  j=max(i*(i==v)for i,v in enumerate(b,1))
  if j:
    b=b[:j-1]+b[j:]
    a+=[j]
  else:
    a=[-1]
    break
print(*a[::-1])

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

a=[]
while len(b) > 0:
    filtered = [i for i in range(len(b)) if i == b[i] - 1]
    if len(filtered) == 0:
        print(-1)
        exit(0)
    j = filtered[-1]
    a.append(b[j])
    del b[j]

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

Solution (Python):
N = int(input())
list_b = list(map(int, input().split()))
ans = [0 for i in range(N)]

finish = False

for i in range(N-1, -1, -1):
  mx = -1
  for k in range(i+1):
    if list_b[k] == k+1:
      mx = max(mx, k+1)
  if mx == -1:
    finish = True
    break
  else:
    ans[i] = mx
    for j in range(mx-1, i):
      list_b[j] = list_b[j+1]
    
if not finish:
    for i in range(N):
        print(ans[i])
else:
    print(-1)

Solution (Python):
from queue import deque

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

res = True
for i, v in enumerate(b):
	if i + 1 < v:
		res = False
		break

if res:
	l = list(b)
	ans = []
	while l:
		for i in range(len(l), 0, -1):
			if i == l[i-1]:
				ans.append(i)
				del l[i-1]
				break
	for v in reversed(ans):
		print(v)
else:
	print(-1)

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def dfs(A, already_use, value_list, vi):
    li = []
    for i in range(len(A)):
        if already_use[i] == True:
            break
        if A[i] == value_list[vi] :
            li.append(i)
    for i in range(len(li) - 1, -1, -1):
        print value_list[vi]
        already_use[li[i]] = True
        dfs(A[li[i] + 1:],  already_use[li[i] + 1:], value_list, vi + 1)

def dfs(A, x):
    li = []
    for i in range(len(A)):
        if already_use[i] == True:
            break
        if A[i] == value_list[vi] :
            li.append(i)
    for i in range(len(li) - 1, -1, -1):
        print value_list[vi]
        already_use[li[i]] = True
        dfs(A[li[i] + 1:],  already_use[li[i] + 1:], value_list, vi + 1)


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]

    ans = []
    already_use = [False for i in range(N)]
    while 1:
        if len(A) <= 0:
            break
        is_NG = True
        for i in range(len(A) - 1, -1, -1):
            if A[i] == i + 1:
                is_NG = False
                ans.append(A[i])
                del A[i]
                break
        if is_NG == True:
            print -1
            return
    for i in range(len(ans)-1, -1, -1):
        print ans[i]




if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

if __name__ == '__main__':
    n = int(input())
    b = [-1] + [int(s) for s in input().split()]
    ans = deque()
    for _ in range(n):
        flag = False
        for i in range(len(b) - 1, 0, -1):
            if b[i] == i:
                b.pop(i)
                ans.appendleft(i)
                flag = True
                break
        if flag == False:
            print(-1)
            quit(0)
    for x in ans:
        print(x)

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

b.reverse()
ans = []
disable = False

for i in range(N):
  for j in range(len(b)):
    if b[j] == len(b) - j:
      ans.append(b.pop(j))
      break
    if j == len(b) - 1:
      disable = True
      ans = [-1]
      break
  if disable:
    break

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

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


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


log = []
while b:
    delit = delitable(b)
    if not delit:
        print(-1)
        break
    del b[delit[-1] - 1]
    log.append(delit[-1])
else:
    log.reverse()
    print("\n".join(map(str, log)))

Solution (Python):
n,*b=map(int,open(0).read().split())
a=[]
while n:
  j=-1
  for i in range(n):
    if b[i]==i+1:
      j=i
  if j+1:
    b=b[:j]+b[j+1:]
    a+=[j+1]
  else:
    a=[-1]
    break
  n-=1
print(*a[::-1])

Solution (Python):
n,*b=map(int,open(0).read().split())
a=[]
while n:
  j=-1
  for i in range(n):
    if b[i]==i+1:
      j=i
  if j+1:
    b=b[:j]+b[j+1:]
    a+=[j+1]
  else:
    a=[-1]
    break
  n-=1
print(*a[::-1])

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

Solution (Python):
import sys

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

ok = 1
for i in range(N):
    if B[i] > i+1:
        ok = 0
if not ok:
    print(-1)
    exit(0)

ans = []
S = [0]*N
for i in range(N):
    rest = i
    for j in range(N-1, -1, -1):
        if S[j] == 1:
            rest -= 1
            continue
        if rest+1 == B[j]:
            ans.append("%d\n" % B[j])
            S[j] = 1
            break
sys.stdout.writelines(ans)

Solution (Python):




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

for idx6 in range(n):
    maxidx = -1
    for idx7 in range(len(b)):
        if b[idx7] == idx7 + 1:
            maxidx = idx7
    
    if maxidx >= 0:
        anslist.append(b.pop(maxidx))
    else:
        ngflg = True

    if ngflg:
        print(-1)
        break

if ngflg == False:
    for idx4 in range(n-1, -1, -1):
        print(anslist[idx4])

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

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

L.reverse()

if len(B)==0:
	for x in L:
		print x
else:
	print -1

Solution (Python):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())



def sol():
    n = int_raw()
    bs = ints_raw()
    ans =[]
    buf = list(bs)
    l = len(buf)
    while l!=0:
        
        old_l = l
        for i in xrange(l,0,-1):
            b = buf[i-1]
            if b == i:
                ans.append(buf.pop(i-1))
                l = len(buf)
                break
        if old_l == l:            
            print -1
            return -1
    for a in reversed(ans):
        print a

sol()

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

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
L=[]
c=0
for j in range(n):
  for i in range(len(l)-1,-1,-1):
    if l[i]==i+1:
      L.insert(0,l.pop(i))
      c+=1
      break
if c!=n:
  print(-1)
else:
  for k in range(len(L)):
    print(L[k])

Solution (Python):
N = int(input())
B = [int(b) for b in input().split()]
lenB = len(B)
Ans = [None] * N
while lenB > 0:
    for i in reversed(range(lenB)):
        if i+1 == B[i]:
            Ans[lenB-1] = B[i]
            del B[i]
            lenB -= 1
            break
    else:
        print(-1)
        break
else:
    for a in Ans:
        print(a)

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    bs = list(map(int, input().split()))

    operations = []
    for i in range(N):
        j_remove = -1
        for j in range(N-i):
            if bs[j] == j+1:
                j_remove = j
        if j_remove == -1:
            print("-1")
            exit()
        operations.append(bs.pop(j_remove))
    for n in reversed(operations):
        print(n)

Solution (Python):
N=int(input())
b=[int(i) for i in input().split()]
ans=[0]*N
for i in range(N)[::-1]:
  for k in range(i+1)[::-1]:
    if b[k]==k+1:
      ans[i]=b[k]
      break
    if k==0:
      print(-1)
      exit()
  b.pop(k)
for i in ans:
  print(i)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

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

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