ZhenlongDai/ACPR huggingface dataset:
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

a.insert(0,-1)
result = []
for i in range (n, 0, -1) :
    for j in range (i, -1, -1) :

        if a[j] == j :
            result.append(j)

            a = a[:j+1] + a[j+2:]
            break
        if j == 0 :
            result = [-1]
            break

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


Failing test case input:
3
1 7 0

Expected output:
-1


Actual output:
1
1
1


Fixed submission (verdict: Accepted):


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

a.insert(0,-1)
result = []
for i in range (n, 0, -1) :
    for j in range (i, -1, -1) :

        if a[j] == j :
            result.append(j)

            a = a[:j] + a[j+1:]
            break
        if j == 0 :
            result = [-1]
            break

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [' '] * N

  for i in range(N - 1, -1, -1):
    flag = False
    for j in range(len(B)):
      if B[j] == j + 1: continue
      if j == 0: return '-1'
      flag = True
      ans[i] = str(B.pop(j - 1))
      break
    if not flag: ans[i] = str(B.pop(-1))

  return '\n'.join(ans)

print(solve())


Failing test case input:
9
1 1 1 1 2 1 4 1 2

Expected output:
1
2
1
1
2
4
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ 0 ] * N

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

print(solve())

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import heapq

N=int(input())
l=list(map(int,input().split()))
temp=[]

if l[0]!=1:
    print(-1)

for i in range(len(l))[::-1]:
    temp.append(l.pop(-1))
    if temp[-1]==1:
        heapq.heapify(temp)
        while temp:
            print(heapq.heappop(temp))


Failing test case input:
3
0 8 1

Expected output:
-1


Actual output:
-1
1


Fixed submission (verdict: Accepted):


N=int(input())
l=list(map(int,input().split()))
pre=[]
ans=[]

while l:
    if pre==l:
        print(-1)
        exit()
    pre.clear()
    pre+=l
    for i in range(len(l))[::-1]:
        if l[i]==i+1:
            ans.append(l.pop(i))
            break

for item in ans[::-1]:
    print(item)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
list_b = list(map(int, input().split()))
ans = [0 for i in range(N)]

finish = False

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

Failing test case input:
3
1 7 0

Expected output:
-1


Actual output:
[7, 0, 0]
-1


Fixed submission (verdict: Accepted):
N = int(input())
list_b = list(map(int, input().split()))
ans = [0 for i in range(N)]

finish = False

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline  
sys.setrecursionlimit(10 ** 7)  


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


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

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


if __name__ == "__main__":
    main()


Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
1
1
1
1
2
1
4
3
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline  
sys.setrecursionlimit(10 ** 7)  


def dfs(N, a, i, procedure):
    if i == 0:
        return procedure

    for j in reversed(range(1, i+1)):
        if a[j-1] == j:
            l = a[:]
            del l[j-1]
            p = procedure[:]
            p.append(j)
            ret = dfs(N, l, i-1, p)
            if ret is not None:
                return ret
            break


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

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


if __name__ == "__main__":
    main()
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = list(map(int, input().split()))

for i in range(N):
  if i + 1 < b[i]:
    print("-1")
    exit()

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

print(L)
  

Failing test case input:
9
1 1 1 2 2 1 4 1 2

Expected output:
1
2
1
1
2
4
2
1
1


Actual output:
[1, 2, 1, 1, 2, 4, 2, 1, 1]


Fixed submission (verdict: Accepted):
N = int(input())
b = list(map(int, input().split()))

for i in range(N):
  if i + 1 < b[i]:
    print("-1")
    exit()

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

for i in L:
  print(i)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n, *b = map(int, open(0).read().split())
    b.sort()

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

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

if __name__ == '__main__':
    main()


Failing test case input:
9
1 1 1 2 2 1 2 3 2

Expected output:
1
2
2
3
1
2
2
1
1

Actual output:
1
1
1
1
2
2
2
2
3


Fixed submission (verdict: Accepted):
def main():
    n, *b = map(int, open(0).read().split())

    m = []
    for k in range(1, n+1):
        for i in range(n - k, -1, -1):
            if b[i] == i + 1:
                b.pop(i)
                m.append(i+1)
                break

    if len(b) > 0:
        print(-1)
    else:
        print('\n'.join(map(str, m[::-1])))


if __name__ == '__main__':
    main()

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
l = [int(i) for i in input().split()]

a = [0]*n

