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


Failing test case input:
3
-2 0 4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
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

    if br:
        print(-1)
    else:
        for _ in range(len(a)):
            print(a.pop())

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
s=list(map(int,input().split()))


result=[]

for i in range(n-1):
    posi=-1
    for j in range(min(i+1,n-i-1)):
        if s[j]<=i+1:
            posi=j
    if posi!=-1:
        result.append(s[posi])
        s.pop(posi)
    else:
        print(posi)
        exit()
    
    

for item in result:
    print(item)



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
2
2
3
1
1
1


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


result=[]

for i in range(n):
    posi=-1
    for index,ss in enumerate(s):
        if ss==index+1:
            posi=index
    if posi==-1:
        print(-1)
        exit()
    else:
        result.append(s[posi])
        s.pop(posi)

for item in result[::-1]:
    print(item)

Problem: p03089
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


n = int(input())
nums = [int(i) for i in input().split()]
nums.sort()
ans = []
for i, num in enumerate(nums, start=1):
    if num <= i:
        ans.append(num)
    else:
        print(-1)
        break
else:
    for a in ans:
        print(a)

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
1
1
1
1
2
2
2
3


Fixed submission (verdict: Accepted):

import sys

n = int(input())
nums = [int(i) - 1 for i in input().split()]
ans = []
for i in range(n):
    for j in range(len(nums) - 1, -1, -1):
        if nums[j] == j:
            ans.append(j + 1)
            del nums[j]
            break
    else:
        print(-1)
        sys.exit()
for a in ans[::-1]:
    print(a)
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):
    for j in range(len(b)-1,-1,-1):
        if b[j] <= j+1:
            ans.append(b[j])
            b.pop(j)
            break
if len(ans) == N:
    for i in ans:
        print(i)
else:
    print(-1)


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:
2
3
2
1
2
1
1
1
1


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

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,*B = map(int, open(0).read().split())
ans = [0]*N
for i in range(N):
  for j in range(len(B)-1,-1,-1):
    if B[j]==j+1:
      ans[N-1-i] = j+1
      B = B[:j]+B[j+1:]
      break
print('\n'.join(map(str,ans)))

Failing test case input:
3
-2 1 4

Expected output:
-1


Actual output:
0
0
0


Fixed submission (verdict: Accepted):
N,*B = map(int, open(0).read().split())
ans = [0]*N
for i in range(N):
  for j in range(len(B)-1,-1,-1):
    if B[j]==j+1:
      ans[N-1-i] = j+1
      B = B[:j]+B[j+1:]
      break
if B==[]:
  print('\n'.join(map(str,ans)))
else:
  print(-1)

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

a=[]
while b:
    f=True
    if b[0]!=1:
        print(-1)
        exit()
    if len(b)==1:
        a.append(b.pop())
        break
    for i in range(1,len(b)):
        if b[i]!=i+1:
            temp=b.pop(i-1)
            a.append(temp)
            f=False
            break

    if f:
        a.append(b.pop())
        
for i in range(N):
    print(a[-1*(i+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()))

a=[]
while b:
    f=True
    if len(b)==1:
        if b[0]!=1:
            print(-1)
            exit()
        else:
            a.append(b.pop())
        break
    for i in range(len(b)-1,-1,-1):
        if b[i]==i+1:
            temp=b.pop(i)
            a.append(temp)
            f=False
            break
    if f:
        print(-1)
        exit()

for i in range(N):
    print(a[-1*(i+1)])
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int, input().split()))
b = [b[0]] + b[1:][::-1]

ans = []
for i, j in enumerate(b):
    if i + 2 < j:
        print(-1)
        exit()
    else:
        ans.append(str(j))
print(*ans, sep="\n")

Failing test case input:
3
-2 4 3

Expected output:
-1


Actual output:
-2
3
4


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

ans = []
for i in range(n):
    tmp = -1
    for j, k in enumerate(b):
        if j + 1 == k:
            tmp = j
    if tmp == -1:
        print(-1)
        exit()
    else:
        ans.append(b.pop(tmp))
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()))
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):
        if b[n-i-1]!=1:
            a.append(b[n-i-1])
        else:
            print(b[n-i-1])
            a.sort()
            for j in range(len(a)):
                print(a[j])
            a=[]

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()))
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 = list(map(int,input().split()))
bc = b[::-1]
a = []
s = 0
for i in range(n):
    if bc[i] == 1:
        sbc = sorted(bc[s:i+1],reverse=True)
        if sbc[0] <= len(sbc):
            for j in sorted(sbc):
                a.append(j)
            s = i+1
        else:
            print(-1)
            exit()
