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: Runtime Error

Solution code:
from sys import stdin, stdout
from math import sqrt, pi, acos, gcd, atan2, cos, sin, factorial
from decimal import Decimal
from random import randint
from matplotlib import mlab
from matplotlib import pylab
PEPS = 1e-10
INF = float('inf')


def sqr(a):
    return a * a


def dist(a, b = (0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def s_dist(a, b = (0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def dist3(a, b = (0, 0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def s_dist3(a, b = (0, 0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def trans(p, al):
    return (p[0] * cos(al) + p[1] * sin(al), - p[0] * sin(al) + p[1] * cos(al))


def get_angle(a, b, c):
    cos_al = (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b)
    return acos(cos_al)


def write_float(ans):
    stdout.write(str('%.13f' % ans) + '\n')


def get_hight(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt1[0], pt3[1] - pt1[1])
    return abs(a[0] * b[1] - a[1] * b[0]) / dist(pt1, pt2)


def get_square(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt2[0], pt3[1] - pt2[1])
    return (a[0] * b[-1] - a[1] * b[0]) / 2


def sign(v):
    if v > 0:
        return 1
    elif v < 0:
        return -1
    else:
        return 0


def inn(pt, triangle):
    signs = set()
    signs.add(sign(get_square(triangle[0], triangle[1], pt)))
    signs.add(sign(get_square(triangle[1], triangle[2], pt)))
    signs.add(sign(get_square(triangle[2], triangle[0], pt)))
    return len(signs) == 1


def inter_in(a, b):
    return dist((a[0], a[1]), (b[0], b[1])) < a[-1] + b[-1]


def inter_in3(a, b):
    return dist3(a[:-1], b[:-1]) < a[-1] + b[-1]


def shift(what, wth):
    return (what[0] - wth[0], what[1] - wth[1])


n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
ans = []

while len(vl):
    for i in range(len(vl) - 1, -1, -1):
        if vl[i] == i + 1:
            ans.append(i + 1)
            vl = vl[:i] + vl[i + 1:]
            break
    else:
        stdout.write('-1\n')
        break


if len(ans) == n:
    ans = ans[::-1]
    stdout.write(' '.join(list(map(str, ans))))

Submission status: Runtime Error

Solution code:
N = input()
l = input().split()

ret = []
for x in l:
  if x >= len(ret):
    print(-1)
    break
  else:
    ret.insert(x, x)
for x in ret:
  print(x)

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
ans=[]
for i in range(n):
  for j in range(n-1-i,-1,-1):
    if not m[j]==j+1:
      continue
    #m[j]==j
    ans.append(j+1)
    m=m[:j]+m[j+1:]
if not len(m)==0:
  print(-1)
else:
  for i in range(n):
    print(ans[n-1-i])

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
ans=[]
for i in range(n):
  for j in range(n-1-i,-1,-1):
    if not m[j]==j:
      continue
    #m[j]==j
    ans.append(j+1)
    m=m[:j]+m[j+1:]
if not len(m)==0:
  print(-1)
else:
  for i in range(n):
    print(ans[n-1-i])

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
ans=[]
for i in range(n):
  for j in range(i,-1,-1):
    if not m[j]==j:
      continue
    #m[j]==j
    ans.append(j)
    m=m[:j]+m[j+1:]
if not len(m)==0:
  print(-1)
else:
  for i in range(n):
    print(ans[n-1-i])

Submission status: Runtime Error

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

    #出力用
    outs = []

    for i in range(N):
        for k in range(N-1,-1,-1):
            if B[k] == k:
                del B[k]
                outs.append(k)
                break
        else:
            print(-1)
            return

    for out in outs:
        print(out)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

    #出力用
    outs = []

    for i in range(N):
        for k in range(N-1:-1:-1):
            if B[k] == k:
                del B[k]
                outs.append(k)
                break
        else:
            print(-1)
            return

    for out in outs:
        print(out)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
b=[int(i) for i in input().split()]
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)
ordering(N,b)

Submission status: Runtime Error

Solution code:
N=int(input())
b=[int(i) for i in input().split()]
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)
print(ordering(N,b))

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

result = []
while True:
    #  print(b)
    for i in range(1, len(b)+1):
        #  print(i)
        if b[-i] == len(b)-i+1:
            #  print('break')
            result.append(b[-i])
            b.pop(b[-i])
            break
    else:
        if not b:
            break
        print(-1)
        exit()
for i in result[::-1]:
    print(i)

Submission status: Runtime Error

Solution code:
import sys


def main():
    lines = sys.stdin.readlines()
    N = int(lines[0])
    b = [int(i) for i in lines[1].split(' ')]
    a = []
    for i in range(1, N+1):
        max_b = max(b)
        for k in range(max_b, 0, -1):
            if k <= i :
                if b[k-1] == k:
                    print(k)
                    b.pop(k-1)  
                    break
    if len(b) > 0 :
        print(-1)

        
       

        




if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

a = []
index = -1
n = N
while len(b):
    for i in range(n):
        if i+1 == b[i]:
            index = i
    if index > -1:
        a.insert(0, b.pop(index))
        n -= 1

if len(a):
    for e in a:
        print(e)
else:
    print(index)

Submission status: Runtime Error

Solution code:
from collections import deque

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

# 最後に挿入した数字は
# k番目のkとなる

# 1 2 2 1 2 3 2
# 複数通り該当するときは
# 最後の数が該当する
# 0 0 3 0 0 6
# 3を取り除くと
# 0 0 0 0 6 -> 矛盾

ans = deque()

q = deque(enumerate(b, 1))
r = deque()

flg = False
while q:
    idx, bb = q.pop()
    # print(idx, bb, r)
    if idx == bb:
        ans.appendleft(bb)
        if len(ans) == N:
            flg = True
            break
        q = q + r
        r = deque()
    else:
        r.appendleft((idx - 1, bb))

if flg:
    for aa in ans:
        print(aa)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
l=[]
while len(x):
    for i,a in enumerate(x):
        if a==i+1:
            index=i
    l.append(x.pop(index))
for i in reversed(l):
    print(i)

Submission status: Runtime Error

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

if 1 not in b:
    print(-1)
else:
    lst = []
    index = -1
    for i in range(N):
        if b[i] == 1:
            lst.append([])
            index += 1
        lst[index].append(b[i])
            
    flag = False
    ans = []
    if N < max(b):
        print(-1)
    else:
        if len(lst) == 0:
            print(-1)
        else:
            lst.reverse()
            for i in range(len(lst)):
                for j in range(len(lst[i])):
                    if lst[i][j] > j+1:
                        flag = True
                        print(-1)
                        break
                if flag:
                    break
            
            for i in range(len(lst)):
                lst[i].reverse()
                cnt = 1
                while(len(lst[i]) > 0 ):
                    
                    if lst[i][0] <= cnt:
                        ans.append(lst[i].pop(0))
                    else:
                        ans.append(cnt)
        
                        lst[i].reverse()
                        lst[i].pop(lst[i].index(cnt))
                        lst[i].reverse()             
                        
                    cnt += 1
            else:
                print(*ans,sep="\n")

Submission status: Runtime Error

Solution code:
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')
N = int(input())
B = list(map(int,input().split()))

ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')

Submission status: Runtime Error

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 not b and max(b) > N - len(log):
        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: Runtime Error

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):
        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: Runtime Error

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

def func(B,i,C):
    if(C[0:i].count(True) + 1 == B[i]): #左の入力済みを数える
        print(B[i])
        C[i] = True
        next = -1
        for j in range(N-1,-1,-1):
            if C[j] == False:
                next = j
                break
        if next == -1:
            return
        func(B,next,C)
    else:
        next = i - 1
        for j in range(i-1,-1,-1):
            if C[j] == False:
                next = j
                break
        func(B,next,C)

flag = 0
for i in range(N):
    if B[i] > i + 1:
        flag = -1
        break

if(flag == -1):
    print(-1)
else:
    C = [False] * N
    func(B,N-1,C)

Submission status: Runtime Error

Solution code:
n = int(input())
b = list(map(int,input().split()))
c = []
al =False
if isfalse(b)  :
    al = True
    print(-1)
def insertA(m,b,c):
    if m == 1:
        if b[0]==1:
            c.append(1)
            return True
    if max(b) > m//2:
        k = range(m)[::-1]
    else:
        k = range(m)
    for i in k:
        if b[i] == i+1:
            bi = b[:i]+b[i+1:]
            if insertA(m-1,bi,c):
                c.append(i+1)
                return True
                break
            else:
                continue
    
    
insertA(n,b,c)
for i in c:
    print(i)
if al == False and len(c)<n:
    print(-1)
def isfalse(b):
    for i in range(len(b)):
        if b[i]>i+1:
            return True
    return False

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
def zur(z, xx):
    c = 0
    k = 0
    for i in range(z):
        k += 1
        i += 1
        if i not in xx:
            c += 1
        if c == z:
            return k

def xxxxx(z, xx):
    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: Runtime Error

Solution code:
N=int(input())
b=[int(i) for i in input().split()]
a = [0]*N
def dfs(x,n,a): #n桁のx
  if x == []: #Goalで終了
    return True
    
  for xlen in range(min(len(x),9))[::-1]:
    if x[xlen] == xlen+1:
      a[n] = xlen+1
      xx = copy.copy(x)
      xx.pop(xlen)
      return dfs(xx, n-1, a)

  if a[n] == 0:
      return False
if dfs(b,N-1,a):
  for i in range(N):
    print(a[i])
else:
  print(-1)

Submission status: Runtime Error

Solution code:
import random
import sys
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(10000):
    command=random.shuffle(b)
    if create_a(command)==b:
        for c in command:
            print(c)
        sys.exit()
print(-1)

Submission status: Runtime Error

Solution code:
#落ち着くのんな
import sys
input = sys.stdin.readline

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


used = [True]*n
res = [0]*n
for i in range(1,n+1):
    
    for j in range(n-1,-1,-1):
        if b[j] == i:
            res[tank] = i
            tank = cnt + 1
            cnt = 0
        else:
            cnt += 1

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
b = list(map(int, input().split()))
a = {}
out = []

for k in range(N):
  if b[k] > k + 1:
    print(-1)
    sys.exit()

cnt2 = 0
d = {}

for j in reversed(range(1, N)):
  cnt = 0
  for i in range(j+1, N):
    if b[j] >= b[i]:
      cnt += 1
  a[b[j] + cnt - 1] = b[j]
  if b[j] == 1:
    s = []
    for k in reversed(range(len(a))):
      s.append(a[k])
    out.append(s)
    cnt2 = cnt
out = [k for k in reversed(out)]
for k in range(N):
  print(out[k])

Submission status: Runtime Error

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]) != i + 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: Runtime Error

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

def func(B,i,C):
    if(C[0:i].count(True) + 1 >= B[i]): #左の入力済みを数える
        print(B[i])
        C[i] = True
        next = -1
        for j in range(N-1,-1,-1):
            if C[j] == False:
                next = j
                break
        if next == -1:
            return
        func(B,next,C)
    else:
        for next in range(i-1,-1,-1):
            if C[j] == False:
                func(B,next,C)
                break
        

flag = 0
for i in range(N):
    if B[i] > i + 1:
        flag = -1
        break

if(flag == -1):
    print(-1)
else:
    C = [False] * N
    func(B,N-1,C)

Submission status: Runtime Error

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

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

    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: Runtime Error

Solution code:
N, A, B = map(int, input().split())
P = list(map(int, input().split()))
Pmin = [None]*N
Pmax = [None]*N
for i, p in enumerate(P):
    k = 20000
    for pj in P[:i]:
        if pj > p:
            k = min(k, pj)
    Pmin[p-1] = k

for i, p in enumerate(P):
    k = -1
    for pj in P[:i:-1]:
        if pj < p:
            k = max(k, pj)
    Pmax[p-1] = k
dp = [[10**15]*(N+2) for _ in range(N+2)]
dp[1][N] = 0
for k in range(N-1, -1, -1):
    for i in range(1, N - k + 1):
        x = dp[i][i+k]
        if Pmax[i+k-1] + 1 <= i:
            dp[i][i+k-1] = min(dp[i][i+k-1], x)
        else:
            dp[i][i+k-1] = min(dp[i][i+k-1], x+A)
        if Pmin[i-1] - 1 >= i+k:
            dp[i+1][i+k] = min(dp[i+1][i+k], x)
        else:
            dp[i+1][i+k] = min(dp[i+1][i+k], x+B)
print(min([dp[i][i] for i in range(1, N+1)]))

Submission status: Runtime Error

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

def xxxxx(z, xx):
    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: Runtime Error

Solution code:
n, m = [int(i) for i in input().split()]
E = [[] for i in range(n+1)]
used = [False] * (n + 1)
IN = [0] * (n + 1)

for i in range(m):
    a, b = [int(i) for i in input().split()]
    E[a].append(b)
    E[b].append(a)
    IN[a] += 1
    IN[b] += 1

cnt_4 = 0
cnt_6 = 0
for i in IN[1:]:
    if i % 2 == 1 or i == 0:
        print('No')
        exit()
    if i >= 4:
        cnt_4 += 1
    if i >= 6:
        cnt_6 += 1

if cnt_4 >= 2 or cnt_6 >= 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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()]
starttime = time.time()
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)
    nextStr = subJ(currentStr,currentCheckNum)
    if checkJ(s):
        stack_list.insert(0,[nextStr,checkJ(nextStr)])
    applylist.append(currentCheckNum + 1)
if notfound == 1:
    print("-1")
elif notfound == 2:
    for i in range(len(applylist)):
        print(applylist[int(n)-i-1])
print(time.time() - starttime)

Submission status: Runtime Error

Solution code:
import itertools
N,b = input()
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)