o = 0
for i in l:
    o+=1
    if(i<=o):
        if(i<=len(a)):
            if(a[i-1]!=0):
                a[a.index(0)] = i
            else:
                a[i-1] = i
if(a == l):
    print("\n".join([str(i) for i in a]))
else:
    print(-1)


Failing test case input:
9
1 1 1 2 2 1 4 3 2

Expected output:
1
2
1
3
2
4
2
1
1


Actual output:
1
1
1
2
2
1
4
3
2


Fixed submission (verdict: Accepted):
n = int(input())

l = input().split()

res = []

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


            

if(l != []):
    print(-1)
else:
    print("\n".join(res[::-1]))
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
b = list(map(int, input().split()))

ans=[]

for i in range(N):
    
    
    j = 1
    if j < len(b):
        while b[j] == j + 1:
            j += 1
            if j == len(b):break
    if b[j - 1] == j:
        del b[j-1]
        ans.append(j)
    else:
        print(-1)
        import sys
        sys.exit()

for i in range(len(ans)-1,-1,-1):
    print(ans[i])

Failing test case input:
9
1 1 1 2 2 1 4 3 2

Expected output:
1
2
1
3
2
4
2
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
N=int(input())
b = list(map(int, input().split()))

ans=[]


for i in range(N):
    
    j = False
    for k in range(len(b)-1,-1,-1):
        if b[k] == k + 1:
            j = True
            del b[k]
            ans.append(k+1)
            break
    if not j:
        print(-1)
        import sys
        sys.exit()

for i in range(len(ans) - 1, -1, -1):
    print(ans[i])

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
B = list(map(int, input().split()))
for i, b in enumerate(B, 1):
    if i < b:
        print(-1)
        exit()

d = []
for i in range(N-1, -1, -1):
    d.append(B[i])
    if B[i] == 1:
        for x in sorted(d):
            print(x)
        d = []


Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
1
2
3
4
1
2
1
1
1


Fixed submission (verdict: Accepted):
N = int(input())
B = list(map(int, input().split()))
res = []
while 0 < len(B):
    index = None
    for i, b in enumerate(B, 1):
        if i == b:
            index = i
    if index is None:
        print(-1)
        exit()
    else:
        res.append(B[index-1])
    del B[index-1]
for x in res[::-1]:
    print(x)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
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
    if not ok:
        break
    out.append(bs[change_i])
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))


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

Failing test case input:
3
0 11 4

Expected output:
-1


Actual output:
[0, 11, 4]
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
acts = []
while True:
    for i in range(len(a)):
        idx = len(a)-i-1
        if a[idx] == idx+1:
            a.pop(idx)
            acts.append(idx+1)
            break
    else:
        print('-1')
        break
    if len(a) == 0:
        acts.reverse()
        print('\n'.join(map(str,acts)))
        break

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()


Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
1 1 1 1 2 1 4 3 2


Fixed submission (verdict: Accepted):
N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
    ok = True
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            ans.append(b.pop(i))
            break
        else:
            if i == 0:
                ok = False
    if not ok:
        break
if len(ans) != N:
    print(-1)
else:
    for i in range(N-1, -1, -1):
        print(ans[i])

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
B = list(map(int,input().split()))
A = []
ans = -1
for i in range(N):
  if B[i] <= i+1:
    A.append(B[i])
  else:
    break
    
if (len(A) == len(B)):
  for i in A:
    print(i)
else:
  print(ans)

Failing test case input:
9
1 1 1 1 2 1 4 1 2

Expected output:
1
2
1
1
2
4
1
1
1


Actual output:
1
1
1
1
2
1
4
1
2


Fixed submission (verdict: Accepted):
N = int(input())
B = list(map(int,input().split()))
l = len(B)
A = []
ans = -1
for i in range(N):
  max_j = -1
  for j in range(N-i):
    if B[j] == j+1:
      max_j = j
  if (max_j == -1):
    break
  else:
    A.append(B.pop(max_j))
if (l == len(A)):
  for i in reversed(A):
    print(i)
else:
  print(ans)
Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
b = [int(i) for i in input().split()]
ans = []
for i in range(len(b)):
    for j in reversed(range(len(b))):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            break

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

Failing test case input:
3
-1 20 4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
b = [int(i) for i in input().split()]
ans = []
for i in range(len(b)):
    removed = False
    for j in reversed(range(len(b))):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            removed = True
            break
    if not removed:
        print(-1)
        exit()
