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: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

if b[0] != 1:
  print('-1')
  sys.exit()

for i in range(1,n):
  d = b[i]-b[i-1]
  if abs(d) > 1:
    print('-1')
    sys.exit()

b.reverse()

def sr(l,m):
  for u in range(len(l)):
    if l[u] == m:
      return u
  return -1

ans = []
p = 1
k = 0
while(b):
  x = sr(b,p)
  y = sr(b,p+1)
  if p == 1:
    k = x+1
  if x == -1:
    p -= 1
  else:
    ans.append(b.pop(x))
    k -= 1
    if k == 0 and len(b) > 1:
      p = 1
      continue
    if x > y:
      p += 1

for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
def rightMinNumber(L):
    min = L[len(L)-1]
    min_index = len(L) - 1
    for i in range(len(L)-2,-1,-1):
        if L[i] < min:
            min = L[i]
            min_index = i
    a.append(min)
    if min_index+1 == len(L) and min_index == 0:
        return
    if min_index + 1 < len(L):
        rL = L[min_index+1:]
        rightMinNumber(rL)
    if min_index > 0:
        lL = L[:min_index]
        rightMinNumber(lL)

N = int(input())
B = [int(_) for _ in input().split()]
#出力
a = []
#Bのエンコーダを作る
x = 0

#Bの正当性を調べる。
for i in range(N):
    if B[i] > i+1:
        x = -1
        break

if x == -1:
    print(x)
else :
    rightMinNumber(B)
    for i in range(N):
        print(a[i])

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import sys
n = int(input())
a = []
b = list(map(int, input().split()))
for i in range(len(b)):
    if b[i] > i+1:
        print(-1)
        sys.exit()
b_sort = sorted(b)
b_arr = [0 for i in range(100)]
for i in range(100):
    b_arr[i] = b.count(i+1)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.insert(i-1, b_sort[i-1])
        if b_arr[b_sort[i-1]-1] > 0:
            b_arr[b_sort[i-1]-1] -= 1
        else:
            b_arr[max(b_sort[:i])-1] -= 10
        #print(max(b_sort[:i]))
if len(a) == len(b_sort):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

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

b_order = [-1]*N

def f():
    
    for i in range(N-1,-1,-1):
        i_order = N - (i + 1 - b[i])

        if i_order > N:
            print(-1)
            return

        while b_order[i_order - 1] != -1:
            i_order -= 1
            if i_order < 0:
                print(-1)
                return

        b_order[i_order - 1] = b[i]

    for i in b_order:
        print(i)

f()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	N = int(input())
	B = input().split(" ")
	B = [int(s) for s in B]
	
	ans = []
	for i, vol in enumerate(B):
		if vol > N or vol > i+1:
			print(-1)
			sys.exit()
		
	keep = []
	ans.append(B.pop(0))
	ans.append(B.pop(-1))
	B.reverse()
	for i, vol in enumerate(B):
		if vol > len(ans):
			keep.append((i, vol))
			continue
		ans.append(vol)
		
		for j, val in enumerate(keep):
			k, val2 = val
			if val2+k <= len(ans):
				#print("sss")
				#print(len(ans)+k)
				ans.append(val2)
				keep.pop(j)
	
	for vol in ans:
		print(vol)
			
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
b_rev = []
op = []
for i in (reversed(b)):
    b_rev.append(i)

while 1:
    if b_rev.count(1) == 0 or b[0] != 1:
        print(-1)
        exit()
    if len(b_rev) == 0:
        for i in op:
            print(i)
        else:
            exit()
    idx_one = b_rev.index(1)
    op.append(1)
    b_tmp = b_rev[0:idx_one]
    while len(b_tmp) > 0:
        min_tmp = min(b_tmp)
        for idx, item in enumerate(b_tmp):
            if item == min_tmp:
                idx_min = idx
        op.append(b_tmp.pop(idx_min))
    else:
        del b_rev[0:idx_one + 1]

Submission status: Wrong Answer

Solution code:
def rightMinNumber(L):
    min = L[len(L)-1]
    min_index = len(L) - 1
    for i in range(len(L)-2,-1,-1):
        if L[i] < min:
            min = L[i]
            min_index = i
    a.append(min)
    if min_index+1 == len(L) and min_index == 0:
        return
    if min_index + 1 < len(L):
        rL = L[min_index+1:]
        print(rL)
        rightMinNumber(rL)
    if min_index > 0:
        lL = L[:min_index]
        print(lL)
        rightMinNumber(lL)