Submission status: Runtime Error

Solution code:
import itertools
N,b = input()

N = 3
b = [1,2,1]
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)

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
B = input()
B = B.split()
a = []

for i in range(n):
    a.append(0)
    if int(B[i]) > i+1:
        print(-1)
        sys.exit()
        
for i in


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

Submission status: Runtime Error

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

def error_case():
  print(-1)

if progression[0] == 1:
  one_count = progression.count(1)
  element_num = [i for i, x in enumerate(progression) if x == 1]
  element_max = max(element_num)
  ushiro = progression[element_max:]
  ushiro.pop(0)
  ####print(ushiro)
  element_num.pop()
  element_next = max(element_num)
  next = progression[element_next:element_max]
  next.pop(0)
  ####print(next)
  while N < length:
    if N == 0:
      submit_array.append(1)
    if N == 1:
      if 2 in ushiro:
        submit_array.append(2)
      else:
        submit_array.append(1)
    two_num = [i for i, x in enumerate(ushiro) if x == 2]
    three_num = [i for i, x in enumerate(ushiro) if x == 3]
    if N == 2:
      if len(two_num)>=2:
        submit_array.append(2)
      else:
        if 3 in ushiro:
          submit_array.append(3)
        else:
          submit_array.append(1)
    if N == 3:
      if len(two_num)>=3:
        submit_array.append(2)
      else:
        if len(three_num)>=2:
          submit_array.append(3)
        else:
          if ushiro[1]==3:
            submit_array.append(3)
          else:
            if 4 in ushiro:
              submit_array.append(4)
            else:
              submit_array.append(1)
      
    if progression[N] > (N+1):
      error_case()
      break
    N+=1
    
