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

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

A=np.array(A)

global flg
global res

flg=0
res=[0]*N

def test(A):
    if A.shape[0]==1:
        if A[0]==1:
            res[0]=1
            flg=1
            return 1
        else:
            return 0
    else:
        B=np.arange(len(A))+1
        C=max((A==B)*B)
        if C==0:
            return 0
        else:
            res[len(A)-1]=C
            test(np.delete(A,C-1,0))

Submission status: Wrong Answer

Solution code:
N=int(input())
BBB=[int(x) for x in input().split()]
 
BB=[0 for i in range(N)]
def re(B,n):
  global BB
  if n==1:
    if B[0]!=1:
      return 
    BB[0]=B[0]
    for i in BB:
      print(i)
    exit()
  for i in range(n):
    if B[i]>i+1:
      return 1
    if B[i]==i+1:
      BB[n-1]=B[i]
      re(B[:i]+B[i+1:n],n-1)
  print(-1)
 
re(BBB,N)

Submission status: Wrong Answer

Solution code:
N=int(input())
BBB=[int(x) for x in input().split()]
 
BB=[0 for i in range(N)]
def re(B,n):
  global BB
  if n==1:
    if B[0]!=1:
      print(-1)
      exit()
    BB[0]=B[0]
    for i in BB:
      print(i)
    exit()
  for i in range(n):
    if B[i]>i+1:
      return 1
    if B[i]==i+1:
      BB[n-1]=B[i]
      re(B[:i]+B[i+1:n],n-1)
  print(-1)
 
re(BBB,N)

Submission status: Wrong Answer

Solution code:
N=int(input())
BBB=[int(x) for x in input().split()]
BB=[0 for i in range(N)]
def re(B,n):
  global BB
  if n==1:
    if B[0]!=1:
      print(-1)
      exit()
    BB[0]=B[0]
    for i in BB:
      print(i)
    exit()
  for i in range(n):
    if B[i]>i+1:
      return -1
    if B[i]==i+1:
      BB[n-1]=B[i]
      re(B[:i]+B[i+1:n],n-1)
  return -1
 
result=re(BBB,N)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def dfs(A, already_use, value_list, vi):
    li = []
    for i in range(len(A)):
        if already_use[i] == True:
            break
        if A[i] == value_list[vi] :
            li.append(i)
    for i in range(len(li) - 1, -1, -1):
        print value_list[vi]
        already_use[li[i]] = True
        dfs(A[li[i] + 1:],  already_use[li[i] + 1:], value_list, vi + 1)


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    value_list = list(set(A))
    value_list.sort()

    for i in range(len(A)):
        if i +1 < A[i]:
            print -1
            return
    already_use = [False for i in range(N)]
    dfs(A, already_use, value_list, 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
B = [int(i) for i in input().split(" ")]
if B[0] != 1:
    print("-1")
    exit()
subseq = []
state = []
A = []
for i in range(N)[::-1]:
    if len(state) <= 1 or state[-1] >= B[i]:
        if i+1 < N and B[i] == B[i+1]:
            subseq.append(B[i])
        else:
            state.append(B[i])
        if len(A) + len(state) + len(subseq) == N:
            state.sort()
            subseq.sort(reverse=True)
            for j in range(len(state)):
                if  state[j] > j + 1:
                    for k in range(len(subseq)):
                        state.append(subseq[0]).sort()
                        subseq = subseq[1::]
                        if  state[j] <= j + 1:
                            break
                    if  state[j] > j + 1:
                        print("-1")
                        exit()
            A += state + subseq
            state = [B[i]]
            subseq = []
    else :
        state.sort()
        subseq.sort(reverse=True)
        for j in range(len(state)):
            if  state[j] > j + 1:
                for k in range(len(subseq)):
                    state.append(subseq[0]).sort()
                    subseq = subseq[1::]
                    if  state[j] <= j + 1:
                        break
                if  state[j] > j + 1:
                    print("-1")
                    exit()
        A += state + subseq
        state = [B[i]]
        subseq = []
for i in A:
    print(str(i))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = list(input())
while ' ' in b[:]:
    b.remove(' ')
b_cp = b[:]
b_cp.sort(reverse=True)
ans = ['*' for i in range(N)]

for _ in range(N):
    max = b_cp[0]
    idx = b.index(max)
    shift = idx + 1 - int(max)
    k = N-1
    while True:
        if k < 0:
            print(-1)
            sys.exit()
        cnt = 0
        inc = max
        for l in range(k+1, N):
            if ans[l] == '*' or int(ans[l]) <= int(inc):
                cnt += 1
                if not int(inc) == N:
                    inc = str(int(inc)+1)
        if cnt == shift and ans[k] == '*':
            break
        k -= 1
    ans[k] = max
    b_cp.pop(0)
    b[idx] = '*'

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(str, input().split()))
''.join(b)
ans = []
def dfs(b):
    if len(b) == 1:
        if int(b[0]) == 1:
            return True
    else:
        f = 0
        for j in range(len(b)):
            if int(b[j]) == j + 1:
                f += 1
            else:
                break
        if f == len(b):
            for j in range(len(b)):
                ans.append(b[j])
            return True

        for i in range(len(b) - 1, -1, -1):
            if int(b[i]) == i + 1:
                if i == 0:
                    if dfs(b[1:]):
                        ans.append(i + 1)
                        return True
                else:
                    if dfs(b[:i] + b[i+1:]):
                        ans.append(i + 1)
                        return True
        return False
