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



Sample input:
3
1 2 1


Sample output:
1
1
2

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n)]

def f(a,b,n):
     for i in range(n):
          flag = True
          for j in range(n-i-1,-1,-1):
               if a[j] == j+1:
                    a = a[:j]+a[j+1:]
                    b[n-i-1] = j+1
                    flag = False
                    break
          if flag:
               print("-1")
               return
     for i in range(n):
          print(b[i])
     return
     
f(a,b,n)

Submission status: Accepted

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

ans = []
while(b):
    position = -1
    for i,x in enumerate(b):
        order = i + 1
        if order == x:
            position = i
    if position == -1:
        print(-1)
        exit()
    ans.append(b.pop(position))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
b_list = _li()

ans = []
for i in range(N, 0, -1):
    cand = []
    for j in range(i):
        if b_list[j] == (j+1):
            cand.append(j)
    if len(cand) == 0:
        print(-1)
        exit()
    else:
        a = b_list.pop(cand[-1])
        ans.append(a)

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()] 
a = []
for i in range(n):
    for j in range(len(b), 0, -1):
        if b[j-1] == j:
            del b[j-1]
            a.append(str(j))
            break
if len(a) != n:
    print(-1)
else:
    print("\n".join(list(reversed(a))))

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int, input().split()))
ans = []
cnt = 0
while cnt <= N:
	for j in range(len(b) - 1, -1, -1):
		if b[j] == j + 1:
			ans.append(j + 1)
			del b[j]
			break
	cnt += 1
if len(b) == 0:
	for k in range(N):
		print(ans[N - k - 1])
else:
	print(-1)

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print(ans[len(ans) - i - 1])
        exit()
    for i in range(len(a) - 1, -1, -1):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])
            break


f(b, [])
print(-1)

Submission status: Accepted

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

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

if noanswer==0:
  for i in range(len(a)-1,-1,-1):
    print(a[i])

Submission status: Accepted

Solution code:
n=int(input())
B=[int(i) for i in input().split()]
Ans=[]
for i in range(n-1):
  N=[j+1 for j in range(n-i)]
  b=-1
  for k in range(n-i):
    if B[k]==N[k]:
      b=k
  if b==-1:
    break
  else:
    Ans.append(b+1)
    B=B[:b]+B[b+1:]
if B!=[1]:
  print(-1)
else:
  print(*([1]+Ans[::-1]),sep="\n")

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.reverse()
ans_set = [0]*n
ans = 0

for i in range(n):
    if ans == -1:
        break
    
    for j in range(n):
        if b[j] == n-j:
            ans = b.pop(j)
            ans_set[n-1] = ans
            n -= 1
            break
            
        elif b[j] > n-j:
            ans = -1
            print(ans)
            break

        if n == 0:
            break

if ans != -1:
    for k in ans_set:
        print(k)

Submission status: Accepted

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    A = [0] * N
    B = list(map(int,input().split()))
    for n in range(N-1,-1,-1):
        i = n
        while(1):
            if B[i] == i+1:
                A[n] = B.pop(i)
                break
            i -= 1
            if i < 0:
                print(-1)
                sys.exit()
    for a in A:
        print(a)

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int, input().split()))
ans = []
l = []
k = 0

for j in range(N):
    for i in range(len(b)):
        if b[i] == i+1:
            l.append(i)
    if len(l) == 0:
        k += 1
        break
    ans.append(b[max(l)])
    del b[max(l)]
    l = []
if k > 0:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
ans = []
tmp = 0
while len(b) != tmp and len(b) > 0:
    tmp = len(b)
    for i in reversed(range(len(b))):
        if b[i] == i+1:
            b.pop(i)
            ans.append(i+1)
            break

if len(b) > 0:
    print(-1)
else:
    for x in reversed(ans):
        print(x)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
# import math
import fractions as math
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])
B = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
def check(b,n):
  # print(b,n)
  if n==0:
    return True
  for i in range(n-1,-1,-1):
    if b[i] == i+1:
      # print(i+1)
      b.pop(i)
      ans.append(i+1)
      return check(b,n-1)
  return False

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

Submission status: Accepted

Solution code:
# input
n = int(input())
bs_input = tuple(int(i) for i in input().split())


# imposibility check
# any integer's index > i
def valid(list_):
    return all(i >= l - 1 for i, l in enumerate(list_))