N = int(input())
B = [int(_) for _ in input().split()]
#出力
a = []
#Bのエンコーダを作る
x = 0

#Bの正当性を調べる。
for i in range(N):
    if B[i] > i+1:
        x = -1
        break

if x == -1:
    print(x)
else :
    rightMinNumber(B)
    for i in range(N):
        print(a[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b = input().split()
a = []
cont = 1
for s in b:
    if 1 <= int(s) <= cont:
        a.insert(int(s),int(s))
    cont += 1
if len(a)==len(b):
    for s in a:
        print(s)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
def zur(z, xx):
    if z not in xx:
        return z
    while True:
        z -= 1
        if z == 0:
            print(-1)
            sys.exit()
        if z not in xx:
            return z

i = input()
xs = [int(x) for x in input().strip().split(" ")]
xp = {}

for i, x in enumerate(xs):
    i = i+1
    if x > i:
        print(-1)
        sys.exit()
    if x not in xp:
        xp[x] = list()
    xp[x].append(i)
x = max(xs)
last = len(xs)
xo = []
xx = set()
while True:
    if x == 0:
        break
    if x in xp:
        for i in xp[x]:
            i - x
            xxx = zur(x + last - i, xx)
            xo.append((xxx, x))
            xx.add(xxx)
    x -= 1

for i, x in sorted(xo, key=lambda x:x[0]):
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 1:
#    print(ans,b)
    c = len(ans)
    f = b[0]
    for i in range(1, len(b))[::-1]:
      if b[i] == i + 1 and len(set(b[i:])) == 1:
#        print("check", b[i:])
        ans.extend(b[i:])
        b = b[:i]
        break
    for i in range(1, len(b)):
#      print(f, i, b, n - c, ans)
      if f >= b[i]:
        ans.append(b.pop(i-1))
        break
      elif n - c == b[i]:
        ans.append(b.pop(i))
        break
      elif i == len(b) - 1:
        ans.append(b.pop(-1))
        break
      else:
        f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])

Submission status: Wrong Answer

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

for i in range(n):
    b[i] = int(b[i])


# n個の配列を全て1で埋める
ans=[0]*n

for i in range(n):
    
    for j in reversed(range(b[i],i+1)):
        ans[j] = ans[j-1]
    
    
    ans[b[i]-1] = b[i]

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

Submission status: Wrong Answer

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

cnt = 0
cnt2 = 0
judge = 0
var = N
for i in range(N):  
    if B[i] == var:
        cnt += 1
        if cnt + cnt2 > i:
            judge += 1
    cnt2 = cnt - i
    var += 1
if judge > 0:
    print('-1')
else:
    B.sort()
    for i in range(N):
        print(B[i])

Submission status: Wrong Answer

Solution code:
import itertools
from functools import lru_cache

N = int(input())
b = [int(_b) for _b in input().strip().split(' ')]

@lru_cache(maxsize=1000)
def makeList(l):
  result = [1]
  for i in l:
    result.insert(i-1, i)
  return result

def isSame(l1,l2):
  if len(l1) != len(l2):
    return False
  for a,b in zip(l1,l2):
    if a != b:
      return False
  return True

def isValid(l):
  for i in range(len(l)):
    if not l[i] <= i+1:
      return False
  return True

if not isValid(b):
  print(-1)
  exit()

for l in itertools.permutations(b[1:]):
  if not isValid(l):
    continue
  result = makeList(l)
  print(l,result)
  if isSame(result, b):
    print(1)
    for i in l:
      print(i)
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
b_arr = [0 for i in range(100)]
for i in range(100):
    b_arr[i] = b.count(i+1)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.insert(i-1, b_sort[i-1])
        if b_arr[b_sort[i-1]-1] > 0:
            b_arr[b_sort[i-1]-1] -= 1
        else:
            b_arr[max(b_sort[:i])-1] -= 10
        #print(max(b_sort[:i]))
