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
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
ans=[]
while len(arr)>0:
    maxtmp=0
    for i,j in enumerate(arr):
        #print(i,j,i+1,arr[i])
        if i+1==j:
            maxtmp=j-1
    p=arr.pop(maxtmp)
    ans.append(p)
    #print(ans)

k=reversed(ans)
for i,j in enumerate(k):
    print(j)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()
ans = []
flag = 1
while flag:
  flag = 0
  for i in range(N)[::-1]:
    if i+1 == A[i]:
      ans.append(A[i])
      A = A[:i]+A[i+1:]
      N -= 1
      flag = 1
      break
if A:
  print(-1)
else:
  for a in ans:
    print(a)

Submission status: Wrong Answer

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

lst = []
for i in range(n, 0, -1):
    for j in range(i - 1, -1, -1):
        if b[j] == j + 1:
            lst.append(j + 1)
            b.pop(j)
            break
    else:
        print("No")
        exit()

for num in lst[::-1]:
    print(num)

Submission status: Wrong Answer

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

lst = []
for i in range(n, 0, -1):
    for j in range(i - 1, -1, -1):
        if b[j] == j + 1:
            lst.append(j + 1)
            b.pop(j)
            break
    else:
        print("No")
        break

for num in lst[::-1]:
    print(num)

Submission status: Wrong Answer

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

    ans = ''
    for k in range(1, n + 1):
        for i in range(n - k, -1, -1):
            if b[i] == i + 1:
                b.pop(i)
                ans += str(i + 1) + '\n'
                break
        else:
            print(-1)
            exit()

    print(ans[::-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    m = []
    for i in range(n, 0, -1):
        s = b.pop()
        if s > i:
            print(-1)
            exit()

        m.append(s)
    ans = '\n'.join(map(str, m[::-1]))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))
ans=[]
turn=N
while(b):
    lim=turn
    if b[0]!=1:
        print(-1)
        exit()
    now=0
    for i in range(1,min(lim,len(b))):
        if b[i]==i+1:
            now=i
        else:
            break
    ans.append(now+1)
    del b[now]
    turn-=1
print(*ans[::-1],sep='\n')

Submission status: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))
ans=[]
turn=N
while(b):
    lim=turn
    if b[0]!=1:
        print(-1)
        exit()
    now=0
    for i in range(1,min(lim,len(b))):
        if b[i]==i+1:
            now=i
        else:
            break
    ans.append(now+1)
    del b[now]
print(*ans[::-1],sep='\n')

Submission status: Wrong Answer

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

a = []
while b:
    for i in range(len(b)):
        if i + 1 != b[i]:
            a.append(b[i-1])
            b.remove(b[i-1])
            break
    if b == list(range(1, len(b)+1)):
        for j in reversed(b):
            a.append(j)
            b.remove(j)


a.reverse()
if a[0] != 1:
    print(-1)
else:
    print('\n'.join(map(str, a)))

Submission status: Wrong Answer

Solution code:
n =  int(input())
l =  list(map(int,input().split()))
l1 = []
for i in range(n):
  for j in range(n-1-i,-1,-1):
    if l[j]==j+1:
      l1.append(l[j])
      del l[j]
      break
    else:
      continue
if len(l)==0:
  for j in l1:
    print(j)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n = ni()
    a = na()

    for i, ai in enumerate(a):
        if ai > i + 1:
            print(-1)
            exit(0)
        else:
            print(ai)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
B = [0]+list(map(int,input().split()))

ans_li = []
for i in range(n):
    for j in range(len(B)-1,0,-1):
        if j==B[j]:
            ans_li.append(B.pop(j))
            break
    print(-1);exit()
print('\n'.join(map(str,ans_li[::-1])))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

def dfs(s, ans):
    #print(s, ans)
    if len(s) == 0:
        print('\n'.join(map(str, reversed(ans))))
        exit()
        return
    for i in range(len(s)):
        if s[i] == i+1 and max(s[i+1:] + [0]) <= i+1:
            s1 = s[:i] + s[i+1:]
            ans.append(s[i])
            dfs(s1, ans)
    if len(ans) > 0:
        ans.pop()

dfs(b, [])

print('-1')