if not a:
    print(-1)
    exit()

for k in a:
    print(k)

Failing test case input:
3
2 4 1

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int,input().split()))
bc = b[::-1]
a = []
while bc:
    for i in range(len(bc)):
        if bc[i] == len(bc)-i:
            a.append(bc[i])
            bc.pop(i)
            break
    else:
        print(-1)
        exit()
        
a = a[::-1]
for k in a:
    print(k)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)



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):
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, -1, -1):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])
            break


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

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):





import itertools



import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

    res = [0] * n

    for current_num in range(n, 0, -1):
        for i in range(n):
            if b[i] == current_num:
                idx = (n + current_num - (i+1)) - 1
                if idx > n - 1:
                    print(-1)
                    sys.exit()
                while res[idx] != 0:
                    idx -= 1
                res[idx] = current_num

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

if __name__ == '__main__':
    main()

Failing test case input:
3
0 8 0

Expected output:
-1


Actual output:
0
0
0


Fixed submission (verdict: Accepted):





import itertools



import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

    res = [0] * n

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

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




if __name__ == '__main__':
    main()

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

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

Failing test case input:
3
-1 9 0

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

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())
l=list(map(int,input().split()))
ans=[]
for i in range(n)[::-1]:
  for j in range(i+1)[::-1]:
    if l[j]==j+1:
      a=l.pop(j)
      ans.append(a)
      break
    if j==0 and l[j]!=1:
      break
if l!=[]:
  print(-1)
else:
  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()))

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

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

for a in ans:
  print(a)

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


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

Failing test case input:
3
-1 11 4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
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())
if(a):
    print(-1)

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  if a[i] == i+1:
    print(-1)
    exit()
  else:
    b.insert(a[i]-1,a[i])
for i in range(n):
  print(b[i])

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())
a = list(map(int,input().split()))
b = []
for i in range(n):
  if a[i] > i+1:
    print(-1)
    exit()
  else:
    b.insert(a[i]-1,a[i])
for i in range(n):
  print(b[i])
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 + 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)


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


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
1
2
4
2
1
1
2
1


Fixed submission (verdict: Accepted):
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 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())
S=list(map(int,input().split()))
LIST=list("")

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

while(len(S)>0):
    M=max(S)
    S.remove(M)
    LIST.append(M)

for i in range(len(LIST)-1,-1,-1):
    print(LIST[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
1
1
2
2
2
3


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

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

while(len(S)>0):
    c=10**10
    for i in range (len(S)):
        if(S[i]==i+1):
            c=i
    if(c==(10**10)):
        print("-1")
        exit()  
    LIST.append(S.pop(c))

for i in range(len(LIST)-1,-1,-1):
    print(LIST[i])
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
b = [int(x) for x in str(input()).split(' ')]

out = []
for i, x in enumerate(b):
    if x > i+1:
        print(x, i+1)
        out = [-1]
        break
    else:
        out.insert(x-1, x)

for x in out:
    print(x)

Failing test case input:
3
1 7 0

Expected output:
-1


Actual output:
7 2
-1


Fixed submission (verdict: Accepted):
N = int(input())
b = [int(x) for x in str(input()).split(' ')]

out = []
for i, x in enumerate(b):
    if x > i+1:
        out = [-1]
        break
    else:
        out.insert(x-1, x)

for x in out:
    print(x)

Problem: p03089
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
b = [0] + list(map(int, input().split()))

flag = [1] * (N + 1) 
ans = []
i = N
_i = 0
while True:
    
    if b[i - _i] > i - _i:
        print(-1)
        break
    elif b[i - _i] == i - _i:
        ans.append(i - _i)
        del b[i - _i]
        i -= 1
        _i = 0
    else:
        _i += 1
    if _i >= i:
        
        break
for a in reversed(ans):
    print(a)

Failing test case input:
3
-2 4 3

Expected output:
-1


Actual output:
-1
3


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

flag = [1] * (N + 1) 
ans = []
i = N
_i = 0
while True:
    
    if b[i - _i] > i - _i:
        print(-1)
        exit()
        break
    elif b[i - _i] == i - _i:
        ans.append(i - _i)
        del b[i - _i]
        i -= 1
        _i = 0
    else:
        _i += 1
    if _i >= i:
        
        break
for a in reversed(ans):
    print(a)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

b = []
for _b in list(map(int, input().split())):
    if _b > len(b) + 1:
        print('-1')
        exit()
    b.insert(_b, str(_b))

print('\n'.join(b))


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
1
2
1
1
2
4
2
1


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

b = []
for _b in list(map(int, input().split())):
    if _b > len(b) + 1:
        print('-1')
        exit()
    b.insert(_b - 1, str(_b))

print('\n'.join(b))

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int, input().split()))
x = ""
ok = True
if 1 not in b or b[0] != 1: False
else:
    for i in range(1, n+1):
        if b[-i] == 1:
            if x=="": a = b[-i:]
            else: a = b[-i:x]
            a.sort()
            for v in a: print(v)
            x = -i