print('\n'.join(map(str, reversed(ans))))

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = list(map(int, input().split()))

a = []
for i in range(N-1, -1, -1):
	if b[i] == 1:
		a += sorted([b.pop() for j in range(len(b)-i)])

if len(a) == 0:
	print(-1)
else:
	for ai in a:
		print(ai)

Failing test case input:
3
4 7 1

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
b = list(map(int, input().split()))

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

a = []
for i in range(N):
	for j in range(len(b)-1, -1, -1):
		if b[j] == j+1:
			a += [b.pop(j)]
			break
a.reverse()
			
if len(b) != 0:
	print(-1)
else:
	for ai in a:
		print(ai)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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):
        
        if data[i-1] == i:
            
            ans.append(data.pop(-(len(data)-i)))
if data:
    print(-1)
else:
    for j in reversed(ans):
        print(j)

Failing test case input:
9
1 1 1 2 2 1 2 3 2

Expected output:
1
2
2
3
1
2
2
1
1

Actual output:
1
2
3
2
1
2
2
1
1


Fixed submission (verdict: Accepted):
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) - 1, -1, -1):
        
        if data[i] == i+1:
            
            ans.append(data.pop(-(len(data)-i)))
            break
if data:
    print(-1)
else:
    for j in reversed(ans):
        print(j)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
9
1 1 1 1 2 1 2 3 2

Expected output:
1
2
2
3
1
2
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
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:
            key = i
    if key == -1:
        break
    else:
        a.remove(key)
        ans.append(key + 1)

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = map(int,input().split())
b_ = []
for i in b:
    b_.append(int(i))
b_.sort()
a = []
cont = 1
for i in b_:
    if cont >= i:
        a.append(b_[cont-1])
    cont += 1
if len(a)==len(b_):
    for s in a:
        print(s)
else:
    print(-1)

Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
1
1
1
1
1
2
2
3
4


Fixed submission (verdict: Accepted):
N = int(input())
b = map(int,input().split())
b_ = [int(s) for s in b]
ans = []
for i in range(N):
    for j in range(len(b_),0,-1):
        if j == b_[j-1]:
            del b_[j-1]
            ans.append(j)
            break
if len(ans) == N:
    for i in reversed(ans):
        print(i)
else:
    print(-1)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = list(map(int, input().split()))

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

for a in ans:
  print(a)

Failing test case input:
9
1 1 1 2 2 1 1 1 2

Expected output:
1
2
1
1
1
2
2
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
b = list(map(int, input().split()))

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

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

ans.reverse()
for a in ans:
  print(a)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
B = [0]+list(map(int,input().split()))

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

Failing test case input:
9
1 1 1 2 2 1 4 3 2

Expected output:
1
2
1
3
2
4
2
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
B = [0]+list(map(int,input().split()))

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
from itertools import permutations

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = list(permutations(li, n))
flag = 0
for i in lin:
    i = list(i)
    lis = []
    for j in range(n):
        lis.insert(i[j]-1,i[j])
    if lis == li:
        flag = 1
        break
if flag == 1:
    for i in lis:
        print(i)
else:
    print(-1)

Failing test case input:
2
4 14

Expected output:
-1


Actual output:
4
14


Fixed submission (verdict: Accepted):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = []

while li:
    now = 10**10
    for i,j in enumerate(li,1):
        if i == j:
            now = i
    if now == 10**10:
        print(-1)
        exit()
    lin.append(now)
    li.pop(now-1)

for i in lin[::-1]:
    print(i)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
3
-1 11 4

Expected output:
-1


Actual output:
[-1]
[-1, 11]
[-1, 11, 4]
-1


Fixed submission (verdict: Accepted):
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
    if not ok:
        break
    out.append(bs[change_i])
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
9
1 1 1 2 2 1 4 3 2

Expected output:
1
2
1
3
2
4
2
1
1


Actual output:
1
1
1
1
2
2
2
3
4


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(n, 0, -1):
    for j in range(i, 0, -1):
        if b[j-1] == j:
            ans.append(j)
            b.pop(j-1)
            break
    else:
        print(-1)
        break
else:
    for i in ans[::-1]:
        print(i)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**6)

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

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

dfs(b, [])

print('-1')


Failing test case input:
9
1 1 1 2 2 1 2 3 2

Expected output:
1
2
2
3
1
2
2
1
1

Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)

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