def can_remove(list_, i):
    # index and number doesn't match
    if list_[i - 1] != i:
        return False

    # doesn't affect validity by removing
    if not valid(list_[:(i - 1)] + list_[i:]):
        return False

    return True


def remove(list_, i):
    return list_[:(i - 1)] + list_[i:]

reconstruct = []

bs = list(bs_input)
for i in range(n):
    if not valid(bs):
        reconstruct = []
        break
    for j in range(n - i):
        if can_remove(bs, bs[j]):
            reconstruct.insert(0, bs[j])
            bs = remove(bs, bs[j])
            break


if reconstruct == [] or len(reconstruct) != n:
    print(-1)
else:
    print('\n'.join(str(i) for i in reconstruct))

Submission status: Accepted

Solution code:
import sys

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

ans = []

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

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().split()]

impossible = False
A = []
match = -1

for i in range(N):
    for j in range(len(B)):
        if B[j] == j + 1:
            match = j
    if match == -1:
        impossible = True
        break
    else:
        A.append(B.pop(match))
        match = -1

if impossible:
    print(-1)
else:
    for i in range(N):
        print(A.pop(-1))

Submission status: Accepted

Solution code:
n = int(input())
bs = list(map(int, input().split()))

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

Submission status: Accepted

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

if b[0] > 1:
    print(-1)

else:
    a = []

    while len(b)>0:
        n = len(b)
        br = True
        for i in range(n):
            if  n-i == b[n-1-i]:
                a.append(n-i)
                b.remove(n-i)
                br = False
                break
        if br:
            break

    if br:
        print(-1)
    else:
        for _ in range(len(a)):
            print(a.pop())

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
r = []
flag = True

for i in range(n-1, -1, -1):
  for j in range(i, -1, -1):
    if b[j] == (j + 1):
      r.append(b[j])
      del b[j]
      break
  else:
    flag = False
    break

if flag:
  r.reverse()
  for i in r:
    print(i)
else:
  print('-1')

Submission status: Accepted

Solution code:

def main():
    num = int(input())
    data = list(map(int, input().split()))
    max_num = max(data)

    ans_data = []

    while data != []:
        for i in range(max_num)[::-1]:
            if i >= len(data):
                continue
            if data[i] == i + 1:
                ans_data.append(i + 1)
                data.pop(i)
                break
        else:
            break

    if len(data) == 0:
        for ele in ans_data[::-1]:
            print(ele)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = []
for _ in range(n):
    for i, e in enumerate(reversed(b)):
        if e == len(b) - i:
            ans.append(b.pop(len(b) - i - 1))
            break
        else:
            continue

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

Submission status: Accepted

Solution code:
import sys

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    b = [int(i) for i in input().split()] 
  else:
    # b = [1,2,1]
    # b = [2,2]
    b = [1,1,1,2,2,1,2,3,2]
    N = len(b)

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

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

Submission status: Accepted

Solution code:
input = raw_input

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

done = []
for i in range(N):
    idx = -1
    for j in range(len(b)-1,-1,-1):
        if b[j] == j+1:
            idx = j
            break
    if idx == -1:
        print(-1)
        exit()
    done.append(b.pop(j))

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

Submission status: Accepted

Solution code:
N=int(input())
_b=list(map(int,input().split()))
ix=[]
while len(_b)!=0:
    pp=[i for i in range(len(_b)) if _b[i]==i+1][-1:]
    if len(pp)==0:
        print(-1)
        exit(0)
    p=pp[0]
    _b.pop(p)
    ix.append(p)
ix.reverse()
for i in ix:
    print(i+1)

Submission status: Accepted

Solution code:
N = int(input())
b = [int(x) for x in input().split()]

def solve(b):
    if len(b) == 0:
        return []
    if any(i+1 < b[i] for i in range(len(b))):
        return None
    erasable = [i+1 for i in range(len(b)) if i+1 == b[i]]
    if len(erasable) == 0:
        return None
    i = erasable[-1]  # 一番右から消す
    a = solve(b[:i-1] + b[i:])
    if a != None:
        return [i] + a
    return None

a = solve(b)
if a == None:
    print(-1)
else:
    a.reverse()
    print('\n'.join(map(str, a)))

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int,input().split()))
flag = 0
for i in range(N):
    if b[i] > i+1:
        flag = 1
ans = [0 for i in range(N)]
if flag == 1:
    print(-1)
