Problem:


Score : 400 points

Problem Statement

Snuke has an empty sequence a.

He will perform N operations on this sequence.

In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).

You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq b_i \leq N

Input

Input is given from Standard Input in the following format:

N
b_1 \dots b_N

Output

If there is no sequence of N operations after which a would be equal to b, print -1.
If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.

Sample Input 1

3
1 2 1

Sample Output 1

1
1
2

In this sequence of operations, the sequence a changes as follows:

After the first operation: (1)

After the second operation: (1,1)

After the third operation: (1,2,1)

Sample Input 2

2
2 2

Sample Output 2

-1

2 cannot be inserted at the beginning of the sequence, so this is impossible.

Sample Input 3

9
1 1 1 2 2 1 2 3 2

Sample Output 3

1
2
2
3
1
2
2
1
1



Sample input:
3
1 2 1


Sample output:
1
1
2

Submission status: Wrong Answer

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

ans = []

while bn:
  lst = []
  for i in range(len(bn))[::-1]:
    if i+1 == bn[i]:
      lst.append(i)
  if not lst:
    print(-1)
    exit(0)
  ans.append(bn.pop(lst[-1]))
[print(i) for i in ans[::-1]]

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
B_list = list(map(int, input().split()))
# B_list = [1, 2, 3] * 33
# N = len(B_list)

asc_list = []
temp_l = [B_list[0]]
for num in B_list[1:]:
    if temp_l[-1] < num:
        temp_l.append(num)
    else:
        asc_list.append(copy.deepcopy(temp_l))
        temp_l = [num]

asc_list.append(copy.deepcopy(temp_l))

actionlist = []
cannot = False  # 途中で追加できなくなったらTrueになる
for i in range(1, N + 1):
    # print(asc_list)
    # print(actionlist)
    asc_list_index = -1
    while True:
        if asc_list_index == -(len(asc_list)+1):
            cannot = True
            break

        if asc_list[asc_list_index][0] <= i:  # 最後の単調増加列の0番目を挿入できる
            actionlist.append(asc_list[asc_list_index][0])
            asc_list[asc_list_index].pop(0)
            if not asc_list[asc_list_index]:
                asc_list.pop(asc_list_index)
            break
        else:
            asc_list_index -= 1
    if cannot:
        break

if cannot:
    print(-1)
else:
    for i in actionlist:
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = []
for i in range(n):
	c = 0
	for j in range(len(b)-1, -1, -1):
		c+=1
		if b[j] == j+1:
			b = b[:j]+b[j+1:]
			a.append(j+1)
			break
	if c == len(b):
		print(-1)
		exit()
a.reverse()
for i in a:
	print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = []
for i in range(n):
	for j in range(len(b)-1, -1, -1):
		if b[j] == j+1:
			b = b[:j]+b[j+1:]
			a.append(j+1)
			break
if len(a) == 0:
	print(-1)
else:
	a.reverse()
	for i in a:
		print(i)

Submission status: Wrong Answer

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

D = {}
for a in A :
    if a not in D :
        D[a] = 1
    else :
        D[a] += 1

D = sorted(D.items())

ans = 0

K = []
V = []
for k,v in D :
    
    K.append(k)
    V.append(v)

for i in range(len(K)) :
    k = K[i]
    if i+1 != k :
        ans = -1
        break
else :
    cum = 0
    for i in range(len(V)) :
        v = V[i]
        if cum < i :
            ans = -1
            break
        
        cum += v

if ans == -1 :
    print(ans)
else :
    for i in range(N) :
        for j in range(N-1,-1,-1) :
            if A[j] <= i+1 :
                print(A[j])
                A[j] = float("inf")
                break

Submission status: Wrong Answer

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

D = {}
for a in A :
    if a not in D :
        D[a] = 1
    else :
        D[a] += 1

D = sorted(D.items())

ans = 0

K = []
V = []
for k,v in D :
    
    K.append(k)
    V.append(v)

for i in range(len(K)) :
    k = K[i]
    if i+1 != k :
        ans = -1
        break
else :
    cum = 0
    for i in range(len(V)) :
        v = V[i]
        if cum < i :
            ans = -1
            break
        
        cum += v

if ans == -1 :
    print(ans)