if len(a) == len(b_sort):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def func(b):
    target = [[] for _ in range(len(b) + 1)]
    out = []
    for i in range(len(b)):
        target[b[i]].append(i)
    search = 0
    pos = -1
    while True:
        # print("target:{}".format(target))
        # print("search:{}".format(search))
        # print("pos:{}\n".format(pos))
        if len(target[search]) > 0 and \
                        target[search][-1] > pos:
            out.append(search + 1)
            pos = target[search][-1]
            search += 1
        else:
            search -= 1
            if search == -1:
                return out
            if len(target[search]) > 0:
                target[search].pop()
            if search == 0:
                pos = -1
            else:
                if len(target[search - 1]) == 0:
                    return out
                pos = target[search - 1][-1]


# print(func([0, 1, 0]))
# print(func([1, 1]))
# print(func([0, 0, 0, 1, 1, 0, 1, 2, 1]))

n = int(input())
b = [int(i) - 1 for i in input().split()]
_list = func(b)
if len(_list) == len(b):
    for i in _list:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

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

result = []

def solve(B, cur):
    pre = 0
    for i, bi in enumerate(B):
        if bi == cur:
            result.append(cur)
            solve(B[pre:i], cur + 1)
            pre = i

solve(B, 1)

ans = []
for i, ri in enumerate(result):
    ans.insert(ri - 1, ri)

if ans == C:
    for ri in result:
        print(ri)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np


def input_line():
    N = int(input())
    b = [int(i) for i in input().split()]

    # TODO 最後にbに1を加える
    tmp = []
    for i in b:
        tmp.append(i - 1)
    b = tmp

    return N, np.array(b)


def possible_check(b):
    # 1 bの最大値がNより大きい
    counter = [0] * 100
    if (max(b) >= len(b)):
        print(-1)
        exit()
    else:
        for i in b:
            counter[i] += 1

    # 2 最短でおいてもその数字をそこに置けない
    for index, i in enumerate(b):
        if (b[i] > index):
            print(-1)
            exit()

    # 3　自分より小さいものが自分より手前に十分な数存在しない
    for i in range(N):
        if (np.sum((b - b[i])[0:i + 1] < b[i]) < i):
            print(-1)
            exit()
    return


if __name__ == "__main__":
    N, b = input_line()
    experiment_list = []

    possible_check(b)

    print("?")

Submission status: Wrong Answer

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

b_order = [-1]*N

def f():
    
    for i in range(N-1,-1,-1):
        i_order = N - (i + 1 - b[i])

        if i_order > N:
            print(-1)
            return

        while b_order[i_order - 1] != -1:
            i_order -= 1
            if i_order < 0:
                print(-1)
                return

        b_order[i_order - 1] = b[i]
        print(b_order)

    for i in b_order:
        print(i)

f()

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
c=[]
for i in range(n-1,-1,-1):
    if 0<b[i][1]<=i+1 and 0<b[i][0]<=i+1:
        c.append(b[i][1])
        d.pop(b[i][0]-1)
        b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
    else:
        print(-1)
        break
else:
    for i in c[::-1]:
        print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = input().split()
a = []
cont = 1
for s in b:
    if int(s) <= cont:
        a.append(int(s))
    cont += 1
if len(a)==len(b):
    for s in a:
        print(s)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=[int(i) for i in input().split()]
koho=[]
hoge=""
ans=[]
cnt=0
result=True
for i in range(n):
    if i<n-1:
        if b[i+1]==1 and len(hoge)>=1:
                koho.append(hoge+str(b[i]))
                hoge=""
        else:
            hoge+=str(b[i])
    else:
        hoge+=str(b[i])
koho.append(hoge)
for i in list(reversed(koho)):
    l=[int(k) for k in i]
    for j in range(len(l)):
        num=sorted(l)[j]
        if num>cnt+1:
            result=False
        else:
            ans.append(num)
        cnt+=1
if result:
    print(*ans,sep="\n")
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
b_arr = [0 for i in range(100)]
for i in range(100):
    b_arr[i] = b.count(i+1)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.insert(i-1, max(b_sort[:i]))
        if b_arr[max(b_sort[:i])-1] > 0:
            b_arr[max(b_sort[:i])-1] -= 1
        else:
            b_arr[max(b_sort[:i])-1] -= 10
        #print(max(b_sort[:i]))
if len(a) == len(b_sort):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = sorted(list(map(int,input().split())))
c=0
if max(b)>a:
  c-=1
for i in range(1,a+1):
    if b.count(i)<a:
        c+=1