if flag == 0:
    for i in range(N):
        for j in range(N-1,b[i]-1,-1):
            ans[j] = ans[j-1]
        ans[b[i]-1] = b[i]
    for i in range(N):
        print(ans[i])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

l = []

a = deque(l)

while b:
    memo = []
    for i in range(len(b)):
        if b[i]-1 == i:
            memo.append(i)
    if memo ==[]:
        print(-1)
        exit()
    a.appendleft(memo[-1]+1)
    b = b[:memo[-1]] + b[memo[-1]+1:]

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

Submission status: Accepted

Solution code:
n = int(input())
bs = list(map(int, input().split()))

ans = []

for i in range(n):
    for j in range(n-i, 0, -1):
        if bs[j-1] == j:
            ans.append(j)
            del bs[j-1]
            break
if len(ans) == n:
    ans = ans[::-1]
    for a in ans:
        print(a)
else:
    print(-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


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

    result = []
    for j in range(n):
        for i in range(n - j, 0, -1):
            if b[i-1] == i:
                result.append(i)
                del b[i-1]
                break
    if len(result) == n:
        result.reverse()
        for v in result:
            print(v)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N=int(input())
b=list(map(int, input().split()))

if(sum(1 for i in range(1, N+1) if b[i-1] > i)):
    ret = [-1]

else:
    M = max(b)
    ret = []
    while len(b):
        for j in range(min(M, len(b)), 0, -1):

            if j == b[j-1]:
                ret += [b[j-1]]
                del b[j-1]
                break

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

Submission status: Accepted

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

ans_list = []
bit = B[:]

for _ in range(100):
    for i in range(N)[::-1]:
        if bit[i] == 1:
            ans_list.append(B[i])
            for j in range(i,N):
                if bit[j] > 0:
                    bit[j] -= 1
            break

if set(bit) == {0}:
    pass
else:
    ans_list = [-1]

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

m = max(B)
f = False
ans = []
for _ in reversed(range(N)):
    for j in reversed(range(len(B))):
        if B[j] == j+1:
            ans.append(B.pop(j))
            f = True
            break
    if f:
        f = False
        continue
    else:
        print(-1)
        exit()
print("\n".join(map(str, reversed(ans))))

Submission status: Accepted

Solution code:
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

Submission status: Accepted

Solution code:
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i])

Submission status: Accepted

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

flag = True
ans = list()
while flag and len(B):
    for i in range(len(B) - 1, -1, -1):
        if B[i] == i + 1:
            del B[i]
            ans.append(i + 1)
            break
    else:
        flag = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) - 1 for i in input().split()]
ans = []
while len(a):
    key = -1
    for i, j in enumerate(a):
        if i == j:
            key = i
    if key == -1:
        break
    else:
        a.remove(key)
        ans.append(key + 1)

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
  n = len(b)
  f = False
  for i in range(n):
    if b[n-i-1] == n-i:
      ans.append(b.pop(n-i-1))
      f = True
      break
  if not f:
    print('-1')
    break
  if len(ans) == N:
    ans.reverse()
    for v in ans:
      print(v)
    break

Submission status: Accepted

Solution code:
def limited_insertion(N: int, B: list) -> list:
    op = []
    for i in range(N-1, -1, -1):
        for j in range(i, -1, -1):
            b = B[j]
            if i+1 < b:
                # invalid number
                return []
            if j+1 == b:
                # remove b[j]
                B = B[:j] + B[j+1:]
                op.append(b)
                break
        else:
            # not found
            return []
    return reversed(op)


if __name__ == "__main__":
    N = int(input())
    B = [int(s) for s in input().split()]

    ans = limited_insertion(N, B)
    if ans:
        for a in ans:
            print(a)
    else:
        print(-1)

Submission status: Accepted

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

def check(b):
    for i in range(len(b))[::-1]:
        if i+1 == b[i]:
            return i
    return -1

ans = []
for i in range(n):
    ind = check(b)
    if ind >= 0:
        ans.append(ind+1)
        b = b[:ind] + b[ind+1:]
    else:
        print(-1)
        exit()
for i in ans[::-1]:
    print(i)

Submission status: Accepted

Solution code:
n=int(input())
b=[int(i) for i in input().split()]
a=[0]
for i in b:
    a.insert(i-1,i)
if sum(a[:n])!=sum(b):
    print(-1)
else:
    for i in a[:n]:print(i)

Submission status: Accepted