Submission status: Wrong Answer

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


result=[]

for i in range(n-1):
    posi=-1
    for j in range(min(i+1,n-i-1)):
        if s[j]<=i+1:
            posi=j
    if posi!=-1:
        result.append(s[posi])
        s.pop(posi)
    else:
        print(posi)
        exit()
    #print(s)
    #print(result)

for item in result:
    print(item)

Submission status: Wrong Answer

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


result=[]

for i in range(n-1):
    posi=-1
    for j in range(min(i+1,n-i-1)):
        if s[j]<=i+1:
            posi=j
    if posi!=-1:
        result.append(s[posi])
        s.pop(posi)
    print(s)
    print(result)

for item in result:
    print(item)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

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

N = I()
b = LI()

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

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
b = list(map(int, input().split()))
A = []
def func(n, x, a):
    if n == 0:
        for j in range(N):
            print(a[j])
        sys.exit()
    for i in range(n):
        if x[i] == i + 1:
            f = func(n - 1, x[:i]+x[i+1:], str(x[i]) + a)                   
func(N, b, '')
print('-1')

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
A = []
def func(n, x, a):
    if n == 0:
        return True
    for i in range(n):
        if x[i] == i + 1:
            f = func(n - 1, x[:i]+x[i+1:], x[i])
            if f:
                A.append(x[i])
                return True
            
func(N, b, 0)
if A == []:
    print('-1')
else:
    print(A)

Submission status: Wrong Answer

Solution code:
inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
b = list(map(int, input().split()))
ans = []
while b:
    ind = 0
    for i,c in enumerate(b):
        if i+1 == c:
            ind = i
    ans.append(b.pop(ind))
ans.reverse()
for tmp in ans:
    print(tmp)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7


def getorder(h,s):
    if len(s) == 1:
        return [h]
    points = []
    for i,c in enumerate(s):
        if c == h:
            points.append(i)
    ret = [h]
    if s[-1] != h:
        tmp = getorder(h+1,s[points[-1]+1:])
        for g in tmp:
            ret.append(g)
    if len(points) != 1:
        points.reverse()
        for j in range(len(points)-1):
            ret.append(h)
            if points[j+1]+1 != points[j]:
                tmp = getorder(h+1,s[points[j+1]+1:points[j]])
                for g in tmp:
                    ret.append(g)
    return ret

n = int(input())
b = list(map(int, input().split()))
if b[0] != 1:
    print(-1)
    sys.exit()
pre = 1
flag = True
for tmp in b:
    if abs(tmp-pre) > 1:
        flag = False
        break
    else:
        pre = tmp
if flag:
    ans = getorder(1,b)
    for t in ans:
        print(t)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
b = list(map(int, input().split()))
if b[0] != 1:
    print(-1)
    sys.exit()
pre = 1
flag = True
for tmp in b:
    if abs(tmp-pre) > 1:
        flag = False
        break
    else:
        pre = tmp
b.reverse()
ans = []
if flag:
    k = 0
    while k < n:
        while k < n and b[k] == 1:
            ans.append(1)
            k+=1
        if k >= n:
            break
        pre = b[k]
        tmplist = deque([pre])
        k+=1
        while k < n and b[k] != 1:
            tmp = b[k]
            if tmp > pre:
                tmplist.append(tmp)
            else:
                tmplist.appendleft(tmp)
            pre = tmp
            k+=1
        tmplist.appendleft(1)
        for h in tmplist:
            ans.append(h)
        k+=1
    for tmp in ans:
        print(tmp)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
b = list(map(int, input().split()))
if b[0] != 1:
    print(-1)
    sys.exit()
pre = 1
flag = True
for tmp in b:
    if abs(tmp-pre) > 1:
        flag = False
        break
    else:
        pre = tmp