if dfs(b):
    ans.insert(0, 1)
    for i in range(len(ans)):
        print(ans[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# 2019/03/23
# AtCoder Grand Contest 032 - A

# Input
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
anslist = list()


ans = 0

# Possible Check
for idx in range(n):
    if b[idx] > (idx + 1):
        ans = -1
        print(ans)
        break

# fixcnt = 0 // (n-1) - idx2
# Make list
if ans == 0:
    fixcnt = 0
    # Loop from n-1, to -1, by -1
    for idx2 in range(n-1, -1, -1):
        if a[idx2] == 0:
            if b[idx2] <= fixcnt + 1:
                a[idx2] = b[idx2]
                anslist.append(b[idx2])
            else:
                for idx3 in range(idx2-1, -1, -1):
                    if b[idx3] <= fixcnt + 1:
                        a[idx3] = b[idx3]
                        anslist.append(b[idx3])
                        fixcnt += 1
                        break
                anslist.append(b[idx2])
                a[idx2] = b[idx2]
            fixcnt += 1

    for idx4 in range(n):
        print(anslist[idx4])

Submission status: Wrong Answer

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

s = []


if b[0] == 1:
    for i in range(0, len(b)-1):
        a = b[i]
        if b[i] == b[i+1]:
            s.append(b[i])
        if b[i]+1 < b[i]:
            print(-1)
            break
        if b[i] > b[i+1]:
            for j in range(b[i], b[i+1]-1, -1):
                s.append(j)
            a = b[i+1] 
                
    for i in range(a,0,-1):
        s.append(i)            
    
    
    for i in range(len(s)-1,-1, -1):
        print(s[i])

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = list(input())
while ' ' in b[:]:
    b.remove(' ')
b_cp = b[:]
b_cp.sort(reverse=True)
ans = ['*' for i in range(N)]

for _ in range(N):
    max = b_cp[0]
    idx = b.index(max)
    shift = idx + 1 - int(max)
    k = N-1
    while True:
        if k < 0:
            print(-1)
            sys.exit()
        cnt = 0
        inc = max
        for l in range(k+1, N):
            if ans[l] == '*' or int(ans[l]) <= int(inc):
                cnt += 1
                if not int(inc) == N:
                    inc = str(int(max)+1)
        if cnt == shift and ans[k] == '*':
            break
        k -= 1
    ans[k] = max
    b_cp.pop(0)
    b[idx] = '*'

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:


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

    # check
    for i, b in enumerate(B):
        if b > i+1:
            print('-1')
            return

    nums = []

    for i in range(N):
        num_esmall = 0
        for j in range(i+1, N):
            num_esmall += int(B[i] >= B[j])
        nums.append(num_esmall + B[i] - 1)

    orders = [-1] * N
    for i in range(N):
        for jj in range(N):
            j = N - jj - 1
            if nums[j] <= i and orders[j] == -1:
                orders[j] = i + 1
                break

    b_o = [[b, o] for b, o in zip(B, orders)]
    b_o = sorted(b_o, key=lambda x: x[1])
    ans = [b for b, o in b_o]
    for a in ans:
        print(a)

main()

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
    for j in range(N-i):
        if b[i+j] > b[i] + j:
            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())
b = list(map(int, input().split()))

used = [False for i in range(N)]

ans = []
for i in range(N-1, -1, -1):
    if used[i]:
        continue
    s = b[i]
    t = []
    for j in range(i, -1, -1):
        if s == 0 or used[j]:
            break
        if s == b[j]:
            used[j] = True
            t.append(b[j])
            s -= 1
    for x in t[::-1]:
        ans.append(x)

if len(ans) != N:
    print(-1)
    exit()

for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b_list = list(map(int, input().split()))
rev_b = reversed(b_list)

for i, b in enumerate(b_list):
    i += 1
    if i < b:
        print(-1)
        exit()

ans = [-1] * N
ans[0] = 1

for i, b in enumerate(rev_b):
    i += 1
    if i == N:
        continue

    if b == 1 or b == 2:
        if ans[i] == -1:
            ans[i] = b
        else:
            for j, a in enumerate(ans):
                if a == -1:
                    ans[j] = b
                    break

    else:
        if 0 <= i + b - 2 < N:
            ans[i + b - 2] = b
        else:
            print(-1)
            exit()
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=1
if b[0] > 1:
    print(-1)
    exit()

try:
    while True:
        if len(b) == j:
            a.append(b[0])
            del b[0]
            break

        if j != b[j]-1:
            j = j-1
            a.append(b[j])
            del b[j]
        else:
            j = j+1

    if len(a) == N:
        a.reverse()
        for ai in a:
            print(ai)
    else:
        print(-1)
except:
    print(-1)

Submission status: Wrong Answer

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

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())
b_list = list(map(int, input().split()))
rev_b = reversed(b_list)