Solution code:
def a(arg):
    for i in range(len(arg)):
        if (i + 1 == int(arg[i])):
            a = i
        if (i + 1 < int(arg[i])):
            return -1

    return int(arg.pop(a))

_ = input()
arg = input().split()

l = []
while (len(arg) > 0):
    b =  a(arg)
    if (b == -1):
        print(-1)
        break
    l.append(b)

if (len(arg) == 0):
    l.reverse()
    for i in l:
        print(i)

Submission status: Accepted

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

res = []
while True:
    if len(b) == 0:
        break
    flg = True

    for i in range(len(b)):
        k = len(b)-i-1
        if k == b[k]-1:
            a = b.pop(k)
            res.append(a)
            flg = False
            break

    if flg:
        print(-1)
        exit()

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split(" ")))
c=[]
for k in range(n):
  b=[j for j,i in enumerate(a) if i==j+1]
  if b==[]:
    print(-1)
    k=n
    break
  else:
    c.insert(0,a.pop(b[-1]))
if k==n-1:
  for i in c:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
b = [int(i) for i in input().split(' ')]
seq = []
while True:
  if len(b) == 0:
    print('\n'.join(seq[::-1]))
    break
  i = -1
  for j in range(len(b)):
    if b[j] == j + 1:
      i = j
  if i == -1:
    print('-1')
    break
  seq.append(str(i + 1))
  b = b[:i] + b[i+1:]

Submission status: Accepted

Solution code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    if not ok:
        break
    out.append(bs[change_i])
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)

Submission status: Accepted

Solution code:
import sys

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

ans = list()

for ii in reversed(range(n)):
    for jj in reversed(range(ii+1)):
        if b[jj] == jj + 1:
            ans.append(b.pop(jj))
            # print(ans)
            break

if len(b) != 0:
    print(-1)
    sys.exit()

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = list()

while len(b) > 0 and n-1 >= 0:
    if b[n-1] == n:
        b.pop(n-1)
        a.insert(0, n)
        n = len(b)
        continue
    n -= 1

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

Submission status: Accepted

Solution code:
listOutput = list()
listInput = list()
nNum = int(input())
strInput = input()
listInput = strInput.split()



while (len(listInput) > 0) and ((nNum - 1) >= 0):
    if int(listInput[nNum - 1]) == nNum:
        listOutput.insert(0, nNum)
        del listInput[nNum - 1]
        nNum = len(listInput)
        continue
    
    nNum -= 1
# end of while

if len(listInput) == 0:
    while(len(listOutput) > 0):
        print(listOutput.pop(0))
else:
    print('-1')

Submission status: Accepted

Solution code:
import sys
N = int(input())
b = list(map(int, input().split()))

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

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
b = list(map(int, input().split()))

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

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

Submission status: Accepted

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

ans = []
while True:
    num = 0
    for i in range(len(b)):
        if b[i] == i + 1:
            num = i + 1
    else:
        if num == 0:
            print("-1")
            quit()
        else:
            ans.append(b[num - 1])
            del b[num - 1]
    if b == []:
        break


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

Submission status: Accepted

Solution code:
import sys

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

check = 0
for i in range(n):
    if b[i] > i + 1:
        check = 1

if check == 1:
    print(-1)
    sys.exit()

ans = [] #Wanted Sequence

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

ans.reverse()

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

Submission status: Accepted

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
a = [0 for i in range(N)]
number = []
for j in range(N):
    for i in range(len(b)-1,-1,-1):
        if(i+1==b[i] and a[i]==0):
            del a[i]
            number.append(b[i])
            del b[i]
            break
if(not a):
    for i in range(N):
        print(number.pop())
if(a):
    print(-1)

Submission status: Accepted

Solution code:
# 実行時の引数の入力：https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

# ***.py a b c形式の引数使用時
# import sys
#
# args = sys.argv
#
# num_len = int(args[1])
# a = []
# b = []
# N = 100
# # b = [1,2,1]
# for i in range(2, 2+num_len):
#     b.append(int(args[i]))
# print(b)

a = []
# print('input:')
num_len = int(input())
b = list(map(int, input().split()))
# print('--'*len(b))
# print('output:')
# print(b)
N = 100



# for i in range(len(b)):
for i in range(num_len):
    # try:
    #     # print(i)
    #     a.insert(b[i], b[i])
    #     print(a)
    # except:
    #     print(-1)

    if b[i]-1 <= len(a):
        # print(i)
        a.insert(b[i]-1, b[i])
        # print(a)
        flag = True
    else:
        flag = False
        break