def dfs(s, ans):
    if len(s) == 0:
        print('\n'.join(map(str, reversed(ans))))
        exit()
        return
    for i in range(len(s)):
        
        
        if s[i] == i+1:
            s1 = s[:i] + s[i+1:]
            allok = True
            for j in range(len(s1)):
                if s1[j] > j+1:
                    allok = False
                    break
            
            if allok:
                ans.append(s[i])
                dfs(s1, ans)
    if len(ans) > 0:
        ans.pop()

dfs(b, [])

print('-1')

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):







from collections import Counter

n = int(input())
bli = list(map(int, input().split()))
cli = bli.copy()
cli.reverse()

for i in range(1, n+1):
    if 1 in cli:
        x = cli.index(1)
        for j in range(0, x+1):
            cli[j] -= 1
    else:
        print(-1)
        quit()
    print(bli[n-1-x])




Failing test case input:
3
4 7 1

Expected output:
-1


Actual output:
1
-1


Fixed submission (verdict: Accepted):







from collections import Counter

n = int(input())
bli = list(map(int, input().split()))
cli = bli.copy()
cli.reverse()
dli = []

for i in range(1, n+1):
    if 1 in cli:
        x = cli.index(1)
        for j in range(0, x+1):
            cli[j] -= 1
    else:
        print(-1)
        quit()
    dli.append(bli[n-1-x])

for i in dli:
    print(i)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
n = N
B = list(map(int,input().split()))
B = B[::-1]
A = []
for i in range(N):
    for m,b in enumerate(B):
        if (N-m == b):
            A.append(b)
            B.pop(m)
            N -= 1
            break
if len(A) == n:
    for a in A[::-1]:
        print(a)
else:
    print(-1)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

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

Failing test case input:
3
0 8 0

Expected output:
-1


Actual output:
2 3
1 3
0 3
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import heapq

N=int(input())
l=list(map(int,input().split()))
temp=[]

if l[0]!=1:
    print(-1)

for i in range(len(l))[::-1]:
    if l[i]>=i:
        print(-1)
        exit()
    temp.append(l.pop(-1))
    if temp[-1]==1:
        heapq.heapify(temp)
        while temp:
            print(heapq.heappop(temp))



Failing test case input:
3
0 8 1

Expected output:
-1


Actual output:
-1
1
-1


Fixed submission (verdict: Accepted):


N=int(input())
l=list(map(int,input().split()))
pre=[]
ans=[]

while l:
    if pre==l:
        print(-1)
        exit()
    pre.clear()
    pre+=l
    for i in range(len(l))[::-1]:
        if l[i]==i+1:
            ans.append(l.pop(i))
            break

for item in ans[::-1]:
    print(item)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
B = list(map(int, input().split()))

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

A = solve(B)
print(A)

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

Failing test case input:
3
-1 9 2

Expected output:
-1


Actual output:
None
-1


Fixed submission (verdict: Accepted):
N = int(input())
B = list(map(int, input().split()))

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

A = solve(B)


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

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
inf = 10 ** 15
mod = 10 ** 9 + 7

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

Failing test case input:
3
-1 9 2

Expected output:
-1


Actual output:
9
2
-1


Fixed submission (verdict: Accepted):




import math
import sys
import bisect
import heapq  
from collections import deque

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

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ False ] * N

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

print(solve())


Failing test case input:
9
1 1 1 1 2 1 4 1 2

Expected output:
1
2
1
1
2
4
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ 0 ] * N

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

print(solve())
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = list(input().split())
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)

print(s)


if len(s) == 0:
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")

Failing test case input:
3
0 9 2

Expected output:
-1


Actual output:
['0', '9', '2']
-1


Fixed submission (verdict: Accepted):
n = int(input())
s = list(input().split())
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)




if len(s) == 0:
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int, input().split()))

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

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

Failing test case input:
3
-1 20 4

Expected output:
-1


Actual output:
No


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int, input().split()))

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

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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = []
c = [0]*N
count_flag=0
b = list(map(int, input().split()))

for count in range(N):
  for i in range(N-count):
    if count_flag == count and b[N-1-count-i]==N-1-count-i+1 :
      
      c[N-1-count]=N-1-count-i+1
      b.pop(N-1-count-i)
      count_flag+=1
       
for i in range(N):
  print(c[i])

Failing test case input:
3
-1 9 1

Expected output:
-1