for i, b in enumerate(b_list):
    i += 1
    if i < b:
        print(-1)
        exit()

ans = [-1] * N
ans[0] = 1

for i, b in enumerate(rev_b):
    i += 1
    if i == N:
        continue

    if b == 1 or b == 2:
        if ans[i] == -1:
            ans[i] = b
        else:
            for j, a in enumerate(ans):
                if a == -1:
                    ans[j] = b
                    break

    else:
        if 0 <= i + b - 2 < N:
            for j in range(i + b - 2, N):
                if ans[j] == -1:
                    ans[j] = b
                    break
        else:
            print(-1)
            exit()
for a in ans:
    print(a)

Submission status: Wrong Answer

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

def step(a,c):
    return a[:c-1:]+[c]+a[c-1::]

def create_a(command):
    a=[]
    for c in command:
        if len(a)+1<c:
            return False
        a=step(a,c)
    return a


def creatable(b):
    if b==[1]:
        return True,[1]
    if len(b)==1:
        return False,[1]

    judge=False
    history=[]
    for i in range(len(b)):
        if b[i]==i+1:
            judge,history=creatable(b[:i:]+b[i+1::])
            if judge:
                history.append(i+1)
        else:
            continue
        if judge:
            break
    return judge,history



#judge,history=creatable(b)

for i in range(100000):
    _b=copy.copy(b)
    random.shuffle(_b)
    if create_a(_b)==b:
        for c in _b:
            print(c)
        sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def checkJ(lst):
    good_jlist = []
    for i in range(len(lst)):
        if lst[len(lst) - i-1] == len(lst) - i:
            good_jlist.append(len(lst) -  i -1)
    return good_jlist

def subJ(lst, j):
    return lst[:j] + lst[j+1:]

n = int(input())
s = [int(i) for i in input().split()]
stack_list = []
stack_list.append([s,checkJ(s)])
notfound = 0
applylist= []
while True:
#     調べる番号がない場合
    if not stack_list[0][0]:
        notfound = 2
        break
    while not stack_list[0][1]:
        stack_list.pop(0)
        if not stack_list:
            notfound = 1
            break
        if not stack_list[0][0]:
            notfound = 2
            break
        
#     調べるリストがない場合
    if notfound == 1 or notfound == 2:
        break
    
    currentStr = stack_list[0][0]
    applylist = applylist[:int(int(n) - len(currentStr))]
    currentCheckNum = stack_list[0][1].pop(0)
    if currentCheckNum == 0 and len(currentStr) > 1:
        continue
    nextStr = subJ(currentStr,currentCheckNum)
    if checkJ(s):
        stack_list.insert(0,[nextStr,checkJ(nextStr)])
    applylist.append(currentCheckNum + 1)
#     print("current list")
#     print(stack_list)
if notfound == 1:
    print("-1")
