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()))

ans = 0
for i in range(N):
    if 1 <= b[i] <= i+1:
        pass
    else:
        ans = -1

a = []
c = []
if ans == 0:
    k = 0
    flag = 0
    for i in range(1, N):
        if b[i] == 1 and flag == 0:
            a.append(sorted(b[:i]))
            flag = 1
            k = i
        elif b[i] == 1 and flag == 1:
            a.append(sorted(b[k:i]))
            k = i
    a.append(sorted(b[k:N]))
        
    for i in range(len(a)-1, -1, -1):
        for j in range(len(a[i])):
            if a[i][j] <= j+1:
                c.append(a[i][j])
            else:
                ans = -1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
#tmpB = copy.deepcopy(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
  #print(A)
  #print(B)

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())
list_b = list(map(int, input().split()))
aaa = []
ans = []
for i in range(N):
  if i == 0:
    aaa.append(1)
    ans.append(1)
  elif i == 1:
    s = []
    f = []
    for h in range(i+1):
      a = aaa.copy()
      b = ans.copy()
      a.insert(h, h+1)
      b.append(h+1)
      s.append(a)
      f.append(b)
    aaa = s
    ans = f
  else:
    j = []
    f = []
    for d in range(len(aaa)):
      s = []
      t = []
      for k in range(i+1):
        a = aaa[d].copy()
        b = ans[d].copy()
        a.insert(k, k+1)
        b.append(k+1)
        s.append(a)
        t.append(b)
      j = s
      f = t
    aaa = j
    ans = f

if list_b in aaa:
  index = aaa.index(list_b)
  anser = ans[index]
  for i in range(N):
    print(anser[i])
else:
  print('-1')

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.reverse()
l2=[]
l3=[]
l4=[]
for x in l:
  if x==1:
    l2.append(x)
    l2.sort()
    l3+=l2
    l2=[]
    l4.reverse()
    l3+=l4
    l4=[]
  else:
    if len(l2)>0 and l2[-1]==x:
      l4.append(x)
    else:
      l2.append(x)
if n!=len(l3):
  print(-1)
  exit()
for x in l3:
  print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=[int(i) for i in input().split()]
koho=[]
if b[0]==1:
    hoge=""
    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)):
        if i[0]!="1":
            i="1"+i
        l=[int(k) for k in i]
        for j in range(len(l)):
            print(sorted(l)[j])
else:
    print(-1)

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(vol)
			continue
		ans.append(vol)
		
		for j, val in enumerate(keep):
			#print(val)
			if val <= len(ans):
				ans.append(val)
				keep.pop(j)
	
	for vol in ans:
		print(vol)
			
if __name__ == "__main__":
	main()

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 ans[j] < b_i:
                break
        if k == -1:
            print -1
            return -1
    for a in ans:
        print a
    return 0

sol()

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
        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 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 b[i] == 1:
        if i != N-1:
            if b[i+1] != 1 and b[i+1] != 2:
                count += 1
if count>0:
    print(-1)
else:
    for i in b:
        s = random.randint(1,i)
        print(s)

Submission status: Wrong Answer

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

a = [0]*n

o = 0
l.sort()
for i in l:
    o+=1
    if(i<=o):
        if(i<=len(a)):
            if(a[i-1]!=0):
                a[a.index(0)] = i
            else:
                a[i-1] = i
if(a == l):
    print("\n".join([str(i) for i in a]))
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 listC == listB:
            for ans in listA:
                print(ans)
        else:
            print(-1)

Submission status: Wrong Answer

Solution code:
import sys

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

ope = []
while len(B) > 0:
  max = -1
  for j in range(len(B)):
    if B[j] == j+1:
      max = j
    else:
      break
  if max == -1:
    print(-1)
    sys.exit()
  v = B.pop(max)
  ope.insert(0, v)

for o in ope:
  print(o)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
judge = True
for i in range(0, N):
    if i+1 < nums[i]:
        judge = False