else :
    for i in range(len(K)) :
        for j in range(V[i]) :
            print(i+1)

Submission status: Wrong Answer

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

A = sorted(A)

ans = 1

cum = [0]*N
for i, a in enumerate(A) :
    if i == 0 :
        cum[i] = a
    
    else :
        cum[i] = cum[i-1] + a

for i in range(N-2,-1,-1) :
    if cum[i]*2 >= A[i+1] :
        ans += 1
    else :
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
check = sorted(b)
ok = True
for i in range(1, N+1):
    if check[i-1] > i:
        ok = False
        break
if not ok:
    print(-1)
else:
    for i in range(N):
        print(b[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
check = sorted(b)
ok = True
for i in range(1, N+1):
    if check[i-1] > i:
        ok = False
        break
if not ok:
    print(-1)
else:
    for i in range(N):
        print(b[i], end="")
        if i != N-1:
            print(" ", end="")
        else:
            print()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import  defaultdict
from operator import itemgetter

n = ni()
b = list(li())

lower = [0]*n
upper = [0]*n
filled = [False]*n
a = [0]*n

nums = defaultdict(int)
for i, bi in enumerate(b[::-1]):
    lower[n-i-1] = bi + nums[bi] - 1
    nums[bi] += 1

for i, bi in enumerate(b):
    upper[i] = n - (i + 1 - bi) - 1

blu = [(bi, lowi, upi) for bi, lowi, upi in zip(b, lower, upper)]
blu.sort(key=itemgetter(2))

for bi, lowi, upi in blu:
    for pos in range(lowi, upi+1):
        if 0 > pos or pos >= n:
            break

        if not filled[pos]:
            a[pos] = bi
            filled[pos] = True
            break

if not all(filled):
    print("No")
else:
    print("Yes")
    print("\n".join(map(str, a)))

Submission status: Wrong Answer

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

res = [0] * N
pos = [0] * N

for i in range(N):
    pos[i] = N - (i + 1 - B[i]) - 1

ok = True
for p in pos:
    if p < 0:
        ok = False
    if p >= N:
        ok = False

if not ok:
    print(-1)
    exit(0)

nums = list(dict.fromkeys(B))
nums.sort(reverse = True)

for num in nums:
    for i in range(N-1, -1, -1):
        if B[i] != num:
            continue
        b = B[i]
        p = pos[i]
        if res[p] == 0:
            res[p] = b
        else:
            while res[p] != 0:
                p -= 1
                if p < 0 or p >= N:
                    print(-1)
                    exit(0)
                if res[p] == 0:
                    res[p] = b
                    break

for x in res:
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.sort()
b.reverse()
for i in range(n):
    if b[i] > n - i:
        print("-1")
        exit()
b.reverse()
for i in range(n):
    print(b[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    b = [int(i) for i in input().split()]
    num = [i for i in range(1,len(b)+1)]
    sorted_b = sorted(b)
    flag = True
    for i in range(len(b)):
        if b[i] > num[i]:
            flag = False
            break
    if flag == True:
        print(sorted_b)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=[]
for i in range(n)[::-1]:
  if l[i]==i+1:
    a=l.pop(i)
    ans.append(a)
if l!=[]:
  print(-1)
else:
  for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for _ in range(N):
    for i in range(len(data), 0, -1):
        #print(data[i],i)
        if data[i-1] == i:
            #print(data[i],i,data)
            ans.append(data.pop(-(len(data)-i)))
if data:
    print(-1)
else:
    for j in reversed(ans):
        print(j)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n=int(input())
    b = list(map(int, input().split()))
    ans = []
    for i in range(n):
        for j in range(len(b)-1, -1, -1):
            if b[j] == j+1:
                ans.append(j+1)
                b = b[:j] + b[j+1:]
                break
        if len(b) + i + 1 != n:
            print(-1)
            return
    for i in range(n):
        print(ans[i])

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

#print(n,b)
#n=9
#b=[1, 1, 1, 2, 2, 1, 2, 3, 2]

ans=[]

for j in range(n-1):
    val=110
    
    lenb=len(b)
    for i in range(lenb-1,-1,-1):
        if i+1==b[i]:
            val=b[i]
            break
    b.pop(i)
    ans.append(val)        
                
ans.append(b[0])

if ans.count(110) > 0:
    print(-1)
else:
    for i in ans:
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = []
for i in range(1,n+1):
    for j in range(n):
        if 1<=b[j]<=i:
            a.append(b.pop(j))
            break
    if len(a) != i:
        print(-1)
        exit()
for num in a:
    print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = N
B = list(map(int,input().split()))
B = B[::-1]
A = []
flag = 0
while N > 0:
    for m,b in enumerate(B):
        if (N-m == b):
            A.append(b)
            B.pop(m)
            flag = 1
            N -= 1
            break
    print(-1)
    exit()
for a in A[::-1]:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
bs = list(map(int, input().split()))
ans = []
flag = True
while bs:
    if not flag:
        break
    else:
        for i in range(N):
            if bs[-(i+1)] == N-i:
                if i != 0:
                    bs = bs[:-(i+1)]+bs[-i:]
                else:
                    bs = bs[:-(i+1)]
                ans.append(N-i)
                N -= 1
                break
        if bs:
            if bs[0] != 1:
                flag = False
if flag:
    for i in range(1, N+1):
        print(ans[-i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
sequence_size = int(input())
sequence = list(map(int, input().split()))
error = False
error_msg = -1
sequence.sort()
if max(sequence) > sequence_size:
    print(error_msg)
else:
    for index in range(0,sequence_size - 1):
        if sequence[index] <= index + 1:
            error is False
        else:
            error is True
            break
if error is False:
    for num in range(0,sequence_size,+1):
        print(sequence[num])
else:
    print(error_msg)

Submission status: Wrong Answer

Solution code:
sequence_size = int(input())
sequence = list(map(int, input().split()))

sequence.sort()
if max(sequence) > sequence_size:
    print("-1")
else:
    for index in range(sequence_size - 1):
        if sequence[index] <= index + 1:
            print(sequence[index])
        else:
            print("-1")
            break

Submission status: Wrong Answer

Solution code:
import sys

N = int(raw_input())
bs = map(int, raw_input().split(" "))

def calc(bbs, ls):
    if len(bbs) == 1 and bbs[0] == 1:
        a = ls+[1]
        a.reverse()
        for aa in a:
            print aa
        sys.exit()
    for i in range(len(bbs)):
        if i + 1 == bbs[i]:
            calc(bbs[:i]+bbs[i+1:], ls+  [i+1])
calc(bs, [])

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
k =[]
x = list(map(int, input().split()))
x = x[::-1]
for i in range(n):
    for j,p in enumerate(x):
        if p == n-j:
            k.append(p)
            x.pop(j)
            n-=1

            break
    else:
        print(-1)
        sys.exit()
for i in k:
    print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=input()
n=int(n)
b=input().split()
b=[int(i) for i in b]
count=1
for i in b:
    if i>count:
        print(-1)
        count=0
        break
    count+=1
if count!=0:
    count=0
    while count<n:
        ll=list()
        for i in range(n):
            a=b[-1]
            ll.append(a)
            del b[-1]
            count+=1
            if a==1:
                ll.sort()
                for i in ll:
                    print(i)
                break

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print(ans[len(ans) - i - 1])
        exit()
    for i in range(len(a) - 1, 0, -1):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])
            break

f(b, [])
print(-1)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
l = [int(x) for x in input().split()]
ans = [0] * n
ans[0] = 1
for i in range(n):
  if l[i] > i + 1:
    print(-1)
    sys.exit()
for i in reversed(range(1, n)):
  k = 0
  for j in range(i + 1, n):
    if l[i] >= l[j]:
      k += 1
  k += l[i] - 1
  while ans[k] != 0:
    k += 1
  ans[k] = l[i]
for i in range(n):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.reverse()
ans_set = [0]*n

for i in range(n):
    for j in range(n):
        
        if b[j] == n-j:
            ans = b.pop(j)
            ans_set[n-1] = ans
            n -= 1
            break
            
        elif b[j] > n-j:
            ans = -1
            print(ans)
            break

        if n == 0:
            break

for k in ans_set:
    print(k)

Submission status: Wrong Answer

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

ops = []
for i in range(n):
  for j, b in enumerate(reversed(bs)):
    if n - i - j == b:
      bs.pop(n-i-j-1)
      ops.append(n-i-j)
      break
  if len(bs) == n-i:
    break
if len(ops) == n:
  print(*ops, sep="\n")
else:
  print(-1)

Submission status: Wrong Answer

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

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

else:
    a = []

    while len(b)>0:
        n = len(b)
        br = True
        for i in range(n):
            if  n-i == b[n-1-i]:
                a.append(n-i)
                b.remove(n-i)
                br = False
                break
        if br:
            break

    for _ in range(len(a)):
        print(a.pop())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for anse in ans:
        print(anse)

Submission status: Wrong Answer

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

uniq_b = set(b)
for x in uniq_b:
	if b.count(x) > n - x + 1:
		print(-1)
		exit()

for i, x in enumerate(b):
	if x > i+1:
		print(-1)
		exit()

for i in range(len(b)):
	y = max(x for x in b if x <= i+1)
	print(y)
	b.remove(y)

Submission status: Wrong Answer

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

uniq_b = set(b)
for x in uniq_b:
	if b.count(x) > n - x + 1:
		print(-1)
		exit()

for i, x in enumerate(b):
	if x > i+1:
		print(-1)
		exit()

for x in sorted(b):
	print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(x) for x in input().split()]
uniq_b = set(b)
for x in uniq_b:
	if b.count(x) > n - x + 1:
		print(-1)
		exit()

for x in sorted(b):
	print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) - 1 for i in input().split()]
ans = []
while len(a):
    key = -1
    for i, j in enumerate(a):
        if i == j:
            ans.append(i + 1)
            key = i
            break
    if key == -1:
        break
    else:
        a.remove(key)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) - 1 for i in input().split()]