b.reverse()
ans = []
if flag:
    k = 0
    while k < n:
        while k < n and b[k] == 1:
            ans.append(1)
            k+=1
        if k >= n:
            break
        pre = b[k]
        tmplist = deque([pre])
        k+=1
        while k < n and b[k] != 1:
            tmp = b[k]
            if tmp >= pre:
                tmplist.append(tmp)
            else:
                tmplist.appendleft(tmp)
            pre = tmp
            k+=1
        tmplist.appendleft(1)
        for h in tmplist:
            ans.append(h)
        k+=1
    for tmp in ans:
        print(tmp)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    N = int(input())
    B = deque(list(map(int, input().split())))
    temp = deque([])
    result = []
    for i in range(N):
        b = B.pop()
        temp.appendleft(b)
        if b == 1:
            work = []
            for t in temp:
                if t-1 > len(work):
                    print(-1)
                    return
                else:
                    work.insert(t-1, t)
            for w in work:
                result.append(w)
            temp = deque([])
    if len(result) == 0:
        print(-1)
    for r in result:
        print(r)
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))
A = []
for b in B:
    A.insert(b-1, b)
if all(A[i] <= i+1 for i in range(n)):
    print(*A, sep='\n')
else:
    print(-1)

Submission status: Wrong Answer

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

a = []

for i in range(N):
  for j in range(i):
    if b[j] == j+1:
      a.append(j+1)
a.sort()
if a == sorted(b):
  a = []
  for i in range(N):
    for j in range(i):
      if b[j] == j+1:
        print(j+1)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:

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

ans = []
removed = [False] * N

flag = True
while flag:
    flag = False
    prev = 0
    ex_idx = -1
    for i in range(N):
        if removed[i]:
            continue

        if prev + 1 == B[i]:
            prev = B[i]
            ex_idx = i
        else:
            break
    
    if ex_idx != -1:
        ans.append(B[ex_idx])
        removed[ex_idx] = True
        flag = True


if all(removed):
    for a in ans[::-1]:
        print(a)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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



ans = []
removed = [False] * N

flag = True
while flag:
    flag = False
    prev = 0
    ex_idx = -1
    for i in range(N):
        if removed[i]:
            continue

        if prev + 1 == B[i]:
            prev = B[i]
            ex_idx = i
        else:
            break
    
    if ex_idx != -1:
        ans.append(B[ex_idx])
        removed[ex_idx] = True
        flag = True


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

Submission status: Wrong Answer

Solution code:
from collections import Counter


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



ans = []
removed = [False] * N

flag = True
while flag:
    flag = False
    prev = 0
    # まだ消していないものの中で、左端のものを探す
    l = -1
    for i in range(N):
        if not removed[i]:
            l = i
            break

    if l == -1:
        break
    ex_idx = -1
    idx = -1
    for i in range(l,N):
        if removed[i]:
            continue

        if prev + 1 == B[i]:
            prev = B[i]
            ex_idx = i
        else:
            break
    
    if ex_idx != -1:
        ans.append(B[ex_idx])
        removed[ex_idx] = True
        flag = True


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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10 ** 7)  # NOQA