if judge:
    for i in range(0, N):
        print(nums[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

N = int(input())
max = 0
b = [int(x) for x in input().split()]
flag = [0 for x in range(N)]
for i in b:
    if i > max:
        max = i
submax = max
ans = []
while b != []:
    if ((submax) == my_index(b,submax-1)):
        ans.append(b.pop(submax-1))
        submax = max
    else :
        submax = submax-1
        if b[0] != 1:
            print(-1)
            exit()

for x in range(len(ans)):
    print(ans.pop())

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()
li=[]

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.reverse()
l2=[]
l3=[]
l4=[]
for x in l:
  if x==1:
    l2.append(x)
    l2.sort()
    l3+=l2
    l2=[]
    l3+=l4
    l4=[]
  else:
    if len(l2)>0 and l2[-1]==x:
      l4.append(x)
    else:
      l2.append(x)
if n!=len(l3):
  print(-1)
  exit()
for x in l3:
  print(x)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    if 1 <= b[i] <= i+1:
        pass
    else:
        ans = -1

a = []
c = []
if ans == 0:
    k = 0
    flag = 0
    for i in range(1, N):
        if b[i] == 1 and flag == 0:
            a.append(sorted(b[:i]))
            flag = 1
            k = i
        elif b[i] == 1 and flag == 1:
            a.append(sorted(b[k:i]))
            k = i
    a.append(sorted(b[k:N]))
    for i in range(len(a)-1, -1, -1):
        for j in range(len(a[i])):
            c.append(a[i][j])
    
    
    #print(a)
    #print(c)
    for i in range(N):
        print(c[i])
else:
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
judge = False
for i in range(0, N):
    if i+1 < nums[i]:
        judge = True
if judge == False:
    for i in range(0, N):
        print(nums[i])
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:
                print(-1)
                break
        elif listA[index3] > index3+1:
            print(-1)
            break
        else:
            if listA[index3]-1 <=  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            else:
                print(-1)
                break
        index3+=1
    if index3 == len(listA):
        if listC == listB:
            for ans in listA:
                print(ans)
        else:
            print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    for i, b in enumerate(B):
        if b > i+1:
            return [-1]

    ns = sorted(list(set(B)))
    ans = [-1] * N
    nid = defaultdict(list)
    for i, b in enumerate(B):
        nid[b].append(i)

    c = 0
    for i1 in reversed(nid[1]):
        ans[i1] = c
        c += 1
        for k in ns[1:]:
            while nid[k]:
                i = nid[k].pop()
                if i < i1:
                    nid[k].append(i)
                    break
                else:
                    ans[i] = c
                    c += 1
        
    ans = [(i, b) for i, b in zip(ans, B)]
    ans.sort()
    ans = [i for _, i in ans]
    return ans


def main():
    N = read_int()
    B = read_int_n()
    for r in slv(N, B):
        print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

N = int(input())
max = 0
b = [int(x) for x in input().split()]
flag = [0 for x in range(N)]
for i in b:
    if i > max:
        max = i
submax = max
ans = []
while b != []:
    if ((submax) == my_index(b,submax-1)):
        ans.append(b.pop(submax-1))
        submax = max
    else :
        submax = submax-1
        if b[0] != 1:
            print(-1)
            exit()

for x in range(len(ans)):
    print(ans.pop(len(ans)-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):
        if b[i] > i+1:
            return -1
    
    for i in range(N-1,-1,-1):
        i_order = N - (i + 1 - b[i])

        try:
            while b_order[i_order - 1] != -1:
                i_order -= 1
        
        except:
            print(-1)
            return

        b_order[i_order - 1] = b[i]

    for i in b_order:
        print(i)

f()

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
        
if flag==True:

    for i in range(n-1,-1,-1):
        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 = int(input())
b = [int(x) for x in input().split()]
ans = []
while len(b) > 1:
    tmp = max(b)
    flag = 0
    if tmp >= len(b):
        ans = None
        break
    while flag == 0:
        if b[tmp-1] == tmp: # 数字とインデックスが一致
            ans.append(b.pop(tmp-1))
            flag = 1
        else:
            tmp -= 1
        if tmp == 0:
            flag = -1
            break
    if flag == -1:
        ans = None
        break

if ans == None or b[0] != 1:
    print(-1)
else: 
    ans.append(1)
    for i in ans[::-1]:
        print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(x) for x in input().split()]
ans = []
while len(b) > 1:
    print(ans)
    tmp = max(b)
    flag = 0
    if tmp >= len(b):
        ans = None
        break
    while flag == 0:
        if b[tmp-1] == tmp: # 数字とインデックスが一致
            ans.append(b.pop(tmp-1))
            flag = 1
        else:
            tmp -= 1
        if tmp == 0:
            flag = -1
            break
    if flag == -1:
        ans = None
        break

if ans == None or b[0] != 1:
    print(-1)
else: 
    ans.append(1)
    for i in ans[::-1]:
        print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
judge = False
if nums[0] == 1:
    for i in range(0, N):
        if i+1 < nums[i]:
            judge = True
    if judge == False:
        for i in range(0, N):
            print(nums[i])
    else:
        print(-1)
else:
    print(-1)

Submission status: Wrong Answer

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

def solution(chosen=[0]*N, n=0):
    if n == N:
        return []
    c = 0
    for i in range(N):
        if chosen[i] == 0 and b[i] == i + 1 - c:
            chosen[i] = 1
            s = solution(chosen, n+1)
            if s is None:
                chosen[i] = 0
            else:
                s.append(b[i])
                return s
        elif chosen[i] == 1:
            c += 1
        elif c == 0 and b[i] > 1:
            return None
    return None

ans = solution()
if ans is None:
    print(-1)
else:
    for i in range(N):
        print(ans[i])

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

Submission status: Wrong Answer

Solution code:
n=int(input())
b=input().split()
c=n
a=[]
while len(b)!=0 and b[0]=="1":
    for x in range(c,0,-1):
        #print(x)
        if b[x-1]==str(x):
            #print("b")
            del b[x-1]
            a.append(int(x))
            c-=1

if len(a)==n:
    for x in range(n-2,-1,-1):
        print(a[x])
    print(1)
else:
    print(-1)

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(vol)
			#print(len(ans))
			continue
		ans.append(vol)
		
		for j, val in enumerate(keep):
			if val >= len(ans)-1:
				ans.append(val)
	
	for vol in ans:
		print(vol)
			
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
length = int(input())
progression = list(map(int,input().split()))
N = 0
submit_array = []

def error_case():
  print(-1)

if progression[0] == 1:
  one_count = progression.count(1)
  element_num = [i for i, x in enumerate(progression) if x == 1]
  element_max = max(element_num)
  while N < length:
    if progression[N] > (N+1):
      error_case()
      break
    N+=1
    
else:
  error_case()

Submission status: Wrong Answer

Solution code:
length = int(input())
progression = list(map(int,input().split()))
N = 0
submit_array = []
print(length)
print(progression)

def error_case():
  print(-1)

if progression[0] == 1:
  one_count = progression.count(1)
  element_num = [i for i, x in enumerate(progression) if x == 1]
  element_max = max(element_num)
  while N < length:
    if progression[N] > (N+1):
      error_case()
      break
    N+=1
    
else:
  error_case()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
l = collections.Counter()
ppp = [0 for i in range(100)]
for i in a:
    l[i] += 1

l = l.most_common()
l.sort()
for i in range(n):
    k = a[i]
    if k > i+1:
        print(-1)
        exit()

for i in range(n-2):
    if a[-(i+1)] > a[-(i+2)] and a[-(i+1)] != 1 and a[-(i+2)] != 1:
        p = a[-(i+1)]
        a[-(i+1)] = a[-(i+2)]
        a[-(i+2)] = p
b = a[1:]
b.reverse()
a = [a[0]] + b
for i in range(n):
    print(a[i])

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)))
ans=[]
ct=0
for i in s_b:
  if i>ct+1:
    print(-1)
    exit()
  count=b.count(i)
  for j in range(count):
    ans.append(i)
  ct+=count