if c == a :
    for i in range(a):
        print(b[i])
else :
    print(-1)

Submission status: Wrong Answer

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

for i in range(n):
    b[i] = int(b[i])


# n個の配列を全て1で埋める
ans=[1]*n

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B= input().split()
B.reverse()
a = []
x = []
l = []
result = True
for i in range(N):
  b = int(B[i])
  x.append(b)
  if b == 1:
    x.sort()
    for y in x:
      if y > i+1:
        result = False
        break
      a.insert(y-1,y)
      l.append(y)
    x = []

  if result == False:
    break
    
if result:
  for i in l:
    print(i)
else:
  print("-1")

Submission status: Wrong Answer

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

if 1 not in b:
    ans = [-1]
else:
    start = N
    for i in range(N-1, -1, -1):
        if b[i] == 1:
            queue.append(b[i:start])
            start = i

    for a in queue:
        if len(a) == 1:
            if a[0] != 1:
                ans = [-1]
                break
            else:
                ans.append(1)
        else:
            flag = True
            for i in range(len(a)):
                if a[i] <= i+1:
                    pass
                else:
                    flag = False
                    ans = [-1]
                    break
            if not flag:
                break

            tmp = []
            next_pass = False
            idx = 0
            x = None
            for i in range(len(a)-1, 0, -1):
                if not next_pass:
                    if a[i-1] <= a[i]:
                        tmp.insert(idx, a[i])
                        tmp.insert(idx, a[i-1])
                        next_pass = True
                        x = i-1
                    else:
                        tmp.append(a[i])
                        idx = len(tmp)
                        x = i
                else:
                    next_pass = False
            if x != 0:
                tmp.insert(0, 1)
            ans.extend(tmp)

for a in ans:
    print(a)

Submission status: Wrong Answer

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

def shorten(l, count, opr):
    next_opr = []
    if count==n:
        return opr
    for x in set(l):
        if len(l)>=x and len(l)>=max(set(l)):
            if l[x-1] == x:
                l_ = l[:]
                l_.pop(x-1)
                # print(x, l_, count+1, opr+[x])
                next_opr = shorten(l_, count+1, opr+[x])
    return next_opr
ans = shorten(bb,0,[])[::-1]
if ans == []:
    print(-1)
else:
    for x in ans:
        print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 1:
    c = len(ans)
    f = b[0]
    for i in range(1, len(b))[::-1]:
      if b[i] == i + 1 and len(set(b[i:])) == 1:
        ans.extend(b[i:])
        b = b[:i]
        break
    for i in range(1, len(b)):
      if b[-1] ==  n - c or i == len(b) - 1:
        ans.append(b.pop(-1))
        break
      if f >= b[i]:
        ans.append(b.pop(i-1))
        break
      elif n - c == b[i]:
        ans.append(b.pop(i))
        break
      else:
        f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
li = list(reversed(li))
if 1 not in li:
  print(-1)
  exit()

#print(li)
a = []
flag = 0
for i in range(n):
  if li[i] == 1:
    a.append(1)
    arr = sorted(li[flag:i])
    for j in arr:
      if j != 1:
        a.append(j)
        flag = i+1
#print(a)
for k in a:
  print(k)

Submission status: Wrong Answer

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

def shorten(l, count, opr):
    next_opr = []
    if count==n:
        return opr
    for x in set(l):
        if len(l)>=x and len(l)>=max(set(l)):
            if l[x-1] == x:
                l_ = l[:]
                l_.pop(x-1)
                print(x, l_, count+1, opr+[x])
                next_opr = shorten(l_, count+1, opr+[x])
    return next_opr
ans = shorten(bb,0,[])[::-1]
if ans == []:
    print(-1)
else:
    for x in ans:
        print(x)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-

from sys import stdin

###########################################

############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
n = stdin.readline().split()
data = stdin.readline().split()

out = []

token = 0

# check first data and return -1 if != 1
if int(data[0]) != 1:
    token = -1
else:    
# print first data
    out.append(1)

for i,x in enumerate(data):
    data[i]=int(x)
    
# split to multiple data.
x = 1
split = []
chunck = []
#while x < len(data):
for i,num in enumerate(data[x:]):
    chunck.append(num)
    if num == 1:
        split.append(chunck)
        chunck=[]
        x = i+1
if chunck != []:
    split.append(chunck)