def dfs(N, a, i, b):
    if i == N + 1:
        if a == b:
            return a
        else:
            return None
    i += 1
    for j in range(1, i):
        A = a[:]
        A.insert(j-1, j)
        res = dfs(N, A, i, b)
        if res is not None:
            return res


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

    res = dfs(N, [], 1, b)
    if res is None:
        print(-1)
    else:
        print(*res, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

result =[]
while len(a) > 0:
    ok = False
    for i in range(len(a)-1, -1, -1):
        print(i, len(a))
        if i+1 == a[i]:
            result.append(a[i])
            a.pop(i)
            ok = True
            break
    if not ok:
        result = [-1]
        break
for i in result[::-1]: print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
ok = True
for i in range(n):
    if b[i] > i+1:
        ok = False
        break
if ok:
    x = ""
    for i in range(1, n+1):
        if b[-i] == 1:
            if x=="": a = b[-i:]
            else: a = b[-i:x]
            a.sort()
            for v in a: print(v)
            x = -i
else: print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
x = ""
ok = True
if 1 not in b or b[0] != 1: False
else:
    for i in range(1, n+1):
        if b[-i] == 1:
            if x=="": a = b[-i:]
            else: a = b[-i:x]
            a.sort()
            for v in a: print(v)
            x = -i
if not ok: print(-1)

Submission status: Wrong Answer

Solution code:
N,*B = map(int, open(0).read().split())
ans = [0]*N
for i in range(N):
  for j in range(len(B)-1,-1,-1):
    if B[j]==j+1:
      ans[N-1-i] = j+1
      B = B[:j]+B[j+1:]
      break
print('\n'.join(map(str,ans)))

Submission status: Wrong Answer

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

xs = [[] for i in range(n)]
cnt = 0
prev = 0
for b in bs:
    if b - prev > 1:
        print(-1)
        exit() 
    if b == 1:
        cnt += 1
    xs[cnt].append(b)        
    prev = b

for x in xs[::-1]:
    for ans in sorted(x):
        print(ans)

Submission status: Wrong Answer

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

xs = [[] for i in range(n)]
cnt = 0
prev = 0
for b in bs:
    if b - prev > 1:
        print(-1)
        exit() 
    if b == 1:
        cnt += 1
    xs[cnt].append(b)        
    prev = b
# print(xs)
for x in xs[::-1]:
    for ans in x:
        print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=0
nMax=1
for i in range(n):
    if b[i]<=nMax:
        nMax=b[i]+1
    elif b[i]>nMax:
        ans=-1
        break
if ans==-1:
    print(ans)
else:
    a=[]
    for i in range(n):
        for j in range(len(b)):
            if b[len(b)-1-j]==len(b)-j:
                a.append(b[len(b)-1-j])
                b=b[:len(b)-1-j]+b[len(b)-j:]
                break
    for i in range(n):
        print(a[n-1-i])

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=0
nMax=1
for i in range(n):
    if b[i]<=nMax:
        nMax=b[i]+1
    elif b[i]>nMax:
        ans=-1
        break
if ans==-1:
    print(ans)
else:
    a=[]
    for i in range(n):
        if b[n-i-1]!=1:
            a.append(b[n-i-1])
        else:
            print(b[n-i-1])
            a.sort()
            for j in range(len(a)):
                print(a[j])
            a=[]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

while b:
    for i in reversed(range(len(b))):
        if b[i] == i+1:

            ans.append(b.pop(i))
            break

    else:
        print(-1)
        exit()

Submission status: Wrong Answer

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

cnt = {i: 0 for i in range(1, N + 1)}
for i in range(0, N):
    for b in B[i:]:
        if (i + 1) == b:
            cnt[b] += 1

res = []
while N > 0:
    idx = -1
    for i in range(len(B) - 1, -1, -1):
        if i + 1 == B[i] and cnt[B[i]] == 1 and B[i] != 1:
            idx = i
            break
        elif cnt[B[i]] > 1:
            idx = i
    res.append(B[idx])
    cnt[B[idx]] -= 1
    N -= 1
    tmp = []
    for i, b in enumerate(B):
        if i != idx:
            tmp.append(b)
    B = tmp

if B[0] != 1:
    print(-1)
else:
    for ans in res[::-1]:
        print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
for i in ans[::-1]:
    print(i)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
b = list(map(int, input().split()))
b.sort()
b.reverse()
for i in range(n):
    if b[i] > n - i:
        print("-1")
        exit()
b.reverse()
for i in range(1,n+1):
    index = bisect.bisect_left(b,i)
    index = min(index,len(b)-1)
    print(b[index])
    del b[index]

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = []
C = []
for i in range(n):
    B.append([A[i], i+1-A[i], i])
    if i + 1 - A[i] < 0:
        print(-1)
        exit()
for i in range(n):
    f = False
    c = 0
    m = [-1, -1, -1]
    for j in range(n):
        if B[j][1] == 0:
            f = True
            break
        if B[j][1] < 0:
            c += 1
    if not f and c < n:
        print(-1)
        exit()
    if c == n: break
    for k in range(n):
        if B[k][1] == 0 and B[k][2] > m[2]:
            m = B[k]
    C.append(m[0])
    B[m[2]][1] -= 1
    for l in range(n):
        if B[l][1] != 0:
            B[l][1] -= 1
print(*C[::-1], sep="\n")

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
arr = list(map(int,input().split()))
arr2 = []
for i in arr:
    if i > 1:
        if i - 1 in arr2:
            arr2.remove(i-1)
        else:
            print(-1)
            exit()
    arr2.append(i)
ans = []
for i in arr:
    ans.insert(i-1,i)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(n):
    if i+1 < A[i]:
        print(-1)
        exit()
    B.append([A[i], i+1 - A[i], i])
C = []
for i in range(n):
    m = [0, 0, 0]
    for j in range(n):
        if B[j][1] == 0 and B[i][2] >= m[0]:
            m = B[j]
    B[m[2]][1] -= 1
    C.append(m[0])
    for k in range(n):
        if B[k][2] >= m[2] and B[k][1] > 0:
            B[k][1] -= 1
print(*C[::-1], sep="\n")

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
print(-1)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
A = list(map(int, input().split()))
if min(A) != 1:
    print(-1)
    exit()
j = 0
B = list(reversed(A))
for i in range(n):
    if B[i] == 1:
        C = sorted(B[j:i+1])
        for k in C:
            print(k)
        j = i+1

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


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


def check(B, cnt):
    n = len(B)
    for i in range(n):
        if B[n - i - 1] == (n - i):
            hand.append(B[n - i - 1])
            B = B[: n - i - 1] + B[n - i :]
            break
    if len(B) != n and len(B) > 0:
        return B
    else:
        return False


cnt = 1
while B:
    B = check(B, cnt)
    # print(B)

if len(hand) < N:
    print(-1)
    sys.exit()
for i in range(N):
    if hand[i] > i + 1:
        print(-1)
        sys.exit()
answer = hand[::-1]
print(*answer, sep="\n")

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
ans = []
idx = n
if 1 not in b:
    print(-1)
    exit()
for i in reversed(range(n)):
    if b[i] != 1: continue
    elif b[i] > i + 1:
        print(-1)
        exit()
    else:
        b_ = b[i:idx]
        l_ = []
        idx = i
        ma = max(b_)
        for j, bi in enumerate(b_):
            if bi == j + 1 or bi < j + 1:
                if bi in l_: continue
                else:
                    for _ in range(b_.count(bi)):
                        ans.append(bi)
                    l_.append(bi)
            elif bi > j + 1:
                print(-1)
                exit()
for i in range(n): print(ans[i])

Submission status: Wrong Answer

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

def solve(arr):
  ret = []
  while len(arr) > 0:
    before = len(arr)
    for i in reversed(range(len(arr))):
      if arr[i] == i + 1:
        ret.append(arr.pop(i))
        break
    if len(arr) == before:
      return None
  return list(reversed(ret))

A = solve(B)
print(A)

if A == None:
  print(-1)
else:
  for a in A:
    print(a)

Submission status: Wrong Answer

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

B = []
Btmp = [Bin[0]]
for i in range(1, N):
  if Bin[i] == 1:
    B.append(Btmp)
    Btmp = []
  Btmp.append(Bin[i])
else:
  B.append(Btmp)
#print(B)
#print(list(reversed(B)))

def solve(arr):
  ret = []
  while len(arr) > 0:
    before = len(arr)
    for i in reversed(range(len(arr))):
      if arr[i] == i + 1:
        ret.append(arr.pop(i))
        break
    if len(arr) == before:
      return None
  return reversed(ret)

A = []
success = True
for Bsub in reversed(B):
  tmp = solve(Bsub)
  if tmp == None:
    success = False
    break
  A.extend(tmp)
#print(A)
if success:
  for a in A:
    print(a)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

    res = [0] * n

    for current_num in range(n, 0, -1):
        for i in range(n):
            if b[i] == current_num:
                idx = (n + current_num - (i+1)) - 1
                if idx > n - 1:
                    print(-1)
                    sys.exit()
                while res[idx] != 0:
                    idx -= 1
                res[idx] = current_num

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# 数列の操作で入力の配列を作ることができるか、と言う形式の問題(構築？)
# 考え方としては、一意に定まるとして考えることが定石
# 特徴的なケース1,nを考えたが、有効そうな案は浮かばず
# 前からi番目がj の時、これはi-j+1番以降に出されたことがわかる
# 前から順番に埋めて行ったら解けそう
# b[i-1]<=iなら絶対いけるのでは？
n = int(input())
b = list(map(int,input().split()))
for i in range(n):
    if b[i] > i+1: 
        print(-1)
        exit()