for i in range(n):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
num = [0 for _ in range(100)]

#可能か判定
enable = True
for i in range(N):
  if b[i] > i + 1:
    enable = False
    break
  num[b[i] - 1] += 1
for i in range(max(b)):
  if num[i] == 0:
    enable = False
if not enable:
  print(-1)
else:
#達成可
  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:
import re
flg = 0
n = int(input())
b = input().replace(' ','')
b = b.split('1')
if b[0] != '':
  print(-1)
  exit()
del b[0]
b = [x[::-1] for x in b[::-1]]
b = ['1'+x for x in b]
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(-1)
        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())
l = [int(i) for i in input().split()]

a = [0]*n

o = 0
for i in l:
    o+=1
    if(i<=o):
        if(i<=len(a)):
            if(a[i-1]!=0):
                a[a.index(0)] = i
            else:
                a[i-1] = i
if(a == l):
    print("\n".join([str(i) for i in a]))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
b=input().split()
for i in range(len(b)):
    b[i] = int(b[i])
flg = False
flg2 = True
tmp = [0] * n
for i in range(1,n+1):
    if flg2 is False:
        flg = False
        break
    for l in range(len(b)):
        if b[l] <= i and b[l] >= 1 : 
            try:
                a[ b[l]-1 ] = b[l]
                # print(str(i)+"番目 "+str(b[l]) + str(a))
                tmp[i-1] = b[l]
                b[l] = 200
                flg = True
            except IndexError: 
                flg2 = False
                break