for x in reversed(split):
    maxnum=max(x)
    if x == [1]:
        out.append(1)
    else:
        for i in range(1,maxnum+1):
            if i in x:
                count = x.count(i)
                if x.index(i) >= i-2:
                    for xx in range(count):
                        out.append(i)
                else:
                    token = -1

if token == -1:
    print(-1)
else:
    # print outputs
    for x in out:
        print(x)

Submission status: Wrong Answer

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

result = []

def solve(B, cur):
    pre = 0
    for i, bi in enumerate(B):
        if bi == cur:
            result.append(cur)
            solve(B[pre:i], cur + 1)
            pre = i

solve(B, 1)

ans = []
for i, ri in enumerate(result):
    if 1 <= ri <= i + 1:
        ans.insert(ri - 1, ri)
    else:
        print(-1)
        quit()

if ans == C:
    for ri in result:
        print(ri)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
listB = list(map(int, input().split()))
i = 1
if i == 1:
    listA = []
    index2 = len(listB)-1
    befI = len(listB)
    while index2 > -1:
        if listB[index2]!=1:
            pass
        else:
            if index2 != befI:
                newL = listB[index2:befI]
                newL.sort()
                listA.extend(newL)
                befI = index2
            else:
                listA.append(1)
        index2-=1
    listC = []
    index3=0
    while index3 < len(listA):
        if index3 == 0:
            if listA[index3] == 1:
                listC.append(listA[index3])
            else:
                listC.append(0)
        elif listA[index3] > index3+1:
            listC.append(0)
        else:
            if listA[index3]-1 <=  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            else:
                listC.append(0)
        index3+=1
    if index3 == len(listA):
        if 0 in listC or listA == []:
            print(-1)
        else:
            for ans in listA:
                print(ans)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:

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

a = []*n
add_will_list = b_line.copy()

def select_number(i,add_will_list):
    for k in range(1,i+1):
        if k in add_will_list:
            return k
    else:
        return -1

added_list = []
for i in range(1,n+1):
    if len(add_will_list) == 0:
        continue 
    j = select_number(i,add_will_list)
    if j == -1:
        print(j)
        break
    a.insert(j-1,j)
    added_list.append(j)
    del add_will_list[add_will_list.index(j)]
else:
    for added in added_list:
        print(added)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = map(int,input().split())
b_ = []
for i in b:
    b_.append(int(i))
b_.sort()
a = []
for i in range(1,N+1):
    if i >= b_[i-1]:
        a.append(b_[i-1])
if len(a)==len(b_):
    for s in a:
        print(s)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
