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:
N = int(input())
B = list(map(int,input().split()))
tmpB = B[:]
A = []
for i in range(1,N+1):
  if(B == []):
    break
  for b in B:
    if(1 <= b <= i):
      A.insert(b-1, b)
      B.remove(b)
      break
if(B == []):
  if(sorted(A) == sorted(tmpB)):
    for a in A:
      print(a)
    exit()
print(-1)

Submission status: Wrong Answer

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

index=0
ichiI = 0
while index < len(listB):
    if index == 0:
        if listB[index] == 1:
            pass
        else:
            print(-1)
            break
    else:
        if listB[index] == 1:
            ichiI = index
        else:
            if listB[index] > index- ichiI+1:
                print(-1)
                break   
    index+=1

if index == len(listB):
    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:
                print(-1)
                break
        else:
            if listA[index3]-1 <  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            elif listA[index3]-1 == len(listC):
                listC.append(listA[index3])
            else:
                break
        index3+=1
    if listC == listB:
        for ans in listA:
            print(ans)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
import re
flg = 0
n = int(input())
b = input().replace(' ','')
b = b.split('1')
if b[0] != '':
  print(-1)
  exit()
del b[0]
b = ['1'+x for x in b]
b = [x[::-1] for x in b[::-1]]
for i in b:
  for j in range(1,10):
    for k in [x for x in i if x == str(j)]:
      if i.index(k) + 1 < int(k):
        print(-2)
        exit()
for i in b:
  for j in range(1,10):
    for k in [x for x in i if x == str(j)]:
      flg = 1
      print(k)
if flg == 0:
  print(-1)

Submission status: Wrong Answer

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

for i in range(n):
    if b[i]>i+1:
        print(-1)
        import sys
        sys.exit()
    else:
        l.append([b[i],i+1-b[i]])

from operator import itemgetter
l.sort(key=itemgetter(0))
l.reverse()
l.sort(key=itemgetter(1))
l.reverse()

for i in range(1,n+1):
    for j in range(len(l)):
        if l[j][0]<=i:
            print(l[j][0])
            l.remove(l[j])
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i  in input().split()]
if b[0] != 1:
    print(-1)
else:
    a = "".join([str(i) for i in b]).split("1")
    a = [list(("1" + i)) for i in a[1:]]
    ans = []
    for i in range(len(a)-1, -1, -1):
        temp = a[i]
        temp = [int(t) for t in temp]
        max_temp = max(temp)
        set_list = set(range(1, max_temp+1))
        if set(temp) == set_list:
            temp = sorted(a[i])
            ans.extend(temp)
        else:
            print(-1)
            break
    for i in ans:
        print(i)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