else:
  error_case()
  
nn = 0
while nn < len(submit_array):
  print(submit_array[nn])
  nn+=1

Submission status: Runtime Error

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

def func(B,i,C):
    if(C[0:i].count(True) + 1 == B[i]):
        print(B[i])
        C[i] = True
        next = -1
        for j in range(N-1,-1,-1):
            if C[j] == False:
                next = j
                break
        if next == -1:
            return
        func(B,next,C)
    else:
        next = -1
        for j in range(i-1,-1,-1):
            if C[j] == False:
                next = j
                break
        func(B,next,C)

flag = 0
for i in range(N):
    if B[i] > i + 1:
        flag = -1
        break

if(flag == -1):
    print(-1)
else:
    C = [False] * N
    func(B,N-1,C)

Submission status: Runtime Error

Solution code:
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)),reverse=True)
ans=[]
for itr in range(n):
  for j in s_b:
    try:
      if len(b)>=j:
        if b[j-1]==j:
          b.pop(j-1)
          ans.append(j)
          break
    except:
      print("error")
    if j==1:
      print(-1)
      exit()
ans.reverse()
for i in range(n):
  print(ans[i])

Submission status: Runtime Error

Solution code:
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)),reverse=True)
ans=[]
for itr in range(n):
  for j in s_b:
    if len(b)>=j:
      if b[j-1]==j:
        b.pop(j-1)
        ans.append(j)
        break
    if j==1:
      print(-1)
      exit()