Actual output:
0
0
0


Fixed submission (verdict: Accepted):
N = int(input())
b = []
c = [0]*N
count_flag=0
b = list(map(int, input().split()))

for count in range(N):
  for i in range(N-count):
    if count_flag == count and b[N-1-count-i]==N-1-count-i+1 :
      c[N-1-count]=N-1-count-i+1
      b.pop(N-1-count-i)
      count_flag+=1
if count_flag == N:
  for i in range(N):
    print(c[i])
else:print(-1)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

ans = []
removed = [False] * N

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

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


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

Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):

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

ans = []
removed = [False] * N

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

        if idx + 1 == B[i]:
            idx += 1
            idx_remove = i

        else:
            idx += 1
    
    if idx_remove != -1:
        ans.append(B[idx_remove])
        removed[idx_remove] = True
        flag = True


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

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
3
0 8 1

Expected output:
-1


Actual output:
-1
-1
-1
0
0
0


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int, input().split()))
b.reverse()
ans_set = [0]*n
ans = 0

for i in range(n):
    if ans == -1:
        break
    
    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

if ans != -1:
    for k in ans_set:
        print(k)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
3
-2 4 3

Expected output:
-1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
b = [int(i) for i in input().split()]
a = []
for i in range(n):
	f = 1
	for j in range(len(b)-1, -1, -1):
		if b[j] == j+1:
			b = b[:j]+b[j+1:]
			a.append(j+1)
			f=0
			break
	if f == 1:
		print(-1)
		exit()
a.reverse()
for i in a:
	print(i)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
b=list(map(int,input().split()))
ans=[]
turn=N
while(b):
    lim=turn
    if b[0]!=1:
        print(-1)
        exit()
    now=0
    for i in range(1,min(lim,len(b))):
        if b[i]==i+1:
            now=i
        else:
            break
    ans.append(now+1)
    del b[now]
print(*ans[::-1],sep='\n')

Failing test case input:
9
1 1 1 2 2 1 4 1 2

Expected output:
1
2
1
1
2
4
2
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
N=int(input())
b=list(map(int,input().split()))
ans=[]
turn=N
while(b):
    last=-1
    for i in range(len(b)):
        if i+1==b[i]:
            last=i
    if last==-1:
        print(-1)
        exit()
    ans.append(last+1)
    del b[last]
    
print(*ans[::-1],sep='\n')

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = list(map(int,input().split()))

a = []

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

Failing test case input:
9
1 1 1 2 2 1 4 3 2

Expected output:
1
2
1
3
2
4
2
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
b = list(map(int,input().split()))
l = [0]*N
for i in range(N):
  for j in range(min(N,len(b))-1,-1,-1):
    if b[j] == j+1:
      b.pop(j)
      l[i] = j+1
      break
if b == []:
  l.reverse()
  for k in range(N):
    print(l[k])
else:
  print(-1)

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 1:
    c = len(ans)
    f = b[0]
    for i in range(1, len(b)):
      if b[-1] ==  n - c:
        ans.append(b.pop(-1))
        break
      if f >= b[i]:
        ans.append(b.pop(i-1))
        break
      elif n - c == b[i]:
        ans.append(b.pop(i))
        break
      else:
        f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])

Failing test case input:
9
1 1 1 2 2 1 4 3 2

Expected output:
1
2
1
3
2
4
2
1
1


Actual output:
1
2
3
4
1
2
2
1
1


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 1:

    c = len(ans)
    f = b[0]
    for i in range(1, len(b))[::-1]:
      if b[i] == i + 1:

        ans.append(b.pop(i))
        break
    else:
      for i in range(1, len(b)):

        if f >= b[i]:
          ans.append(b.pop(i-1))
          break
        elif n - c == b[i]:
          ans.append(b.pop(i))
          break
        elif i == len(b) - 1:
          ans.append(b.pop(-1))
          break
        else:
          f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
B = list(map(int, input().split()))
ret = [-1] * n
ng = False
for i in range(n):
  p = n - i - 1
  found = False
  for j in range(B[p] - 1, min(n, n - (p - B[p] + 2) + 1)):
    if ret[j] < 0:
      ret[j] = B[p]
      found = True
      break
  if not found:
    ng = True
    break

if ng:
  print(-1)
else:
  for i in range(n):
    print(ret[i])

Failing test case input:
9
1 1 1 2 1 1 2 3 2