print('-1')

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
gc032 A
"""

from collections import Counter

n = int(input())
bli = list(map(int, input().split()))
cli = bli.copy()
cli.reverse()

for i in range(1, n+1):
    if 1 in cli:
        x = cli.index(1)
        for j in range(0, x+1):
            cli[j] -= 1
    else:
        print(-1)
        quit()
    print(bli[n-1-x])

Submission status: Wrong Answer

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

a = []
for _n in range(1, n + 1):
    a.insert(_n, list(range(1, _n + 1)))

err = False
res = []

for i, _b in enumerate(b):
    if _b in a[i]:
        res.append(str(_b))
    else:
        err = True
        break

if err:
    print('-1')
else:
    print('\n'.join(res))

Submission status: Wrong Answer

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

def search_num(num):
  try:
    nn = b.index(num)
    b.remove(num)
    return num
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1

if n != len(b):
  print('-1')
else:
  for i in range(n):
    num = search_num(i+1)
    if num == -1:
      print('-1')
      break
    else:
      pool.append(str(num))
      if i+1 == n:
        text = '\n'.join(pool)
        print(text)

Submission status: Wrong Answer

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

a = []
for _n in range(1, n + 1):
    a.insert(_n, list(range(1, _n + 1)))

err = False
res = []

for i, _b in enumerate(b):
    if _b in a[i]:
        res.append(str(_b))
    else:
        err = True
        break

if err:
    print(-1)
else:
    print('\n'.join(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.insert(i-1, max(b_sort[:i]))
        #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 = input()
N = int(n)

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

answer = []

count = 0
count_bk = 0

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

Submission status: Wrong Answer

Solution code:
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ False ] * N

  for i in range(N):
    for j in range(len(B)):
      if B[j] == j + 1: continue
      if j == 0: return '-1'
      ans[i] = str(B.pop(j - 1))
      break
    if not ans[i]: ans[i] = str(B.pop(-1))
  return '\n'.join(reversed(ans))

print(solve())

Submission status: Wrong Answer

Solution code:
n=int(input())
b=[int(x) for x in input().split()]
flag=None
b=sorted(b)
for i in range(n):
    if not b[i] <= i+1:
        print(-1)
        break
    if i+1==n:
        flag=True

if flag:
    for x in b:
        print(x)

Submission status: Wrong Answer

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

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

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 = []
for i in range(N-1, -1, -1):
	if b[i] == 1:
		a += sorted([b.pop() for j in range(len(b)-i)])

if len(a) != N:
	print(-1)
else:
	for ai in a:
		print(ai)

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) - 1, -1, -1):
        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 = list(map(int,input().split()))
tmpB = B[:]
A = []
for i in range(1,N+1):
  for b in B:
    if(B == []):
      break
    if(1 <= b <= i):
      A.insert(b-1, b)
      B.remove(b)
      break
tmpA = A[:]
if(B == []):
  if(sorted(tmpA) == sorted(tmpB)):
    for a in A:
      print(a)
  else:
    print(-1)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
B=list(map(int,input().split()))
B.sort()
c=sorted(Counter(B).most_common(),key=lambda x:x[0])
m=len(c)
ans=N
tmpid=0
count=0
for i in range(1,N+1):
    if tmpid==m:
        if count>0:
            ans-=1
            count-=1
    elif i==c[tmpid][0]:
        count+=(c[tmpid][1]-1)
        tmpid+=1
        ans-=1
    elif count>0:
        ans-=1
        count-=1
if ans==0:
    for b in B:
        print(b)
else:
    print(-1)

Submission status: Wrong Answer

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

flag = True
if b[0] != 1:
    flag = False

for i in range(n):
    a.insert(b[i]-1,b[i])
    #print(a)
    if b[i] > i:
        flag = False

if flag == False:
    print("-1")

else:
    for i in a:
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
import collections
c = collections.Counter(b)
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)):
      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:
import re
flg = 0
n = int(input())
b = input().replace(' ','')
b = b.split('1')
del b[0]
b = ['1'+x for x in b]
b = [x[::-1] for x in b[::-1]]
for i in b:
  for j in range(1,10):
    for k in [x for x in i if x == str(j)]:
      flg = 1
      print(k)
if flg == 0:
  print(-1)

Submission status: Wrong Answer

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

ans = []
note = N
for i in range(N-1,-1,-1):
    if B[i] == 1:
        ans += sorted(B[i:note])
        note = i

check = []
for a in ans:
    check.insert(a-1,a)

if check != B:
    print(-1)
    exit()

for a in ans:
    print(a)

Submission status: Wrong Answer

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

result = []
nums = [0] * (N + 1)
for i, bi in enumerate(B):
    nums[bi] += 1
    if bi == 1:
        for j in range(1, N + 1):
            if nums[j] != 0:
                for k in range(nums[j]):
                    result.append(j)
        nums = [0] * (N + 1)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [None] * N
b = list(map(int,input().split()))
b_sorted = sorted(list(zip(b,list(range(N)))),key=lambda x:x[0])
i = 0
log = []
for i in range(N):
    if b_sorted[i][0] <= i + 1:
        value, index = b_sorted[i]
        log.append(str(value))
    else:
        print(-1)
        break
else:
    print("\n".join(log))

Submission status: Wrong Answer

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

index=0
ichiI = 0
while index < len(listB):
    if index == 0:
        if listB[index] == 1:
            pass
        else:
            print(-1)
            break
    #else:
        #if listB[index] == 1:
            #ichiI = index
        #else:
            #if listB[index] > index- ichiI+1:
                #print(-1)
                #break   
    index+=1

if index == len(listB):
    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
    for ans in listA:
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
isContinue = True
res = []
isContinue = True
while isContinue:
    if len(b) > 1:
        for i in range(len(b)):
            if not b[i] == i + 1:
                if i == 0:
                    print(-1)
                    isContinue = False
                    break
                else:
                    res.append(b.pop(i - 1))
                    break
            if i == len(b) - 1:
                res.append(b.pop(i))
                break
    else:
        if b[0] == 1:
            res.append(b.pop(0))
            isContinue = False
        else:
            print(-1)
            isContinue = False
if len(b) == 0:
    for i in range(1,n+1):
        print(res[-i])

Submission status: Wrong Answer

Solution code:
n,*b=map(int,open(0).read().split())

a=[]
for i in range(n):
    bs=list(set(b))
    bs.sort(reverse=True)
    ii=0
    while 1:
        mxi=b.index(bs[ii])
        if mxi==bs[ii]-1:
            del b[mxi]
            a.append(bs[ii])
            break
        elif mxi>bs[ii]-1:
            ii+=1
        else:
            break
    if mxi<bs[ii]-1:
        print(-1)
        break

print(*a[::-1],sep="\n")

Submission status: Wrong Answer

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

ans=[]

for i in range(N):
    # print(b)
    #j:index of delete + 1(ans base)
    j = 1
    if j < len(b):
        while b[j] == j + 1:
            j += 1
            if j == len(b):break
    if b[j - 1] == j:
        del b[j-1]
        ans.append(j)
    else:
        print(-1)
        import sys
        sys.exit()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
bc = b[::-1]
a = []
s = 0
for i in range(n):
    if bc[i] == 1:
        sbc = sorted(bc[s:i+1],reverse=True)
        if sbc[0] <= len(sbc):
            for j in sorted(sbc):
                a.append(j)
            s = i+1
        else:
            print(-1)
            exit()
if not a:
    print(-1)
    exit()

for k in a:
    print(k)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.append(max(b_sort[:i]))
        #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=input().split()
B.append('0')

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

history=[]
while len(B)!=1:

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

    bef_kick_len=len(B)
    # kick seatmate
    for state in range(len(B)-1):
        # print("state {} state+1 {}".format(state,B[state]))
        if B[state]==B[state+1]:
            history.append(B.pop(state))
            break

    # if failed, go to kill original
    if len(B)==bef_kick_len:
        for ind in range(len(B))[::-1]:
            # print("index {} value {}".format(ind+1, B[ind]))
            if int(B[ind])==ind+1:
                history.append(B.pop(ind))
                break

#print(history)

rev_his=reversed(history)
for i in rev_his:
    print(i)

Submission status: Wrong Answer

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

a = []
for i in range(N-1, -1, -1):
	if b[i] == 1:
		a += sorted([b.pop() for j in range(len(b)-i)])

if len(a) != N:
	print(-1)
else:
	for ai in a:
		print(ai)

Submission status: Wrong Answer

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

flag = True
if b[0] != 1:
    flag = False

for i in range(n):
    a.insert(b[i]-1,b[i])
    #print(a)

if flag == False:
    print("-1")

else:
    for i in a:
        print(i)

Submission status: Wrong Answer

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

ans=[]

for i in range(N):
    print(b)
    #j:index of delete + 1(ans base)
    j = 1
    if j < len(b):
        while b[j] == j + 1:
            j += 1
            if j == len(b):break
    if b[j - 1] == j:
        del b[j-1]
        ans.append(j)
    else:
        print(-1)
        import sys
        sys.exit()

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

Submission status: Wrong Answer

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

a = []
for i in range(N-1, -1, -1):
	if b[i] == 1:
		a += sorted([b.pop() for j in range(len(b)-i)])

if len(a) != len(b):
	print(-1)
else:
	for ai in a:
		print(ai)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.append(max(b_sort[i-1:i]))
        #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=[int(x) for x in input().split()]

b=sorted(b)
for i in range(n):
    if i+1==n:
        print(b)
    elif not b[i] <= i+1:
        print(-1)
        break

Submission status: Wrong Answer

Solution code:
import math

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

a = []
lis = []

for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
        lis.insert(b[i-1], b[i-1])
    else:
        break

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

check = True
for i in range(n):
    if a[i] > i+1:
        check = False
if check:
    ans = []
    start = 0
    while len(a) != 0:
        temp = False
        for i in range(len(a)-1):
            if a[i] >= a[i+1]:
                ans.append(a[i])
                a.pop(i)
                temp = True
                break
        if temp == False:
            ans.append(a[-1])
            a.pop(-1)
    ans.reverse()
    for i in range(n):
        print(ans[i])
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = input().split()
bls = []
for i in b:
    bls.append(int(i))

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

ans = []

splist = []

now = []
for n in bls:
    if n == 1:
        if len(now) != 0:
            splist.append(now)
        now = [1]
    else:
        now.append(n)

if len(now) != 0:
    splist.append(now)
        
for s in splist:
    sans = []
    for n in range(0,len(s)):
        num = s[n]
        if num<= n+1:
            #print("ok",num,n)
            sans.append(num)
        else:
            #print("ng",num,n)
            print(-1)
            exit()
    sans.sort(reverse=True)

    for i in sans:
        ans.append(int(i))
    
for i in range(1,len(ans)+1):
    print(ans[-i])

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(int(x) for x in input().split())
revans = []
flg = True
cond = True
while(flg):
    for i, item in enumerate(b):
        if i == len(b)-1:
            if item == len(b):
                revans.append(b.pop(i))
            else:
                flg = False
                cond = False
                break
        else:
            if item == i+1:
                if b[i+1] == item + 1:
                    continue
                else:
                    revans.append(b.pop(i))
                    break
    if b == []:
        flg = False

if cond:
    revans.reverse()
    for item in revans:
        print(item)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
tmp = B[:]
A = []
for i in range(1,N+1):
  for b in B:
    if(B == []):
      break
    if(1 <= b <= i):
      A.insert(b-1, b)
      B.remove(b)
      break
if B == []:
  for a in A:
    print(a)
else:
  print(-1)

Submission status: Wrong Answer

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

index=0
ichiI = 0
while index < len(listB):
    if index == 0:
        if listB[index] == 1:
            pass
        else:
            print(-1)
            break
    else:
        if listB[index] == 1:
            ichiI = index
        else:
            if listB[index] > index- ichiI+1:
                print(-1)
                break   
    index+=1
    
if index == len(listB):
    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
    for ans in listA:
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()] 
pool = []
def search_num(num):
  try:
    nn = b.index(num)
    b.remove(num)
    return num
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1
    
for i in range(n):
  num = search_num(i+1)
  if num == -1:
    print('-1')
    break
  else:
    pool.append(str(num))
    if i+1 == n:
      text = '\n'.join(pool)
      print(text)
      break

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(int(x) for x in input().split())
revans = []
flg = True
cond = True
while(flg):
    for i, item in enumerate(b):
        if i == len(b)-1:
            if item == len(b):
                revans.append(b.pop(i))
            else:
                flg = False
                cond = False
                break
        else:
            if item == i+1:
                if b[i+1] == item + 1:
                    continue
                else:
                    revans.append(b.pop(i))
                    break
    print(b)
    if b == []:
        flg = False

if cond:
    revans.reverse()
    for item in revans:
        print(item)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
M = [int(i) for i in input().split()]
# print(N, M)
a = list(range(1, N+1))
b = a[1:] + [a[0]]
b = b[::-1]
# print(b)
# print(M)
for aa, bb in zip(M, b):
    if aa > bb:
        print(-1)
        exit()
# print(M)
mm = M[::-1]
# print(M)
# print(M[1:] + [M[0]])
for x in M[1:] + [M[0]]:
    print(x)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i:
        a.append(max(b_sort[i-1:i]))
    else:
        pass
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 = input().split()
bls = []
for i in b:
    bls.append(int(i))

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

ans = []

splist = []

now = []
for n in bls:
    if n == 1:
        if len(now) != 0:
            splist.append(now)
        now = [1]
    else:
        now.append(n)

if len(now) != 0:
    splist.append(now)
        
for s in splist:
    sans = []
    for n in range(0,len(s)):
        num = s[n]
        if num<= n+1:
            #print("ok",num,n)
            sans.append(num)
        else:
            #print("ng",num,n)
            print(-1)
            exit()
    sans.sort(reverse=True)

    for i in sans:
        ans.append(int(i))
    
for i in range(0,len(ans)):
    print(ans[-i])

if len(ans) > 1:
    print(ans[0])

Submission status: Wrong Answer

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

can = True
for i in range(1, n +1):
  if b[i - 1] > i:
    can = False

if can:
  for x in b:
    print(x)
else:
  print(-1)

Submission status: Wrong Answer

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

for i, _b in enumerate(b):
    if _b in a[i]:
        print(str(_b))
    else:
        print('-1')
        break

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
B=list(map(int,input().split()))
B.sort()
c=Counter(B).most_common()
m=len(c)
ans=N
tmpid=0
count=0
for i in range(1,N+1):
    if tmpid==m:
        ans-=1
    elif i==c[tmpid][0]:
        count+=(c[tmpid][1]-1)
        tmpid+=1
        ans-=1
    elif count>0:
        ans-=1
if ans==0:
    for b in B:
        print(b)
else:
    print(-1)

Submission status: Wrong Answer

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

result = []
nums = [0] * (N + 1)
for i, bi in enumerate(B):
    nums[bi] += 1
    if bi == 1:
        for j in range(1, N + 1):
            if nums[j] != 0:
                for k in range(nums[j]):
                    result.append(j)
        nums = [0] * (N + 1)

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

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

Submission status: Wrong Answer

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

a = []
for i in range(N-1, -1, -1):
	if b[i] == 1:
		a += sorted([b.pop() for j in range(len(b)-i)])

if len(a) == 0:
	print(-1)
else:
	for ai in a:
		print(ai)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def main():
    lines = sys.stdin.readlines()
    N = int(lines[0])
    b = [int(i) for i in lines[1].split(' ')]
    a = []

    #MAXの値より2回減少が続くと無理みたい
    max_index = b.index(max(b))
    if len(b) > max_index + 2:
        if b[max_index+2] < b[max_index]:
           print(-1)
           return  


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i, _b in enumerate(b):
    if _b in a[i]:
        print(_b)
    else:
        print(-1)
        break

Submission status: Wrong Answer

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

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

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

n = int_raw()
bs = ints_raw()

def sol():
    ans =[0]*n
    for i in xrange(n,0,-1):
        b_i = bs[i-1]
        if b_i > i:
            print -1
            return -1
        k= -1
        for j in xrange(n-i+b_i-1,b_i-2,-1):
            if ans[j] == 0:
                ans[j] = b_i
                k= j
                break
        if k == -1:
            print -1
            return -1
    for a in ans:
        print a

sol()

Submission status: Wrong Answer

Solution code:
import math

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

a = []

for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
    else:
        break

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

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=[]
for i in range(n):
  tmp=i+1
  if b[i]<=tmp:
    ans.append(tmp)
  else:
    print(-1)
    exit()
for i in ans:
  print(i)

Submission status: Wrong Answer

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

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

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

print(L)

Submission status: Wrong Answer

Solution code:
import math

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

a = []
print(b)
for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
    else:
        break

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

Submission status: Wrong Answer

Solution code:
import random

N = int(input())
b = [int(i) for i in input().split()]
count = 0
for i in range(N):
    if b[i] > i+1:
        count += 1

if count >= 1:
    print(-1)
else:
    for i in b:
        s = random.randint(1,i)
        print(s)