ans.reverse()
for i in range(n):
  print(ans[i])

Submission status: Runtime Error

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

# N = 3
# b_list = [1,1,3,1,2]
# b_list = [1, 1, 1, 2, 2, 1, 2, 3, 2]
# b_list = [1,1,1,2,2,1,2,3,2]

a_list = []

def insert(tmp_list, x, new):

    tmp = tmp_list[x:]
    tmp_list[x] = new
    tmp_list += tmp
    return tmp_list

p_list = []
m_list = []
z_list = []

for num, b in enumerate(b_list):
    num+=1
    
    idx = b-num
    
#     " 実現不可能 "
    if idx>0:
        print(-1)
#         exit()
    elif idx<0:
        m_list.append(b)
    elif idx==0:
        if num==1:
            continue
        z_list.append(b)

m_list.sort(reverse=True)
z_list.sort()

sol_list = []
sol_list.append(1)

m_max = max(m_list)

import numpy as np
care_dict = {}
for num, i in enumerate(n_list):
    if i!=m_max:
        continue
    d_list = []
    for j in n_list[num+1:]:
        diff = i-j
        d_list.append(diff)
    d_list = np.array(d_list)
    d_list = d_list[d_list>0]
    if len(d_list):
        care_dict[i] = len(d_list)
        