ans = []
while len(a):
    key = -1
    for i, j in enumerate(a):
        if i == j:
            ans.append(i)
            key = i
            break
    if key == -1:
        break
    else:
        a.remove(key)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
b=[int(i) for i in input().split()]
a=1
t=-1
w=[-1]*2
ans=[]
while w[0]!=0 or w[1]!=n-1:
    if t<-n:
        print(-1)
        exit()
    if a==1 and b[t]==1:
        ans.append(1)
        w[0]=n+t
        w[1]=n+t
        a+=1
    elif 0<=w[1]<n-1 and b[w[1]+1]<=a:
        ans.append(b[w[1]+1])
        w[1]+=1
        a+=1
    elif 0<w[0]<=n-1 and b[w[0]-1]<=a:
        ans.append(b[w[0]-1])
        w[0]-=1
        a+=1
    else:
        t-=1
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b= input()
B = b.split(" " )
B_i = [int(k) for k in B]
ans = []
for i,e in enumerate(B_i):
  if i < e-1:
    print("-1")
    break
  ans.insert(-1*e,e)
for A in ans:
  print(str(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
b= input()
B = b.split(" " )
B_i = [int(k) for k in B]
ans = []
for i,e in enumerate(B_i):
  E = e-1
  if i < E:
    print("-1")
    break
  ans.insert(-1*E,e)
for A in ans:
  print(str(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
b= input()
B = b.split(" " )
B_i = [int(k) for k in B]
B_i.sort()
ans = []
for i,e in enumerate(B_i):
  E = e-1
  if i < E:
    print("-1")
    break
  ans.insert(E,e)
for A in ans:
  print(str(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
b= input()
B = b.split(" " )
B_i = [int(k) for k in B]
ans = []
for i,e in enumerate(B_i):
  E = e-1
  if i < E:
    print("-1")
    break
  ans.insert(E,e)
for A in ans:
  print(str(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    out.append(bs[change_i])
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    out.append(bs[change_i])
    print(out)
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    if bs[i] > i + 1:
        break
    elif bs[i] < i + 1:
        i = bs[i] - 1
    else:
        if i == len(bs) - 1:
            out.append(bs[i])
            del bs[i]
            i -= 1
        elif bs[i+1] < i + 2:
            out.append(bs[i])
            del bs[i]
        else:
            i += 1
if len(bs) == 0:
    for o in reversed(out):
        print(o)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    if bs[i] > i + 1:
        break
    elif bs[i] < i + 1:
        i -= 1
    else:
        if i == len(bs) - 1:
            out.append(bs[i])
            del bs[i]
            i -= 1
        elif bs[i+1] < i + 2:
            out.append(bs[i])
            del bs[i]
        else:
            i += 1
if len(bs) == 0:
    for o in reversed(out):
        print(o)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
a = []
n = int(input())
b = [int(e) for e in input().split()]
for j in range(1, n+1):
    a.append(j)
print(a)
print(b)
for i in range(1, n):
    if a[i] != b[i]:
        print(-1)
    else:
        print(a[i])

Submission status: Wrong Answer

Solution code:
a = []
n = int(input())
b = [int(e) for e in input().split()]
for j in range(1, n+1):
    a.append(j)
for i in range(1, n):
    if a[i] != b[i]:
        print(-1)
    else:
        print(a[i])

Submission status: Wrong Answer

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

def main():
    b.sort()
    for i in range(n):
        print(b[i])

for i in range(n):
    if b[i] < n-i:
        main()
        break
    elif b[i] == n-i:
        continue
    if i == n - 1 and b[i] <= n:
        main()
        break
else:
    print("-1")

Submission status: Wrong Answer

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

def main():
    b.sort()
    for i in range(n):
        print(b[i])

for i in range(n):
    if b[i] < n-i:
        main()
        break
    elif b[i] == n-i:
        continue
    if i == n - 1 and b[i] == 1:
        main()
        break
else:
    print("-1")

Submission status: Wrong Answer

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

for i in range(n):
    if b[i] > n-i:
        print("-1")
        quit()
else:
    b.sort()
    for i in range(n):
        print(b[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
a = [0 for i in range(N)]
number = []
for j in range(N):
    for i in range(len(b)-1,-1,-1):
        if(i+1==b[i] and a[i]==0):
            del a[i]
            number.append(b[i])
            del b[i]
            break
if(not a):
    for i in range(N):
        print(number.pop())

Submission status: Wrong Answer

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

for i in range(n):
    if b[i]<=i+1:
        continue
    else:
        flag=True
        break

if flag:
    print("-1")
else:
    for i in range(n):
        print(b[i])

Submission status: Wrong Answer

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

for i in range(n):
    if b[i]<=i+1:
        continue
    else:
        flag=True
        break

if flag:
    print("-1")
else:
    for i in range(n):
        print("1")

Submission status: Wrong Answer

Solution code:
# 実行時の引数の入力：https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

# ***.py a b c形式の引数使用時
# import sys
#
# args = sys.argv
#
# num_len = int(args[1])
# a = []
# b = []
# N = 100
# # b = [1,2,1]
# for i in range(2, 2+num_len):
#     b.append(int(args[i]))
# print(b)

a = []
# print('input:')
num_len = int(input())
b = list(map(int, input().split()))
# print('--'*len(b))
# print('output:')
# print(b)
N = 100



# for i in range(len(b)):
for i in range(num_len):
    # try:
    #     # print(i)
    #     a.insert(b[i], b[i])
    #     print(a)
    # except:
    #     print(-1)

    if b[i]-1 <= len(a):
        # print(i)
        a.insert(b[i]-1, b[i])
        print(a)
        flag = True
    else:
        flag = False
        break


if flag:
    for i in a:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# 実行時の引数の入力：https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

# ***.py a b c形式の引数使用時
# import sys
#
# args = sys.argv
#
# num_len = int(args[1])
# a = []
# b = []
# N = 100
# # b = [1,2,1]
# for i in range(2, 2+num_len):
#     b.append(int(args[i]))
# print(b)

a = []
print('input:')
num_len = int(input())
b = list(map(int, input().split()))
print('--'*len(b))
print('output:')
print(b)
N = 100



# for i in range(len(b)):
for i in range(num_len):
    # try:
    #     # print(i)
    #     a.insert(b[i], b[i])
    #     print(a)
    # except:
    #     print(-1)

    if a == b:
        # print(i)
        a.insert(b[i], b[i])
        # print(a)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
import sys

#sys.stdin.readline()

input_list = [int(x) for x in sys.stdin.readline().split(" ")]
#input_list = [1]
record = {}
def solve(input_list):
  # Return answer list if answer is found, False otherwise
  
  if (tuple(input_list) in record):
    return record[tuple(input_list)]
    
  if (len(input_list) == 0):
    return []
  else:
    
    for i in range(len(input_list)):
      if input_list[i] > len(input_list):
        return False

      if (input_list[i] == i + 1):
        copy = list(input_list)
        #print(i)
        copy.pop(i)
        result = solve(copy)
        if (not result == False):
          record[tuple(input_list)] = [i + 1] + result
          return [i + 1] + result

    return False

#print('aa')
answer = solve(input_list) 
 
if (answer):
  for number in answer:
    print (number)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split(" ")))
ans = []
Flag = True

for i in range(N):
	if B[i] > i+1:
		Flag = False
	else:
		ans.append(B[i])

if Flag:
	for k in ans:
		print(k)
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split(" ")))
ans = []
Flag = True

B.sort()

for i in range(N):
	if B[i] > i+1:
		Flag = False

if Flag:
	for k in B:
		print(k)
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split(" ")))
ans = []
Flag = True

B.sort()

for i in range(N):
	if B[i] >= i+1:
		Flag = False

if Flag:
	for k in B:
		print(k)
else:
	print(-1)

Submission status: Wrong Answer

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

l = []
for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if B[j] == j+1:
            l.append(j+1)
            B.pop(j)
            N -= 1
            break

for l_i in l[::-1]:
    print(l_i)

Submission status: Wrong Answer

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

for b in B:
    while len(S) and S[-1] >= b:
        ans.append(S.pop())
    S.append(b)

ans = (ans + S[::-1])[::-1]

for i, a in enumerate(ans, start=1):
    if i < a:
        print(-1)
        break
else:
    print(*ans, sep="\n")

Submission status: Wrong Answer

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

for b in B:
    while len(S) and b - 1 != len(S):
        ans.append(S.pop())
    S.append(b)

ans = (ans + S[::-1])[::-1]

for i, a in enumerate(ans, start=1):
    if i < a:
        print(-1)
        break
else:
    print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
# AGC032 Problem-AGC032

n = int(input())
a = list (map(int, input().split()))
#print (a)
a.insert(0,-1)
result = []
for i in range (n, 0, -1) :
    for j in range (i, -1, -1) :
#        print (a)
        if a[j] == j :
            result.append(j)
#            print (result)
            a = a[:j+1] + a[j+2:]
            break
        if j == 0 :
            result = [-1]
            break

result.reverse()
for ans in result :
    print (ans)

Submission status: Wrong Answer

Solution code:
a = []
N = int(input())
a1=input().split()
for i in range(N):
    if i == a1[i]:
        a.append(i)
    else:
        a.append(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=[]
k=1
for i in range(1,n+1):
  if a[-1] <= min(i,k) :
    s+=[a[-1]]
    a=a[:-1]
    k=i
  elif a[0] >i:
    print(-1)
    break
  else:
    s+=[a[0]]
    a=a[1:]
    k+=1
else:
  for i in s:print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
prob = list(map(int, input().split()))
ans = []
for i in reversed(range(N)):
  boo = False
  for j in reversed(range(i + 1)):
    if prob[j] == j + 1:
      boo = True
      ans.append(j + 1)
      del prob[j]
      break
  if not boo:
    break
if len(ans) == N:
  for x in ans:
    print(x)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
L=[int(i)-1 for i in input().split()]
M=[]
while True:
    flag=0
    if len(L)==0:
        for m in M[::-1]:
            print(m+1)
        sys.exit()
    if L[0]!=0:
        print(-1)
        sys.exit()
    for i in range(len(L)):
        if L[i]!=i:
            s = L.pop(i - 1)
            M.append(s)
            flag=1
            break
    if flag==0:
        s=L.pop(len(L)-1)
        M.append(s)

Submission status: Wrong Answer

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

def low(lis, n):
    return [
        l for l in lis if l <= n
    ]

def rev_idx(lis, n):
    return [
        i for i, e in enumerate(lis[::-1]) if e == n
    ]


try:
    sort = sorted(list(set(nums)))[1:]
    order = low(nums, 1)
    order[0]
    for i, n in enumerate(sort):
        lows = low(nums, n)
        for index in rev_idx(lows, n):
            order.insert(n + index - 1, n)
    for o in order:
        print(o)
except:
    print(-1)