if flag:
    for i in a:
        print(i)
else:
    print(-1)

Submission status: Accepted

Solution code:
_,s=open(0);a=['']
for i in s.split():a.insert(int(i)-1,i)
print(*a[-1]and[-1]or a)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
op = []
while b:
    cur = 0
    for i in range(len(b)):
        if b[i] == i+1:
             cur = max(cur,i+1)
        else:
            continue
    if cur == 0:
        print(-1)
        exit()
    else:
        op.append(cur)
        b = b[0:cur-1]+b[cur:]
for i in range(n):
    print(op.pop())

Submission status: Accepted

Solution code:
N = int(input())
barr = list(map(int,input().split()))
cntb = []
for i in range(N):
    cntb.append([barr[i],i])
task = []
ok = True
for n in range(N):
    for i in range(N)[::-1]:
        if cntb[i][1]+1 == cntb[i][0]:
            task.append(cntb[i][0])
            cntb[i][0] = -1
            break
        elif cntb[i][0] > 0 and cntb[i][1] + 1 < cntb[i][0]:
            ok = False
        else:
            cntb[i][1] -= 1

if ok:
    for i in range(N)[::-1]:
        print(task[i])
else:
    print(-1)

Submission status: Accepted

Solution code:
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 j + 1 == b[j]:
            ans.append(b.pop(j))
            break
    else:
        print(-1)
        exit()

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

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int, input().split()))
a = []
for i in range(N):
    k = N - i
    for j in range(k):
        l = k - j
        if b[l-1] == l:
            a.append(l)
            del b[l-1]
            break
    if len(b) == k:
        break
if len(b) == 0:
    for i in reversed(range(N)):
        print(a[i])
else:
    print(-1)

Submission status: Accepted

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

ans = []

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

Submission status: Accepted

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

ans=[]

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

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i in range(len(B)-1, -1, -1):
        b = B[i]
        if i+1 == b:
            ans.append(i+1)
            break
    else:
        print(-1)
        exit()
    del B[i]
    
for idx in range(0, N):
	tmp = ans.pop(-1)
	print(tmp)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			tmp = arr.pop(idx2-1)
			ans.append(tmp)
			break
		elif idx2 == 1:
			print(-1)
			exit()

for idx in range(0, N):
	tmp = ans.pop(-1)
	print(tmp)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int,input().split()))

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

if len(nums) == 0:
    for elem in reversed(operation):
        print(elem)
else:
    print(-1)

Submission status: Accepted

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

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

if len(B) == 0:
    for l_i in l[::-1]:
        print(l_i)
else:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
ans = []
flag = True
for i in range(n):
  flag = True
  m = len(b)
  for j in range(m):
    if b[m-1-j] == m-j:
      ans.append(m-j)
      del b[m-1-j]
      flag = False
      break
  if flag:
    print(-1)
    break
if not flag:
  for i in range(n):
    print(ans[n-1-i])

Submission status: Accepted

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

for _ in range(n):
    for i in reversed(range(len(b))):
        if b[i] == i+1:
            a.append(b.pop(i))
            count += 1
            break

if count != n:
    print(-1)
else:
    for ai in a[::-1]:
        print(ai)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
b = list(map(int, input().split()))
# 1 1 1 2 2 1 2 3 2


# b = map(int, '1 1 1 2 2 1 2 3 2'.split())
# N = len(b)

steps = []
for i in range(N):
    cands = []
    for j in range(N - i):
        if (j + 1) == b[j]:
            cands.append(j)
    if len(cands) == 0:
        print(-1)
        sys.exit()
    else:
        j = cands[-1]
        steps.append(j + 1)
        b = b[:j] + b[j+1:]
for s in steps[::-1]:
    print(s)

Submission status: Accepted

Solution code:
# AGC032 Problem-AGC032

n = int(input())
a = list (map(int, input().split()))
#print (a)
a.insert(0,-1)
result = []
for i in range (n, 0, -1) :
    for j in range (i, -1, -1) :
#        print (a)
        if a[j] == j :
            result.append(j)
#            print (result)
            a = a[:j] + a[j+1:]
            break
        if j == 0 :
            result = [-1]
            break

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

Submission status: Accepted

Solution code:
input()
a=[0]
for i in input().split():
  a.insert(int(i)-1,i)
print(*[-1]if a.pop()else a,sep='\n')