m_list = iter(m_list)
o_list = []

for m in m_list:
    
    for o in o_list:
        gr = care_dict[o]
        if len(sol_list)>= o+(gr-1):
            sol_list.append(o)
            o_list.remove(o)
    
    if m in care_dict.keys():
        gr = care_dict[m]
        
#         print(len(sol_list), m+(gr-1))
        
        if len(sol_list)>= m+(gr-1):
            sol_list.append(m)
        else:
            o_list.append(m)
    else:
        sol_list.append(m)
        
for o in o_list:
    gr = care_dict[o]
    if len(sol_list)>= o+(gr-1):
        sol_list.append(o)
        o_list.remove(o)
        
for z in z_list:
    sol_list.append(z)

for s in sol_list:        
    print(s)

Submission status: Runtime Error

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

for i in range(n):
    b[i] = int(b[i])
    ans[i] = b[i]


# n個の配列を全て0で埋める
#ans=[2]*n

for i in range(n):
    
    for j in reversed(range(b[i],i+1)):
        ans[j] = ans[j-1]
    
    
    ans[b[i]-1] = b[i]

if ans[0] != 1:
    print(-1)
else:
    for i in range(n):
        print(ans[i])

Submission status: Runtime Error

Solution code:
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
if set(np.diff(sorted(data))) != {0,1} and data[0] != 1:
    print(-1)
else:

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#最後のやつがjならはj番目にできたと確定する
dead=0
N=int(input())
b=list(map(int,input().split()))
ans=[0 for i in range(N)]#k番目にans[k-1]が入ったよの表
for i in reversed(range(1,N+1)):
    num=b[i-1]#頭からi番目の数
    sa_left=i-num#n-saleftから検証
    for j in reversed(range(1,N-sa_left+1)):
        if ans[j-1]==0:
            ans[j-1]=num
            break
if all(k!=0 in ans):
    for i in ans:
        print(ans)
else:
    print("-1")