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 numpy as np

def main():
    n = int(input())
    a = []
    b = list(map(int, input().rstrip().split(" ")))

    for i in range(n):
        for j in range(len(b)):
            if b[j] == j + 1:
                if j + 1 == len(b): 
                    a.append(b.pop(j))
                    break
                elif b[j+1] != j + 2:
                    a.append(b.pop(j))
                    break
            else:
                break

    a.reverse()
    if len(a) == n:
        for v in a:
            print(v)
    else:
        print(-1)



if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    n = int(input())
    a = []
    b = list(map(int, input().rstrip().split(" ")))

    for i in range(n):
        for j in range(len(b)):
            if b[j] == j + 1:
                if j + 1 == len(b): 
                    a.append(b.pop(j))
                    break
                elif b[j+1] != j + 2:
                    a.append(b.pop(j))
                    break

    a.reverse()
    if len(a) == n:
        for v in a:
            print(v)
    else:
        print(-1)



if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
N = input()
l = sorted(map(int, input().split()))

ret = []
for x in l:
#  print(x)
  if len(ret) == 0:
    ret.append(x)
  elif x > len(ret):
    ret = [-1]
    break
  else:
    ret.insert(x, x)
#print("**")
for x in ret:
  print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = input().split()
b = [int(i) for i in b ]
ans = 1
def check(n):
	global b
	global ans
	for i in range(1,n+1):
		if not b[0] == 1:
			ans = 0
		elif b[i-1] <= i:
			b[i-1-(b[i-1])],b[i-1] = b[i-1],b[i-1-(b[i-1])]
		else:
			ans = 0
		return b
b = check(N)
if ans == 0:
	print(-1)
else:
	for i in b:
		print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = input().split()
b = [int(i) for i in b ]
def check(n):
	for i in range(1,n+1):
		if i < b[i-1]:
			return 0
	return 1
if check(N) == 1:
	for i in range(N):
		print(b[i])
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = []
  while a != []:
    ct = 0
    
    for i in a:
      ct += 1
      if i != ct:
       if ct == 1: 
          print(-1)
          exit()
       else:
        ans.append(a.pop(ct-2))
        break
      else: 
        if len(a) == a[-1]:
         ans.append(a.pop(-1))
        
       
  for i in ans[::-1]:
   print(i)
solve()

Submission status: Wrong Answer

Solution code:
import sys

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

s=s+[10**6]
ans=[0]*N


for i in range (N):
    m=-1
    for j in range (N-i):
        if s[j]==j+1:
            m=j
    if m<0:
        sys.exit()
    
    ans[N-i-1]=m+1
    
    for j in range (m,N):
        s[j]=s[j+1]
        
    
for i in range(N): print(ans[i])

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=1
for i in range(n):
  if not m[i]<=i+1:
    a=0
if a==1:
  for i in m:
    print(i)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
def delete(k,ct,cmp):
	if arr[k]>=cmp:
		delete(k-1,ct,cmp)
	if arr[k]-2>0:
		delete(k-1,arr[k]-ct,arr[k])
		freq[k]=1
	freq[k]=1
	print(arr[k])

n=int(input())
arr=list(map(int,input().split()))
freq=[0]*n
for i in range(n):
	if arr[i]>i+1:
		print(-1)
		exit()
j=n-1
freq[0]=1
print(1)
while  j>-1:
	if freq[j]==0:
		ct=arr[j]-2
		if ct>0:
			delete(j-1,ct,arr[j])
		print(arr[j])
		freq[j]=1	
	j-=1	
	pass

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    ans = []
    for n in range(N, 0, -1):
        for i in range(N-1, -1, -1):
            if not B[i]:
                continue
            if B[i] == n:
                ans.append(n)
                B[i] = 0
                break
            n -= 1
    print(*ans[::-1], sep='\n')

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

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

if N >= 2:
    if B[-1] == 1 and B[-2] > B[-1]:
        print(-1)
        exit()
        
ANS = []


def create(i):
    ans = [B[i]]
    while (i + 1) < N and (B[i] == B[i + 1] - 1):
        ans.append(B[i + 1])
        i += 1
    return i + 1, ans


I = 0
while I < N:
    next_I, ans = create(I)
    I = next_I
    ANS.append(ans)


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