listB = list(map(int, input().split()))
i = 1
if i == 1:
    listA = []
    index2 = len(listB)-1
    befI = len(listB)
    while index2 > -1:
        if listB[index2]!=1:
            pass
        else:
            if index2 != befI:
                newL = listB[index2:befI]
                newL.sort()
                listA.extend(newL)
                befI = index2
            else:
                listA.append(1)
        index2-=1
    listC = []
    index3=0
    while index3 < len(listA):
        if index3 == 0:
            if listA[index3] == 1:
                listC.append(listA[index3])
            else:
                listC.append(0)
        elif listA[index3] > index3+1:
            listC.append(0)
        else:
            if listA[index3]-1 <=  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            else:
                listC.append(0)
        index3+=1
    if index3 == len(listA):
        if listB != listC:
            print(-1)
        else:
            for ans in listA:
                print(ans)
    else:
        print(-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
A = []
O = []
for i in range(1, N+1):
    ii = -1
    for ii, (b, a) in enumerate(zip(B[::-1], A[::-1])):
        if b != a:
            num = len(A)-ii+1
            A.insert(num-1, num)
            O.append(num)
            break
    if ii == len(A)-1:
        A.insert(1, 1)
        O.append(1)
if A != B:
    print(-1)
else:
    for i in O:
        print(i)

Submission status: Wrong Answer

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

#可能か判定
enable = True
for i in range(N):
  if b[i] > i + 1:
    enable = False
    break
if not enable:
  print(-1)
else:
#達成可
  tmp = []
  ans = []
  for i in range(N):
    tmp.append(b[i])
    if i == N - 1 or b[i + 1] == 1:
      tmp.sort(reverse = True)
      for t in tmp:
        ans.append(t)
      tmp = []
  ans.reverse()
  for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
if b[0]!=1:
    print(-1)
else:
    ans=[1]
    for j in range(len(b)-1):
        for i in range(len(b)-1,-1,-1):
            if i==0 and b[0]==1:
                ans+=[b.pop(i)]
                break
            if b[i]==i+1:
                ans+=[b.pop(i)]
                break                
    if len(ans)!=n:  
        print(-1)
    else:
        print(1)
        for i in range(n-1,0,-1):
            print(ans[i])

Submission status: Wrong Answer

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

ans = [0 for i in range(n)]

flag=True
for i in range(n):
    if b[i]>i+1:
        flag=False
        
first_1=True
        
if flag==True:
    
    

    for i in range(n-1,-1,-1):
        if b[i]==1 and first_1==True:
            first_1=False
            ans[0]=1
        
        
        
        else:
            ind = b[i]+(n-(1+i)) -1     
            while ans[ind]!=0:
                ind-=1
            ans[ind]=b[i]

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

Submission status: Wrong Answer

Solution code:
n = input()
N = int(n)

b_array = list(map(int, input().strip().split(' ')))

answer = []
count = 0
count_bk = 0
bcount = 1
b_array = b_array[::-1]
for i in b_array:
    if i == 1:
        count += 1
        tmpa = []
        anstmp = []
        for b in sorted(b_array[count_bk:count]):
            if b <= bcount:
                # tmpa.insert(b-1, b)
                anstmp.append(b)
            else:
                print(-2)
                exit()
            bcount += 1
        # print(tmpa[::-1])
        # print(b_array[count_bk:count])

        # if tmpa[::-1] == b_array[count_bk:count]:
        answer.extend(anstmp)
        '''
        else:
            print(-2)
            exit()
        '''
        count_bk = count
    else:
        count += 1
for a in answer:
    print(a)
if len(answer) == 0:
    print(-2)

Submission status: Wrong Answer

Solution code:
import sys
import copy

N = int(input())
b = [int(b) for b in input().split()]
h = {}

def f(b):
  key = "".join([str(x) for x in b])
  if key in h:
    return h[key]
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return h[key]
  
  for i in range(len(b)):
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return h[key]
  
  h[key] = []
  return h[key]

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

Submission status: Wrong Answer

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


def calc(d):
    rec = []
    if len(d) == 0:
        return []
    if len(d) == 1:
        return [d[0]]
    ma = max(d)
    for i in range(len(d)):
        if ma == d[i]:
            rec = calc(d[i - ma + 1:i]) + calc(d[i + 1:]) + [ma] + calc(d[:i - ma + 1])
            break
    return rec


p = calc(b)
for i in p:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = map(int,input().split())
b_ = []
for i in b:
    b_.append(int(i))
b_.sort()
a = []
cont = 1
for i in b_:
    if cont >= i:
        a.append(b_[cont-1])
    cont += 1
if len(a)==len(b_):
    for s in a:
        print(s)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
listB = list(map(int, input().split()))
i = 1
if i == 1:
    listA = []
    index2 = len(listB)-1
    befI = len(listB)
    while index2 > -1:
        if listB[index2]!=1:
            pass
        else:
            if index2 != befI:
                newL = listB[index2:befI]
                newL.sort()
                listA.extend(newL)
                befI = index2
            else:
                listA.append(1)
        index2-=1
    listC = []
    index3=0
    while index3 < len(listA):
        if index3 == 0:
            if listA[index3] == 1:
                listC.append(listA[index3])
            else:
                listC.append(0)
        elif listA[index3] > index3+1:
            listC.append(0)
        else:
            if listA[index3]-1 <=  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            else:
                listC.append(0)
        index3+=1
    if index3 == len(listA):
        if 0 in listC:
            print(-1)
        else:
            for ans in listA:
                print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 1:
    c = len(ans)
    f = b[0]
    for i in range(1, len(b))[::-1]:
      if b[i] == i + 1:
        ans.extend(b[i:])
        b = b[:i]
        break
    for i in range(1, len(b)):
      if b[-1] ==  n - c or i == len(b) - 1:
        ans.append(b.pop(-1))
        break
      if f >= b[i]:
        ans.append(b.pop(i-1))
        break
      elif n - c == b[i]:
        ans.append(b.pop(i))
        break
      else:
        f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])