if(flg):
    for i in range(n):
        print(tmp[i])
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:
                print(-1)
                break
        elif listA[index3] > index3+1:
            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:
N = int(input())
b = []
c = [0]*N
count_flag=0
b = list(map(int, input().split()))
#print(b)
for count in range(N):
  for i in range(N-count):
    if count_flag == count and b[N-1-count-i]==N-1-count-i+1 :
      #c[count]=N-1-count-i
      c[N-1-count]=N-1-count-i+1
      b.pop(N-1-count-i)
      count_flag+=1
       #break
for i in range(N):
  print(c[i])

Submission status: Wrong Answer

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

if flag:
    print(-1)
else:
    for x in bs:
       print(x)

Submission status: Wrong Answer

Solution code:
N = input()
b = list(map(int,input().split()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        #print(b[i] ,i)
        if a[i] == i+1:
            l.append(a.pop(i))
            break
if len(l) == N:
    print("\n".join(map(str,reversed(l))))
else:
    print(-1)

Submission status: Wrong Answer

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

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

L=[]
T=[]
for b in B:
	if b==1:
		idx=1
		L.append(T)
		T=[1]
	else:
		idx+=1
		T.append(b)

	if b>idx:
		print -1
		quit()

else:
	L.append(T)


L.reverse()

for x in L:
	x.sort()

for x in L:
	for i in x:
		print i

Submission status: Wrong Answer

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

if 1 not in b:
    print(-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:
        flag = True
        for i in range(len(a)):
            if a[i] <= i+1:
                pass
            else:
                flag = False
                ans = [-1]
                break
        if not flag:
            break

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

    for a in ans:
        print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
b=input().split()
for i in range(len(b)):
    b[i] = int(b[i])
print(type(b))
flg = False
flg2 = True
tmp = [0] * n
for i in range(1,n+1):
    if flg2 is False:
        flg = False
        break
    for l in range(len(b)):
        if b[l] <= i and b[l] >= 1 : 
            try:
                a[ b[l] ] = b[l]
                # print(str(i)+"番目 "+str(b[l]) + str(a))
                tmp[i-1] = b[l]
                b[l] = 200
                flg = True
            except IndexError: 
                flg2 = False
                break

if(flg):
    for i in range(n):
        print(tmp[i])
else:
    print('-1')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
b = list(map(int,input().split()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        #print(b[i] ,i)
        if a[i] == i+1:
            l.append(a.pop(i))
            break
print("\n".join(map(str,reversed(l))))

Submission status: Wrong Answer

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



ans = []

k = 0
# try:
while True:
#     print(b, k, ans)
    if b[k] == k+1:
#         print('ok')
        k += 1
        if len(b) <= k:
            b.pop(k-1)
            ans.append(k)
            k = 0

    else:
#         print('out')
        if k == 0:
            ans = [-1]
            break
        b.pop(k-1)
        ans.append(k)
        k = 0
    if len(b) == 0:
        break


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

Submission status: Wrong Answer

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

out = []
for i, x in enumerate(b):
    if x > i+1:
        print(x, i+1)
        out = [-1]
        break
    else:
        out.insert(x-1, x)

for x in out:
    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)):
      if b[-1] ==  n - c:
        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())
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])

        try:
            while b_order[i_order - 1] != -1:
                i_order -= 1
        
        except:
            print(-1)
            return

        b_order[i_order - 1] = b[i]

    for i in b_order:
        print(i)

f()

Submission status: Wrong Answer

Solution code:
length = int(input())
progression = list(map(int,input().split()))
N = 0
submit_array = []

def error_case():
  print(-1)

if progression[0] == 1:
  one_count = progression.count(1)
  element_num = [i for i, x in enumerate(progression) if x == 1]
  element_max = max(element_num)
  while N < length:
    
    if progression[N] < (N+1):
      error_case()
      break
    
    N+=1
    
else:
  error_case()