elif notfound == 2:
    for i in range(len(applylist)):
        print(applylist[int(n)-i-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=1
if b[0] > 1:
    print(-1)
    exit(0)

try:
    while True:
        if len(b) == j:
            a.append(b[0])
            del b[0]
            break

        if j != b[j]-1:
            j = j-1
            a.append(b[j])
            del b[j]
        else:
            j = j+1

    if len(a) == N:
        a.reverse()
        for ai in a:
            print(ai)
    else:
        print(-1)
except:
    print(-1)

Submission status: Wrong Answer

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

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

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

    ans = [0 for i in range(n)]
    for i in range(n-1,-1,-1):
        count=0
        if i!=n-1:
            for j in b[i+1:]:
                if b[i] >= j:
                    count+=1
        ind = count + b[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:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def dfs(A, x, already_use):
    li = []
    for i in range(len(A)):
        if already_use[i] == True:
            break
        if A[i] == x :
            li.append(i)
    for i in range(len(li) - 1, -1, -1):
        print x
        already_use[li[i]] = True
        dfs(A[li[i] + 1:], x + 1, already_use[li[i] + 1:])


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    for i in range(len(A)):
        if i +1 < A[i]:
            print -1
            return
    already_use = [False for i in range(N)]
    dfs(A, 1, already_use)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(str, input().split()))
''.join(b)
ans = []
def dfs(b):
    if len(b) == 1:
        if int(b[0]) == 1:
            return True
    else:
        f = 0
        for j in range(len(b)):
            if int(b[j]) != j + 1:
                f = 1
                break
        if f == 0:
            for j in range(len(b)):
                ans.append(b[j])
            return True

        for i in range(len(b) - 1, -1, -1):
            if int(b[i]) == i + 1:
                if i == 0:
                    if dfs(b[1:]):
                        ans.append(i + 1)
                        return True
                else:
                    if dfs(b[:i] + b[i+1:]):
                        ans.append(i + 1)
                        return True
        return False
if dfs(b):
    ans.insert(0, 1)
    for i in range(len(ans)):
        print(ans[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# cording=utf-8

num = int(input())
edge = num-1

if edge % 2 == 1:
    edge -= 1

print(edge)
for i in range(1,edge+1):
    ans = num - i
    print(str(ans) + " " + str(num))

Submission status: Wrong Answer

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

used = [False for i in range(N)]

ans = []
for i in range(N-1, -1, -1):
    if used[i]:
        continue
    s = b[i]
    t = []
    for j in range(i, -1, -1):
        if s == 0:
            break
        if s == b[j]:
            used[j] = True
            t.append(b[j])
            s -= 1
    for x in t[::-1]:
        ans.append(x)

for i in range(N):
    print(ans[i])

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=[]
  else:
    l2.append(x)
if n!=len(l3):
  print(-1)
  exit()
lx=[]
b=''
for x in l3:
  if b==x:
    lx.append(x)
  b=x
  print(x)
lx.sort()
lx.reverse()
for x in lx:
  print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

def main():
    a = []
    b = np.random.randint(1,N+1,N)# ある区間内のランダムな整数を返す関数

    for i in range(1,N+1):    
        #print(np.random.random_integers(i))
        a.append(np.random.randint(i)+1)

    a = np.array(a)
    b = np.array(b)
    #print(a)
    #print(b)

    if (a == b).all():
        print(list(a))
    else:
        print('-1')
    return 

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


for i, b in enumerate(B, start=1):
  if b > i:
    print(-1)
    exit()


bnn = collections.defaultdict(
  lambda: collections.defaultdict(dict)
)
def inv_sousa(B, N, now=tuple()):
  if N == 0 or max(B) > N:
    yield now
  else:
    s_now = tuple(sorted(now))
    if s_now in bnn[B][N] or max(B) > N:
      return
    bnn[B][N][s_now] = False

    N -= 1
    for i in set(B):
      idx = i - 1
      if B[idx] == i:
        yield from inv_sousa(B[:idx] + B[i:], N , now=now + (B[idx],))


for x in inv_sousa(tuple(B), N):
  if x:
    for i in x[::-1]:
      print(i)
    break
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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

ans = [0]*(N+1)
right = [0]
for i in range(N):
    b = B[i]
    if b > i+1:
        print(-1)
        sys.exit()


# import pdb;pdb.set_trace()
for i in range(N):
    b = B[N-i-1]
    if b<max(right) and b>min(right):
        count = 0
        for s in right:
            if s == b:
                count += 1
        ans[b+count] = b
        right.insert(0,b)

    elif b <= min(right):
        count = 0
        for s in right:
            if s == b:
                count += 1
        ans[b+count] = b
        right.insert(0,b)
    elif b >= max(right):
        if right[0] == 0:
            ans[b] = b
            right[0] = b
            continue
        temp = right[0] + 2
        ans[temp] = b
        right.insert(0, b)

for i in range(N):
    print(ans[i+1])

Submission status: Wrong Answer

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


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


b_searched = set()
b_unsearched = []


b_searched.add(tuple(b))
delit = delitable(b)

if delit == []:
    print("-1")
for delit_num in delit:
    b_unsearched.append([b[:delit_num - 1] + b[delit_num:], [delit_num]])


while b_unsearched:
    b, log = b_unsearched.pop()
    if max(b) > N - len(log) - 1:
        continue
        
    b_tuple = tuple(b)
    b_searched.add(b_tuple)
    delit = delitable(b)


    if not delit:
        if not b:
            log.reverse()
            print("\n".join(map(str, log)))
            break
        else:
            continue
    for delit_num in delit:
        b_temp = b[:delit_num - 1] + b[delit_num:]
        if not tuple(b_temp) in b_searched:
            b_unsearched.append([b_temp, log + [delit_num]])
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)
		
		keep.sort()
		tmp = []
		for j, val in enumerate(keep):
			#print(keep)
			#print(val)
			if val <= len(ans):
				ans.append(val)
				#keep.remove(val)
	
	for vol in ans:
		print(vol)
			
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))
sa=[i-b[i-1] for i in range(1,N+1)]
ans=[0 for i in range(N)]#k番目にans[k-1]が入ったよの表
for i in reversed(range(1,N+1)):#頭からi番目
    cnt=0
    for j in range(1,N+1):
        if ans[-1*j]==0:
            if cnt!=sa[i-1]:
                cnt+=1
            else:
                ans[-1*j]=b[i-1]
if all(k!=0 for k in ans):
    for i in ans:
        print(i)
else:
    print("-1")

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:
        for j in range(N-i):
            if b[i+j] > j+1:
                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:
# 2019/03/23
# AtCoder Grand Contest 032 - A

# Input
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
anslist = list()


ans = 0

# Possible Check
for idx in range(n):
    if b[idx] > (idx + 1):
        ans = -1
        break

# fixcnt = 0 // (n-1) - idx2
# Make list
if ans == 0:
    fixcnt = 0
    # Loop from n-1, to -1, by -1
    for idx2 in range(n-1, -1, -1):
        if a[idx2] == 0:
            if b[idx2] <= fixcnt + 1:
                a[idx2] = b[idx2]
                anslist.append(b[idx2])
            else:
                for idx3 in range(idx2-1, -1, -1):
                    if b[idx3] <= fixcnt + 1:
                        a[idx3] = b[idx3]
                        anslist.append(b[idx3])
                        fixcnt += 1
                        break
                anslist.append(b[idx2])
                a[idx2] = b[idx2]
            fixcnt += 1

    for idx4 in range(n):
        print(anslist[idx4])

Submission status: Wrong Answer

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

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

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

n = int_raw()
bs = ints_raw()

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

    for a in ans:
        print a
 
sol()

Submission status: Wrong Answer

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

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

for i, x in enumerate(xs):
    i = i+1
    if x > i:
        print(-1)
        sys.exit()
    if x not in xp:
        xp[x] = list()
    xp[x].append(i)

x = max(xs)
last = len(xs)
xo = []
xx = set()

while True:
    if x == 0:
        break
    nxx = set()
    if x in xp:
        for i in xp[x]:
            xxx = zur(x + last - i, xx)
            xo.append((xxx, x))
            nxx.add(xxx)
        last -= len(xp[x])
    xx = nxx | xx
    x -= 1

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

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()
c = 0
f = 0
for i in range(n-2):
    if a[-(i+1)] <= a[-(i+2)]:
        c = 1
    if a[-(i+1)] > a[-(i+2)] and a[-(i+1)] != 1 and a[-(i+2)] != 1 and c == 1 and f == 0:
        p = a[-(i+1)]
        a[-(i+1)] = a[-(i+2)]
        a[-(i+2)] = p
        f += 1
    else:
        if f > 0:
            f -= 1
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()))

ANS = []


def create(i):
    ans = [B[i]]
    while (i + 1) < N and (B[i] < B[i + 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:
import numpy as np

N = int(input())

def main():
    a = []
    b = np.random.randint(1,N+1,N)# ある区間内のランダムな整数を返す関数

    for i in range(1,N+1):    
        #print(np.random.random_integers(i))
        a.append(np.random.randint(i)+1)

    a = np.array(a)
    b = np.array(b)
    #print(a)
    #print(b)

    if (a == b).all():
        print(True)
    else:
        print(False)
    return 

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

n = ni()
b = na()

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

c = sorted(b)

for i in range(1,n):
  if c[i]-c[i-1] > 1 or c[i]-c[i-1] < 0:
    print('-1')
    sys.exit()

b.reverse()

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

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

for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

def main():
    a = []
    b = np.random.randint(1,N+1,N)

    for i in range(1,N+1):    
        a.append(np.random.randint(i)+1)

    a = np.array(a)
    b = np.array(b)

    print(a)
    print(b)

    if (a == b).all():
        print(True)
    else:
        print(False)
    return 

if __name__ == '__main__':
    main()