Expected output:
1
2
2
3
1
1
2
1
1


Actual output:
1
2
3
2
1
2
1
1
1


Fixed submission (verdict: Accepted):
n = int(input())
B = list(map(int, input().split()))
ret = []
enabled = True

def get_latest():
  for i in range(len(B)):
    if len(B) - i == B[len(B) - i - 1]:
      break
  else:
    global enabled
    enabled = False
  ret.append(B.pop(len(B) - i - 1))
  if B:
    get_latest()

get_latest()
if enabled:
  for i in range(n):
    print(ret[n - i - 1])
else:
  print(-1)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = [int(i) for i in input().split()] 
pool = []

def search_num(num):
  try:
    nn = b.index(num)
    b.remove(num)
    return num
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1

if n != len(b):
  print('-1')
else:
  for i in range(n):
    num = search_num(i+1)
    if num == -1:
      print('-1')
      break
    else:
      pool.append(str(num))
      if i+1 == n:
        text = '\n'.join(pool)
        print(text)

Failing test case input:
9
1 1 1 2 2 1 2 3 2

Expected output:
1
2
2
3
1
2
2
1
1

Actual output:
1
2
3
2
2
2
1
1
1


Fixed submission (verdict: Accepted):
n = int(input())
b = [int(i) for i in input().split()] 
pool = []

def search_num(num):
  try:
    nn = b.index(num)
    if nn + 1 == num:
      b.remove(num)
      return num
    else: return search_num(num-1)
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1

if n != len(b):
  print('-1')
else:
  for i in range(n, 0, -1):
    num = search_num(i+1)
    if num == -1:
      print('-1')
      break
    else:
      pool.append(str(num))
      if i == 1:
        for i in (reversed(pool)):
          print(i)
        break

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list( map(int, input().split()))
ans = []

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

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

    else:
        print(-1)
        exit()


Failing test case input:
9
1 1 1 1 2 1 4 1 2

Expected output:
1
2
1
1
2
4
1
1
1


Actual output:

Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

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

    else:
        print(-1)
        exit()

print(*reversed(ans),sep='\n')
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = []
n = int(input())
b = [int(i) for i in input().split()]

flag = True
if b[0] != 1:
    flag = False

for i in range(n):
    a.insert(b[i]-1,b[i])
    
    if b[i] > i:
        flag = False

if flag == False:
    print("-1")

else:
    for i in a:
        print(i)

Failing test case input:
9
1 1 1 2 2 1 4 1 2

Expected output:
1
2
1
1
2
4
2
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
a = []
n = int(input())
b = [int(i) for i in input().split()]

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

for i in range(n):
    a.insert(b[i]-1,b[i])

if flag == False:
    print("-1")

else:
    for i in a:
        print(i)

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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)

Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
1
1
1
4
2
3
1
2
1


Fixed submission (verdict: Accepted):
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(*reversed(ops), sep="\n")
else:
  print(-1)

Problem: p03089
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
B = list(map(int,input().split()))

ans = []
while N > 0:
  p = False
  for i in range(N)[::-1]:
    b = B[i]
    if b == (i+1):
      ans.append(b)
      p = i
      break
  
  if not p:
    N -= 1
  else:
    newB = []
    for i in range(N):
      if i != p:
        newB.append(B[i])
    
    B = newB
    break
    
if N != 0:
  print(-1)
else:
  print("\n".join(map(str,ans[::-1])))


Failing test case input:
3
1 9 0

Expected output:
-1


Actual output:
1
1
1


Fixed submission (verdict: Accepted):
N = int(input())
B = list(map(int,input().split()))

ans = []
while N > 0:
  ok = False
  for i in range(N)[::-1]:
    b = B[i]
    if b == (i+1):
      ans.append(b)
      ok = True
      k = i
      break
  
  if not ok:
    break
  else:
    newB = []
    for i in range(N):
      if i != k:
        newB.append(B[i])
    
    B = newB
    N -= 1

if N != 0:
  print(-1)
else:
  print("\n".join(map(str,ans[::-1])))
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
b=list(map(int,input().split()))
ans=0
nMax=1
for i in range(n):
    if b[i]<=nMax:
        nMax=b[i]+1
    elif b[i]>nMax:
        ans=-1
        break
if ans==-1:
    print(ans)