if not ok: print(-1)

Failing test case input:
3
-1 9 2

Expected output:
-1


Actual output:

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 sys
n = int(input())
a = []
b = list(map(int, input().split()))
flag = True
for _ in range(n):
    add = 0
    for j in range(1, len(b)+1):
        if j == b[j-1]:
            add = max(add, j)
    if add == 0:
        flag = False
        break
    a.append(add)
    del b[add-1]
if flag:
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

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
4
2
1
1
2
1


Fixed submission (verdict: Accepted):

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

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

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
1
2
2
1
1
1
2
1


Fixed submission (verdict: Accepted):
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 reversed(ans):
    print(x)
else:
  print(-1)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
b=list(map(int,input().split()))
sa=[i-b[i-1] for i in range(1,N+1)]
ans=[0 for i in range(N)]
for i in reversed(range(1,N+1)):
    cnt=0
    for j in range(1,N+1):
        if ans[-1*j]==0:
            if cnt!=sa[i-1]:
                cnt+=1
            else:
                ans[-1*j]=b[i-1]
if all(k!=0 for k in ans):
    for i in ans:
        print(i)
else:
    print("-1")
                

Failing test case input:
3
1 7 0

Expected output:
-1


Actual output:
1
1
1


Fixed submission (verdict: Accepted):
N=int(input())
b=list(map(int,input().split()))
sa=[i-b[i-1] for i in range(1,N+1)]
ans=[0 for i in range(N)]
for i in reversed(range(1,N+1)):
    cnt=0
    for j in range(1,N+1):
        if ans[-1*j]==0:
            if cnt!=sa[i-1]:
                cnt+=1
            else:
                ans[-1*j]=b[i-1]
                break
if all(k!=0 for k in ans):
    for i in ans:
        print(i)
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()]
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)

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 = [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):
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ 0 ] * N

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

print(solve())

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):
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())
b = list(map(int, input().split()))
a = [0]*n
if b[0]!=1:
    print(-1)
    exit()
a[0] = b[0]
for i in range(1,n):
    if b[i]==1:
        a[i]=1
    else:
        a[i] = b[i]
        for j in range(i):
            if a[j]==0:
                print(-1)
                exit()
a.sort()
for i in range(n):
    print(a[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
1
1
1
1
2
2
2
4


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])
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])
    del bs[change_i]

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


Failing test case input:
3
0 9 0

Expected output:
-1


Actual output:
0
9
0


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

l = input().split()

res = []

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

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

            

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


Failing test case input:
3
-2 1 6

Expected output:
-1


Actual output:
6
1
-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):
def main():
    from collections import deque
    N = int(input())
    B = deque(list(map(int, input().split())))
    temp = deque([])
    result = []
    for i in range(N):
        b = B.pop()
        temp.appendleft(b)
        if b == 1:
            work = []
            for t in temp:
                if t-1 > len(work):
                    print(-1)
                    return
                else:
                    work.insert(t-1, t)
            for w in work:
                result.append(w)
            temp = deque([])
    if len(result) == 0:
        print(-1)
    for r in result:
        print(r)
main()

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):
def main():
    from collections import deque
    N = int(input())
    B = deque(list(map(int, input().split())))
    result = deque([])
    for i in range(N):
        flag = False
        for j in range(len(B), 0, -1):
            b = B[j-1]
            if j == b:
                del B[j-1]
                result.append(b)
                flag = True
                break
        if not flag:
            print(-1)
            return
    for j in range(len(result)-1, -1, -1):
        print(result[j])