check = []
cnt = 1
for x in X:
    if x > cnt:
        print(-1)
        exit()
    cnt += 1
    check.insert(x - 1, x)

print(*X, sep='\n')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
def f(a):
  print(a)
  if len(a) == 0:
    return []
  for i in range(len(a)):
    if a[i] == i+1:
      b = a.copy()
      b.pop(i)
      ret = f(b)
      if ret == [-1]:
        continue
      ret.append(i+1)
      return ret
    else:
      continue
  else:
    return [-1]
ret = f(a)
print('\n'.join(map(str,ret)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
#n = 3
#a = [1,2,1]
def f(a):
  print(a)
  if len(a) == 0:
    return []
  for i in range(len(a)):
    if a[i] == i+1:
      b = a.copy()
      b.pop(i)
      ret = f(b)
      if ret == [-1]:
        continue
      ret.append(i+1)
      return ret
    else:
      continue
  else:
    return [-1]
ret = f(a)
print(' '.join(map(str,ret)))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
def ordering(N,b):
    a=[]
    comb=math.factorial(N)
    x=[[]]*comb
    y=[[]]*comb
    for i in range(1,N):
        a=a+[i]
        for n,m in enumerate(a):
            x[n].insert(m-1,m)
            y[n].append(m)
    resnum=[x.index(i) for i in x if i==b]
    try:
        for i in y[resnum[0]]:
            print(i)
    except:
        return(-1)

Submission status: Wrong Answer

Solution code:
def find(n):
    """
    tn = int(n/2)
    s = 2 * tn + 1
    :param n:
    :return:
    """
    tn = int(n/2)
    s = 2 * tn + 1
    count = 0
    line_list = []
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i + j != s:
                line_list.append(str(i) + " " + str(j))
                count +=1

    return count, line_list


if __name__ == '__main__':
    n = input()

    count, line_list = find(int(n))
    print(count)
    print("\n".join(line_list))

Submission status: Wrong Answer

Solution code:
n = int(input())

l = input().split()

res = []

for i in range(n):
    
    
    for j in range(len(l)):
        if(l[j] == str(j+1)):
            res.append(l[j])
            del(l[j])
            break


            

if(l != []):
    print(-1)
else:
    print("\n".join(res[::-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())

l = input().split()

res = []

for i in range(n):
    maxi = 0
    
    for j in range(len(l)):
        if(l[j] == str(j+1)):
            maxi = max(maxi,j)

    res.append(l[maxi])
    del(l[maxi])

            

if(l != []):
    print(-1)
else:
    print("\n".join(res[::-1]))

Submission status: Wrong Answer

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

c = []
while 0 < len(b):
    candidate = []
    for i, b_i in enumerate(b):
        if (i + 1) == b_i:
            candidate.append(i)
    if 0 == len(candidate):
        print(-1)
        exit(0)
    c.append(b[candidate[-1]])
    b.pop(candidate[-1])

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

c.reverse()
print(c)

Submission status: Wrong Answer

Solution code:
def isImpossible(l):
    if(l[0]>1):
        return True
    for i in range(1,len(l)):
        if(l[i]-1>i):
            return True
    
    return False

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

fail = False
rese = []
if(max(l)>len(l) or l[0]!=1):
    print(-1)
elif(isImpossible(l)):
    print(-1)
else:
    ope = 0
    l = l[::-1]
    k = []
    res = []
    i = 0

    pedaco = 0
    
    while len(l)>0:
        ope+=1
        while k != [] and pedaco == 0:
            i = 0
            z = min(k)
            if(z<=len(res)+1):
                while(rese != []):
                    res.append(min(rese))
                    del(rese[rese.index(min(rese))])
                res.append(z)
                del(k[k.index(z)])
            else:
                rese = k.copy()
                k = []
        
        if(l[i] == 1):
            
            res.append(l[i])
            del(l[i])
            if(k!=[]):
                l = l[pedaco::]
                pedaco = 0
            i = -1

        else:
            
            k.append(l[i])
            pedaco+=1
            
        i+=1
        
    while k != [] and pedaco == 0:
            z = min(k)
            while(rese != []):
                    res.append(min(rese))
                    del(rese[rese.index(min(rese))])
            res.append(z)
            del(k[k.index(z)])
            
    print("\n".join([str(i) for i in res]))

Submission status: Wrong Answer

Solution code:
def isImpossible(l):
    if(l[0]>1):
        return True
    for i in range(1,len(l)):
        if(l[i]-1>i or l[i-1]+1<l[i]):
            return True
    
    return False

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

fail = False

if(max(l)>len(l) or l[0]!=1):
    print(-1)
elif(isImpossible(l)):
    print(-1)
else:
    ope = 0
    l = l[::-1]
    k = []
    res = []
    i = 0

    pedaco = 0
    
    while len(l)>0:
        ope+=1
        while k != [] and pedaco == 0:
            i = 0
            z = min(k)

            if(z>len(res)+1):
                fail = True
                break
            res.append(z)
            del(k[k.index(z)])

        if(fail):
            break
        
        if(l[i] == 1):
            
            res.append(l[i])
            del(l[i])
            if(k!=[]):
                l = l[pedaco::]
                pedaco = 0
            i = -1

        else:
            
            k.append(l[i])
            pedaco+=1
            
        i+=1
        
    while k != [] and pedaco == 0:
            z = min(k)
            
            if(z>len(res)+1):
                fail = True
                break
            
            res.append(z)
            del(k[k.index(z)])

    if(fail):
        print(-1)
    else:
        print("\n".join([str(i) for i in res]))

Submission status: Wrong Answer

Solution code:
def isImpossible(l):
    for i in l:
        if(i-1>l.index(i)):
            return True
    
    return False


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



if(max(l)>len(l) or l[0]!=1):
    print(-1)
elif(isImpossible(l)):
    print(-1)
else:
    ope = 0
    l = l[::-1]
    k = []
    res = []
    i = 0

    pedaco = 0
    
    while len(l)>0:
        ope+=1
        while k != [] and pedaco == 0:
            i = 0
            res.append(min(k))
            del(k[k.index(min(k))])

        
        if(l[i] == 1):
            
            res.append(l[i])
            del(l[i])
            if(k!=[]):
                l = l[pedaco::]
                pedaco = 0
            i = -1

        else:
            
            k.append(l[i])
            pedaco+=1
            
        i+=1
        
    while k != [] and pedaco == 0:
            res.append(min(k))
            del(k[k.index(min(k))])

    
    print("\n".join([str(i) for i in res]))

Submission status: Wrong Answer

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

if(max(l)>len(l) or l[0]!=1):
    print(-1)
else:
    l = l[::-1]
    k = []
    res = []
    i = 0
    t = 0
    while len(l)>0:
        while k != [] and t == 0:
            i = 0
            res.append(min(k))
            del(k[k.index(min(k))])
        if(l[i] == 1):
            res.append(l[i])
            del(l[i])
            if(k!=[]):
                l = l[t::]
                t = 0
            i = -1
        else:
            k.append(l[i])
            t+=1
        i+=1
        
    while k != [] and t == 0:
            res.append(min(k))
            del(k[k.index(min(k))])
    print("\n".join([str(i) for i in res]))

Submission status: Wrong Answer

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

a=[]
br=0
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:
            br=1
            break
    if br:
        print(-1)
        break

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

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=[0]
ans=[]
for b in B:
  A.insert(b,b)
  
for i in range(N):
  tmp=0
  for j in range(len(A)):
    if j==A[j]:
      tmp=j
  if tmp!=0:
    del A[tmp]
    ans.insert(0,tmp)
    
if A==[0]:
  for a in ans:
    print(a)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
"""
A - Limited Insertion
"""
import numpy as np

N = input()
b_list = list(map(int, input().split()))
# N = 9
# b_list = [1, 1, 1, 2, 2, 1, 2, 3, 2]
# b_list = [1,1,1,2,2,1,2,3,2]
# b_list = [1,1,3,1,2]
# b_list = [2,2]


def make_idx(tmp_list):
    idx_list = np.arange(1, len(tmp_list)+1, 1)[::-1]
    return idx_list

b_list = b_list[::-1]
idx_list = make_idx(b_list)
rm_list = []

while len(b_list):
    for idx, b in zip(idx_list, b_list):
        if idx==b:
            b_list = b_list[::-1]
            b_list.remove(b)
            rm_list.append(b)
            b_list = b_list[::-1]
            break
        elif idx-b<0:
            print(-1)
#             exit()
    idx_list = make_idx(b_list)
    
print(rm_list[::-1])

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b.sort()
flag = True
for _ in range(n):
    add = 0
    for j in range(1, len(b)+1):
        if j == b[j-1]:
            add = max(add, j)
    if add == 0:
        flag = False
        break
    a.append(add)
    del b[add-1]
if flag:
    for i in range(len(a)):
        print(a[-i-1])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import sys
n = int(input())
a = []
b = list(map(int, input().split()))
flag = True
for _ in range(n):
    add = 0
    for j in range(1, len(b)+1):
        if j == b[j-1]:
            add = max(add, j)
    if add == 0:
        flag = False
        break
    a.append(add)
    del b[add-1]
if flag:
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

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

for j in range(n):
    for i in range(9, 0, -1):
        try:
            if b[i-1] == i:
                b.pop(i-1)
                ans.append(i)
                break
        except: pass 
            
if len(b) == 0:
    [print(ans[-i-1]) for i in range(n)]
else:
    print(-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
b=[int(i) for i in input().split()]
 
c = copy.copy(b) #コピーを行う
a = [0]*N
a_n = N-1
 
for n in range(N)[::-1]:#N桁
  for i in range(min(len(c),9))[::-1]:#大きい数字からcheck
    if c[i]==i+1:
      a[a_n] = c.pop(i)
      #print(c,len(c))
      a_n = a_n-1
      break#このbreakに気づかなかったので、2を取り除いたあとに1も取り除いてしまった
 
if n-1 != a_n:
  print(-1)
  exit()
else:
  for i in range(N):
    print(a[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
ans = []
for i in range(len(b)):
    for j in reversed(range(len(b))):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            break

print('\n'.join(map(str, reversed(ans))))

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
ans = []
for i in range(len(b)):
    print(b)
    for j in reversed(range(len(b))):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            break

print('\n'.join(map(str, reversed(ans))))

Submission status: Wrong Answer

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

ans = []
while(True):
    if len(b) == 0:
        print(*ans,sep="\n")
        break
    for i in range(len(b)-1,-1,-1):
        if b[i] == i+1:
            ans.append(b.pop(i))
            break
    else:
        print(-1)

Submission status: Wrong Answer

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

c = copy.copy(b) #コピーを行う
a = [0]*N
a_n = N-1

for n in range(N)[::-1]:#N桁
  for i in range(min(len(c),9))[::-1]:#大きい数字からcheck
    if c[i]==i+1:
      a[a_n] = c.pop(i)
#      print(c,len(c))
      a_n = a_n-1
      break#このbreakに気づかなかったので、2を取り除いたあとに1も取り除いてしまった

  if n-1 != a_n:
    print(-1)
    exit()
    
for i in range(N):
  print(a[i])

Submission status: Wrong Answer

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

for i in range(N):
  if b[i] > i:
    ans = [-1]
    break
  ans.insert(b[i] - 1, b[i])

for a in ans:
  print(ans)

Submission status: Wrong Answer

Solution code:
INF = 999999999999999999L
EPS = 1e-12

def read():
    return raw_input().strip()

def read_ints():
    return map(int,read().split())

n = int(read())
arr = read_ints()

ans = []

def solve(arr):
    if len(arr) == 0:
        return 
        
    # print arr 
    x = min(arr)
    pos = [i for i in range(len(arr)) if arr[i] == x]
    pos.append(len(arr))
    
    for i in reversed(range(len(pos)-1)):
        ans.append(arr[pos[i]])
        l = pos[i]+1 
        r = pos[i+1]
        solve(arr[l:r])
        
        
solve(arr)

# print ans 

res = []
for i in range(len(ans)):
    if ans[i] > i+1:
        break 
    else:
        res.insert(ans[i]-1, ans[i])
        
# print res 
        
if res == arr:
    print " ".join(map(str,ans))
else:
    print -1

Submission status: Wrong Answer

Solution code:
N = int(input())
list_b = list(map(int, input().split()))
ans = [0 for i in range(N)]

finish = False

for i in range(N-1, -1, -1):
  mx = -1
  for k in range(i+1):
    if list_b[k] == k+1:
      mx = k+1
  if mx == -1:
    finish = True
    break
  else:
    ans[i] = mx
    for j in range(mx-1, i):
      list_b[j] = list_b[j+1]
  print(list_b)
    
if not finish:
    for i in range(N):
        print(ans[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
b=[int(i) for i in input().split()]
A=False
a=[]
for _ in range(N):
  ans=0
  for j in range(len(b)):
    if j+1==b[j]:
      ans=max(ans,j+1)
      A=True
    else:
      A=False
      break
  a.append(ans)
  del b[ans-1]
    
a=a[::-1]
if A:
  for i in a:
    print(i)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    if i+1 < a[i]:
        print(-1)
        exit()
ans = []
tmp = []
for i in range(n):
    tmp.append(a[i])
    if i+1 == n or a[i+1] ==1:
        tmp.sort()
        ans.extend(tmp[::-1])
        tmp = []
ans = ans[::-1]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split());b=[0]*n
for i in a:b.insert(i-1,i)
if sum(b[:n])>sum(a):print(-1)
else:
 for i in range(n):print(b[i])

Submission status: Wrong Answer

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

    # check
    counter = 1
    is_ok = True
    for i, v in enumerate(b):
        if counter < v:
            is_ok = False
            break
        else:
            counter += 1

    if is_ok is False:
        print("-1")
        return 0

    # ready
    read_list = []
    b.reverse()
    revd_b = b

    for i, v in enumerate(revd_b):
        counter = 0
        if i == (len(revd_b) - 1):
            break

        for j in range(0, i + 1):
            if revd_b[j] <= v:
                counter += 1

        read_list.append(v + counter - 1)

    read_list.append(N + 1)

    # insertion
    print_list = []
    print_list.append(1)
    counter = 2

    len_b = len(b)
    while True:
        if (counter - 1) >= len_b:
            break

        for i_counter, v in enumerate(read_list):
            if v <= counter:
                print_list.append(revd_b[i_counter])
                del revd_b[i_counter]
                del read_list[i_counter]
                counter += 1
                break

    print(' '.join(map(str, print_list)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

a=[]
start=0
end=0
j=0
try:
    while True:
        if len(b) == 0:
            a.reverse()
            for ai in a:
                print(ai)
            exit(0)
        if j == len(b) or j > b[j]-1:
            j = j-1
            if j != b[j]-1:
                print(-1)
                exit(0)
            a.append(b[j])
            del b[j]
            j=0
        elif j == b[j]-1:
            j = j+1
        else:
            print(-1)
            exit(0)
except:
    print(-1)

Submission status: Wrong Answer

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

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

a=[]
start=0
end=0
j=0
try:
    while True:
        if len(b) == 0:
            a.reverse()
            for ai in a:
                print(ai)
            break
        if j == len(b) or j > b[j]-1:
            j = j-1
            if j != b[j]-1:
                print(-1)
                break
            a.append(b[j])
            del b[j]
            j=0
        elif j == b[j]-1:
            j = j+1
        else:
            print(-1)
            break
except:
    print(-1)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
N = input()
B = list(map(int,input().split()))[::-1]
ans = []
current = []
rest = 0
def check_end(i):
    if i==len(B)-1:
        return True
    elif B[i] <= B[i+1]:
        return True
    else:
        return False
for i in range(len(B)):


    if rest == B[i]:
        rest -= 1
    else:
        current.append(B[i])
    if check_end(i):
        if rest == 0:
            rest = B[i]-1
            for j in range (1,B[i]):
                current.append(B[i]-j)
        ans.extend(current[::-1])
        current = []
if rest > 0:
    print (-1)
else:
    for a in ans:    
        print (a)

Submission status: Wrong Answer

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

b.reverse()
ans = []
disable = False
n = 0
for i in range(N):
  for j in range(len(b)):
    if b[j] == j + 1 + n:
      ans.append(b.pop(j))
      break
    if j == len(b) - 1:
      disable = True
      ans = [-1]
      break
  n += 1
  if disable:
    break

for a in ans:
  print(a)

Submission status: Wrong Answer

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

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

a=[]
start=0
end=0
j=0
try:
    while True:
        if len(b) == 0:
            a.reverse()
            for ai in a:
                print(ai)
            break
        if j == len(b) or j != b[j]-1:
            j = j-1
            if j != b[j]-1:
                break
            a.append(b[j])
            del b[j]
            j=0
        else:
            j = j+1
except:
    print(-1)
print(-1)

Submission status: Wrong Answer

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

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

a=[]
start=0
end=0
j=0
try:
    while True:
        if len(b) == 0:
            a.reverse()
            for ai in a:
                print(ai)
            break
        if j == len(b) or j != b[j]-1:
            j = j-1
            if j != b[j]:
                break
            a.append(b[j])
            del b[j]
            j=0
        else:
            j = j+1
except:
    print(-1)
print(-1)

Submission status: Wrong Answer

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

b.reverse()
ans = []
disable = False

for i in range(N):
  for j in range(len(b)):
    if b[j] == j + 1:
      ans.append(b.pop(j))
      break
    if j == len(b) - 1:
      disable = True
      ans = [-1]
      break
  if disable:
    break

for a in ans:
  print(a)

Submission status: Wrong Answer

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

  for i in range(N - 1, -1, -1):
    v = -1
    for j in range(i + 1):
      if B[j] == j + 1: v = j
    if v == -1: return '-1'
    ans[i] = v + 1
    B.pop(v)
  return ans

print(solve(), sep='\n')

Submission status: Wrong Answer

Solution code:
def check(X):
	#print(X,len(X))
	if(len(X)==1):
		if(X==[1]):
			return [1]
		else:
			return [-1]
	for i in range(len(X)):
		if(X[i]==i+1):
			c=check(X[:i]+X[i+1:])
			if(c!=[-1]):
				return c+[i+1]
	return [-1]



N=int(input())
B=input().split(" ")
B=[int(b) for b in B]

print(check(B))

Submission status: Wrong Answer

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

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

a=[]
start=0
end=0
j=0
if b[0] > 1:
    print(-1)
    exit()

try:
    while True:
        if len(b) == 0:
            a.reverse()
            for ai in a:
                print(ai)
            break
        if j == len(b) or j != b[j]-1:
            j = j-1
            a.append(b[j])
            del b[j]
            j=0
        else:
            j = j+1
except:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=[]
count=0
while len(b)>0:
  count+=1
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(b.pop(i-1))
  if count==101:
    print(-1)
    exit()
ans.reverse()
for i in range(n):
  print(ans[i])

Submission status: Wrong Answer

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

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

a=[]
start=0
end=0
j=0
if b[0] > 1:
    print(-1)
    exit()

try:
    while True:
        if len(b) == 0:
            a.reverse()
            for ai in a:
                print(ai)
            break
        if j == len(b) or j != b[j]-1:
            j = j-1
            a.append(b[j])
            del b[j]
            print("del", j)
            j=0
        else:
            j = j+1
            print("next")
        print(b, a)
except:
    print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

  for i in range(N - 1, -1, -1):
    v = -1
    for j in range(i + 1):
      if B[j] == j + 1: v = max(v, j + 1)
    if v == -1: return '-1'
    ans[i] = v
    B.pop(v - 1)
  return '\n'.join(map(str, reversed(ans)))

print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
while len(b) >= 1:
    m = b.index(max(b))
    if max(b) - 1 == m:
        print(max(b))
        b = b[0:m] + b[m+1::]
    else:
        print(-1)
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
while len(b) >= 1:
    m = b.index(max(b))
    if max(b) - 1 == m:
        print(b[m])
        b = b[0:m] + b[m+1::]
    else:
        print(-1)
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
while len(b) >= 1:
    m = b.index(max(b))
    if max(b) - 1 == m:
        print(b[m])
        b = b[0:m] + b[m+1::]
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import sys
n = int(input())
a = []
b = list(map(int, input().split()))
for i in range(len(b)):
    c = b[:i+1]
    if i+1 == c[-1]:
        a.append(c[-1])
if len(a) == len(b):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

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

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

print(solve())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import itertools
icchi = []
jlists = list(range(N))
jj = list(itertools.permutations(jlists))

for jlist in jj:
    a = []
    result = []
    for j in jlist:
        if len(a)>=b[j]-1:
            a.insert(j, b[j])
            result.append(b[j])
    if a == b:
        icchi.append('一致')
        for k in range(N):
            print(result[k])
        break

if len(icchi) == 0:
    print(-1)