else:
    a=[]
    for i in range(n):
        for j in range(len(b)):
            if b[len(b)-1-j]==len(b)-j:
                a.append(b[len(b)-1-j])
                b=b[:len(b)-1-j]+b[len(b)-j:]
                break
    for i in range(n):
        print(a[n-1-i])

Failing test case input:
9
1 1 1 1 2 1 4 3 2

Expected output:
1
2
1
3
2
4
1
1
1


Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
b=list(map(int,input().split()))
a=[]
flg=1
for i in range(n):
    if flg==0:
        break
    else:
        flg=0
    for j in range(len(b)):
        
        if b[len(b)-1-j]==len(b)-j:
            a.append(b[len(b)-1-j])
            b=b[:len(b)-1-j]+b[len(b)-j:]
            
            flg=1
            break
if flg==0:
    print(-1)
else:
    for i in range(n):
        print(a[n-1-i])

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = [int(x) for x in input().split()]
ans = []
while len(b) > 1:
    print(ans)
    tmp = max(b)
    flag = 0
    if tmp >= len(b):
        ans = None
        break
    while flag == 0:
        if b[tmp-1] == tmp: 
            ans.append(b.pop(tmp-1))
            flag = 1
        else:
            tmp -= 1
        if tmp == 0:
            flag = -1
            break
    if flag == -1:
        ans = None
        break

if ans == None or b[0] != 1:
    print(-1)
else: 
    ans.append(1)
    for i in ans[::-1]:
        print(i)


Failing test case input:
3
-2 1 4

Expected output:
-1


Actual output:
[]
-1


Fixed submission (verdict: Accepted):
N = int(input())
b = [int(x) for x in input().split()]
ans = []
while len(b) > 1:
    tmp = max(b)
    flag = 0
    if tmp > len(b):
        ans = None
        break
    while flag == 0:
        if b[tmp-1] == tmp: 
            ans.append(b.pop(tmp-1))
            flag = 1
        else:
            tmp -= 1
        if tmp == 0:
            flag = -1
            break
    if flag == -1:
        ans = None
        break

if ans == None or b[0] != 1:
    print(-1)
else: 
    ans.append(1)
    for i in ans[::-1]:
        print(i)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = [int(i) for i in input().split()] 
pool = []
def search_num(num):
  try:
    nn = b.index(num)
    b.remove(num)
    return num
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1
    
for i in range(n):
  num = search_num(i+1)
  if num == -1:
    print('-1')
    break
  else:
    pool.append(str(num))
    if i+1 == n:
      text = '\n'.join(pool)
      print(text)
      break

Failing test case input:
9
1 1 1 2 2 1 4 1 2

Expected output:
1
2
1
1
2
4
2
1
1


Actual output:
1
2
2
4
2
1
1
1
1


Fixed submission (verdict: Accepted):
n = int(input())
b = [int(i) for i in input().split()] 
pool = []

def search_num(num):
  try:
    nn = b.index(num)
    if nn + 1 == num:
      b.remove(num)
      return num
    else: return search_num(num-1)
  except:
    if num-1 > 0:
      return search_num(num-1)
    else: return -1

if n != len(b):
  print('-1')
else:
  for i in range(n, 0, -1):
    num = search_num(i+1)
    if num == -1:
      print('-1')
      break
    else:
      pool.append(str(num))
      if i == 1:
        for i in (reversed(pool)):
          print(i)
        break

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int, input().split()))
ans = []
for i in reversed(range(n)):
    for j in reversed(range(i+1)):
        if b[j]==j+1:
            ans.append(b[j])
            b.pop(j)
            print(b)
            break

        if j==0:
            print(-1)
            exit()
for i in reversed(range(n)):
    print(ans[i])

Failing test case input:
9
1 1 1 1 2 1 2 3 2

Expected output:
1
2
2
3
1
2
1
1
1


Actual output:
[1, 1, 1, 2, 1, 2, 3, 2]
[1, 1, 2, 1, 2, 3, 2]
[1, 2, 1, 2, 3, 2]
[1, 1, 2, 3, 2]
[1, 2, 3, 2]
[1, 2, 2]
[1, 2]
[1]
[]
1
2
2
3
1
2
1
1
1


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int, input().split()))
ans = []
for i in reversed(range(n)):
    for j in reversed(range(i+1)):
        if b[j]==j+1:
            ans.append(b[j])
            b.pop(j)
            break

        if j==0:
            print(-1)
            exit()
for i in reversed(range(n)):
    print(ans[i])