main()
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

l = input().split()

res = []

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


            

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


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):
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):
import math

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

a = []
print(b)
for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
    else:
        break

if(a != b):
    print(-1)
else:
    for i in range(len(a)):
        print(a[i])


Failing test case input:
3
-1 11 4

Expected output:
-1


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


Fixed submission (verdict: Accepted):
import math

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

a = []
lis = []

for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
        lis.insert(b[i-1]-1, b[i-1])
    else:
        break

if(a != b):
    print(-1)
else:
    for i in range(len(a)):
        print(lis[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:
    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:
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 = [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 = list(map(int, input().split()))

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

a = []
i = 0
while(i < len(b)):
    if(b[i] == i + 1):
        i += 1
        continue
    pick = b[i - 1]
    b.remove(pick)
    a = [pick] + a

for i in range(len(b) - 1, -1, -1):
    a = [b[i]] + a

for i in a:
    print(str(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
4
2
3
1
2
1
1
1


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

a = []
i = len(b) - 1
while(i >= 0):
    if(i + 1 == b[i]):
        pick = b[i]
        b.remove(pick)
        a = [pick] + a
        i = len(b)
    i -= 1

if(len(b) > 0):
    print("-1")
    exit()

for i in a:
    print(str(i))

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

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

a = []

for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
    else:
        break

if(a != b):
    print(-1)
else:
    for i in range(len(a)):
        print(a[i])


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
1
1
2
2
1
1
1
2


Fixed submission (verdict: Accepted):
import math

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

a = []
lis = []

for i in range(1, n+1):
    if(b[i-1] <= i):
        a.append(b[i-1])
        lis.insert(b[i-1]-1, b[i-1])
    else:
        break

if(a != b):
    print(-1)
else:
    for i in range(len(a)):
        print(lis[i])

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

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
4
2
1
1
2
1


Fixed submission (verdict: Accepted):
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[::-1]:
    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]
    turn-=1
print(*ans[::-1],sep='\n')

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=[]
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 = input()
b = list(map(int,input().split()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        
        if a[i] == i+1:
            l.append(a.pop(i))
            break
print("\n".join(map(str,reversed(l))))

Failing test case input:
3
0 9 0

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
b = list(map(int,input().split()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        
        if a[i] == i+1:
            l.append(a.pop(i))
            break
if len(l) == N:
    print("\n".join(map(str,reversed(l))))
else:
    print(-1)

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
s=list(map(int,input().split()))


result=[]

for i in range(n-1):
    posi=-1
    for j in range(min(i+1,n-i-1)):
        if s[j]<=i+1:
            posi=j
    if posi!=-1:
        result.append(s[posi])
        s.pop(posi)
    print(s)
    print(result)

for item in result:
    print(item)



Failing test case input:
3
0 8 0

Expected output:
-1


Actual output:
[8, 0]
[0]
[8, 0]
[0]
0


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


result=[]

for i in range(n):
    posi=-1
    for index,ss in enumerate(s):
        if ss==index+1:
            posi=index
    if posi==-1:
        print(-1)
        exit()
    else:
        result.append(s[posi])
        s.pop(posi)

for item in result[::-1]:
    print(item)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

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:

Fixed submission (verdict: Accepted):
import copy
N = int(input())
N2 = copy.copy(N)
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 j in range(1, N2+1):
        print(ans[-j])
else:
    print(-1)

Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
L=list(map(int,input().split()))
ans=[]
def mal(x):
    if len(x)==0:
        return []
    else:
        t=max(x)
        i=x.index(t)
        if i<t-1:
            print(-1)
            exit()
        after=x[:i-t+1]
        before=x[i-t+1:]
        before.remove(t)
        return mal(before)+[t]+mal(after)
ans=mal(L)

for i in range(n):
    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())
L=list(map(int,input().split()))
for i in range(n):
    if L[i]>i+1:
        print(-1)
        exit()
def mal(x):
    if len(x)==0:
        return []
    else:
        t=max(x)
        i=x.index(t)
        k=i-1
        while k>i-t:
            if x[k]>t-i+k:
                t=x[k]
                i=k
            k -= 1
        after=x[:i-t+1]
        before=x[i-t+1:]
        before.remove(t)
        return mal(before)+[t]+mal(after)
ans=mal(L)

for i in range(n):
    print(ans[i])
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
b = list(map(int,input().split()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        
        if a[i] == i+1:
            l.append(a.pop(i))
            break
if len(l) == N:
    print("\n".join(map(str,reversed(l))))
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()))
a = b.copy()
l = []
for idx,num in enumerate(b):
    for i in range(len(b)-idx-1,-1,-1):
        
        if a[i] == i+1:
            l.append(a.pop(i))
            break
if len(l) == N:
    print("\n".join(map(str,reversed(l))))
else:
    print(-1)

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

Failing test case input:
3
0 11 4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
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()
if(len(hoge)==0):
  for i in ans:
    print(i)
else:
  print(-1)

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
















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

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




Failing test case input:
3
-2 4 4

Expected output:
-1


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


Fixed submission (verdict: Accepted):
















a = []

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



N = 100




for i in range(num_len):
    
    
    
    
    
    

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


if flag:
    for i in a:
        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()))
ret = []

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

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

Failing test case input:
3
-2 11 4

Expected output:
-1


Actual output:
4
11
-2


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())
d=list(map(int,input().split()))
b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
c=[]
for i in range(n-1,-1,-1):
    if 0<b[i][1]<=i+1 and 0<b[i][0]<=i+1:
        c.append(b[i][1])
        d.pop(b[i][0]-1)
        b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
    else:
        print(-1)
        break
else:
    for i in c[::-1]:
        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
1
1
1
1
2
2
2
4


Fixed submission (verdict: Accepted):
n=int(input())
d=list(map(int,input().split()))
b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
c=[]
while len(b)>0:
    for i in range(len(b)-1,-1,-1):
        if 0<b[i][1]<=len(b) and 0<b[i][0]<=len(b) and b[i][0]==b[i][1]:
            c.append(b[i][1])
            d.pop(b[i][0]-1)
            b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
            break
    else:
        print(-1)
        break
else:
    for i in c[::-1]:
        print(i)

Problem: p03089
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    for j in range(0,i):
      key = 0
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

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):
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    key = 0
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
if b[0] != 1:
  flag = 1
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

N = int(input())
max = 0
b = [int(x) for x in input().split()]
flag = [0 for x in range(N)]
for i in b:
    if i > max:
        max = i
submax = max
ans = []
while b != []:
    if ((submax) == my_index(b,submax-1)):
        ans.append(b.pop(submax-1))
        submax = max
    else :
        submax = submax-1
        if b[0] != 1:
            print(-1)
            exit()

for x in range(len(ans)):
    print(ans.pop())

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
1
2
1
2
3
2


Fixed submission (verdict: Accepted):
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

N = int(input())
max = 0
b = [int(x) for x in input().split()]
flag = [0 for x in range(N)]
for i in b:
    if i > max:
        max = i
submax = max
ans = []
while b != []:
    if ((submax-1) == my_index(b,submax)):
        ans.append(b.pop(submax-1))
        submax = max
    else :
        submax = submax-1
        if b[0] != 1:
            print(-1)
            exit()

for x in range(len(ans)):
    print(ans.pop(len(ans)-1))

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

for i in b:
    if len(ans) >= i-1:
        ans.insert(i-1, i)
    else:
        print(-1)
        break
for i in ans:
    print(i, sep='\n')


Failing test case input:
3
-2 4 4

Expected output:
-1


Actual output:
-1
-2


Fixed submission (verdict: Accepted):
import sys
n = int(input())
b = list(map(int, input().split()))
ans = []

for i in b:
    if len(ans) >= i-1:
        ans.insert(i-1, i)
    else:
        print(-1)
        sys.exit()
for i in ans:
    print(i, sep='\n')
Problem: p03089
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter


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):
    ans = ans[::-1]
    for i in range(N):
        print(ans[i])
else:
    print(-1)

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 = []
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()))
ans=[]
count=0
while len(b)>0:
  count+=1
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(b.pop(i-1))
  if count==101:
    print(-1)
    exit()
ans.reverse()
for i in range(n):
  print(ans[i])

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()))
ans=[]
count=0
while len(b)>0:
  count+=1
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(b.pop(i-1))
      break
  if count==101:
    print(-1)
    exit()
ans.reverse()
for i in range(n):
  print(ans[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 = []
for i in range(1,N+1):
    if i >= b_[i-1]:
        a.append(b_[i-1])
if len(a)==len(b_):
    for s in a:
        print(s)
else:
    print(-1)

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
1
1
1
1
2
2
2
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)