qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys


def input():
    return sys.stdin.readline().strip()


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


def check(B, cnt):
    n = len(B)
    for i in range(n):
        if B[n - i - 1] == (n - i):
            hand.append(B[n - i - 1])
            B = B[: n - i - 1] + B[n - i :]
            break
    if len(B) != n and len(B) > 0:
        return B
    else:
        return False


cnt = 1
while B:
    B = check(B, cnt)
    # print(B)

if len(hand) < N:
    print(-1)
    sys.exit()
for i in range(N):
    if hand[i] > i + 1:
        print(-1)
        sys.exit()
answer = hand[::-1]
print(*answer, sep="\n")


Fixed code:
import sys


def input():
    return sys.stdin.readline().strip()


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


def check(B, cnt):
    n = len(B)
    for i in range(n):
        if B[n - i - 1] == (n - i):
            hand.append(B[n - i - 1])
            B = B[: n - i - 1] + B[n - i :]
            break
    if len(B) != n and len(B) > 0:
        return B
    else:
        return False


cnt = 1
while B:
    B = check(B, cnt)
    # print(B)

if len(hand) < N:
    print(-1)
    sys.exit()
answer = hand[::-1]
for i in range(N):
    if answer[i] > i + 1:
        print(-1)
        sys.exit()
print(*answer, sep="\n")
Buggy code:
n=int(input())
b=list(map(int,input().split()))
l=len(b)
a=[]
f=0
for _ in range(n):
  for i in range(l-1,-1,-1):
    if b[i]==i+1:
      a.append(b.pop(i))
      break
    if i==0:
      f=1
if f==0:
  for i in range(l-1,-1,-1):
    print(a[i])
else:
  print(-1)

Fixed code:
n=int(input())
b=list(map(int,input().split()))
a=[]
f=0
for _ in range(n):
  for i in range(len(b)-1,-1,-1):
    if b[i]==i+1:
      a.append(b.pop(i))
      break
    if i==0:
      f=1
if f==0:
  for i in range(n-1,-1,-1):
    print(a[i])
else:
  print(-1)
Buggy code:
# AGC032 Problem-AGC032

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

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


Fixed code:
# AGC032 Problem-AGC032

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

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

def chousa(b):
    poped = ["x"]*len(b)
    a = []
    isnt_sorted = len(b)
    while isnt_sorted:
        for i,v in enumerate(b[::-1]):
            if v == 1 and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break
            elif len(a) >= v-1 and a[v-2][0] < len(b)-i and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break

        print(v)
def main():
    N = int(input())
    b = list(map(int,input().split()))
    chousa(b)
if __name__ == "__main__":
    main()

Fixed code:

def chousa(b):
    poped = ["x"]*len(b)
    a = []
    isnt_sorted = len(b)
    for i,v in enumerate(b[::-1]):
        if len(b)-i < v:
            print(-1)
            return

    while isnt_sorted:
        for i,v in enumerate(b[::-1]):
            if v == 1 and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break
            elif len(a) >= v-1 and a[v-2][0] < len(b)-i and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break

        print(v)
def main():
    N = int(input())
    b = list(map(int,input().split()))
    chousa(b)
if __name__ == "__main__":
    main()
Buggy code:
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])


Fixed code:
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])
Buggy code:
import sys

N = int(input())
b = map(int, input().split())
# 1 1 1 2 2 1 2 3 2


# b = map(int, '1 1 1 2 2 1 2 3 2'.split())
# N = len(b)

steps = []
for i in range(N):
    cands = []
    for j in range(N - i):
        if (j + 1) == b[j]:
            cands.append(j)
    if len(cands) == 0:
        print(-1)
        sys.exit()
    else:
        j = cands[-1]
        steps.append(j + 1)
        b = b[:j] + b[j+1:]
for s in steps[::-1]:
    print(s)


Fixed code:
import sys

N = int(input())
b = list(map(int, input().split()))
# 1 1 1 2 2 1 2 3 2


# b = map(int, '1 1 1 2 2 1 2 3 2'.split())
# N = len(b)

steps = []
for i in range(N):
    cands = []
    for j in range(N - i):
        if (j + 1) == b[j]:
            cands.append(j)
    if len(cands) == 0:
        print(-1)
        sys.exit()
    else:
        j = cands[-1]
        steps.append(j + 1)
        b = b[:j] + b[j+1:]
for s in steps[::-1]:
    print(s)
Buggy code:
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]))


Fixed code:
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]))
Buggy code:
n=int(input())
x=list(map(int,input().split()))
l=[]
while len(x):
    for i,a in enumerate(x):
        if a==i+1:
            index=i
    l.append(x.pop(index))
for i in reversed(l):
    print(i)

Fixed code:
n=int(input())
x=list(map(int,input().split()))
l=[]
while len(x):
    index=-1
    for i,a in enumerate(x):
        if a==i+1:
            index=i
    if index == -1:
        print(-1)
        break
    l.append(x.pop(index))
else:
    for i in reversed(l):
        print(i)
Buggy code:
from sys import stdin

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

    ans = []
    for n in range(N, 0, -1):
        for i in range(N-1, -1, -1):
            if not B[i]:
                continue
            if B[i] == n:
                ans.append(n)
                B[i] = 0
                break
            n -= 1
    print(*ans[::-1], sep='\n')

input = lambda: stdin.readline()
main()


Fixed code:
from sys import stdin

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

    ans = []
    for n in range(N, 0, -1):
        for i in range(N-1, -1, -1):
            if not B[i]:
                continue
            if B[i] == n:
                ans.append(n)
                B[i] = 0
                break
            n -= 1
        else:
            print(-1)
            return
    print(*ans[::-1], sep='\n')

input = lambda: stdin.readline()
main()
Buggy code:
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []

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

for i in range(N): 
    
    for j in range(N-i, 0, -1):
        
        if b_list[j-1] == j:
            answer_list.append(b_list[j-1])
            b_list.pop(j-1)
            
            break

answer_list.reverse()


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

Fixed code:
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []
check = 0

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        check = 1
        break

if check == 0:
    for i in range(N):     
        for j in range(N-i, 0, -1):
            
            if b_list[j-1] == j:
                answer_list.append(b_list[j-1])
                b_list.pop(j-1)
                
                break

    answer_list.reverse()


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

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

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

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

Fixed code:
n=int(input())
hoge=list(map(int,input().split()))
ans=[]
for i in range(n):
  for j in range(len(hoge)):
    if(hoge[-j-1]==len(hoge)-j):
      ans.append(hoge[-j-1])
      hoge.pop(-j-1)
      break
ans.reverse()
if(len(hoge)==0):
  for i in ans:
    print(i)
else:
  print(-1)
Buggy code:
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)

Fixed code:
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)
Buggy code:
n=int(input())
b = list(map(int, input().split()))
ans=[]
dl = -1
for num in range(n):
    for i in range(len(b)):
        if b[i] == i+1:
            dl=i
    if dl==-1:
        print(-1)
        exit()
    b.pop(dl)
    ans.append(dl+1)
ans = list(reversed(ans))
for i in ans:
    print(i)

Fixed code:
n=int(input())
b = list(map(int, input().split()))
ans=[]
for num in range(n):
    dl=-1
    for i in range(len(b)):
        if b[i] == i+1:
            dl=i
    if dl==-1:
        print(-1)
        exit()
    b.pop(dl)
    ans.append(dl+1)
ans = list(reversed(ans))
for i in ans:
    print(i)
Buggy code:
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)

Fixed code:
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)
Buggy code:
N = int(input())
prob = list(map(int, input().split()))
ans = []
for i in reversed(range(N)):
  boo = False
  for j in reversed(range(i + 1)):
    if prob[j] == j + 1:
      boo = True
      ans.append(j + 1)
      del prob[j]
      break
  if not boo:
    break
if len(ans) == N:
  for x in ans:
    print(x)
else:
  print(-1)

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

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

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

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

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

for e in a:
    print(e)
Buggy code:
n = int(input())
b = list(map(int,input().split()))
p = []

for i in range(n):
    nn = len(b)
    for j in range(nn-1,-1,-1):
        if b[j] == j+1:
            b = b[:j]+b[j+1:]
            p.append(c[j])
            break
            
if b == []:
    for i in range(n-1,-1,-1):
        print(p[i])
else:
    print(-1)

Fixed code:
n = int(input())
b = list(map(int,input().split()))
p = []

for i in range(n):
    nn = len(b)
    for j in range(nn-1,-1,-1):
        if b[j] == j+1:
            p.append(b[j])
            b = b[:j]+b[j+1:]
            break
            
if b == []:
    for i in range(n-1,-1,-1):
        print(p[i])
else:
    print(-1)
Buggy code:
n = int(input())
b = list(map(int, input().split()))
b.reverse()
ans_set = [0]*n

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

        if n == 0:
            break

for k in ans_set:
    print(k)

Fixed code:
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)
Buggy code:
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)

Fixed code:
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)
Buggy code:
n=int(input())
b=list(map(int,input().split()))
ans=[]
while True:
    l=len(b)
    temp=[]
    for i in range(l-1,-1,-1):
        if b[i]==i+1: ans.append(i+1)
        else: temp.append(b[i])
    b=temp[:]
    if len(b)==l:
        print(-1)
        exit()
    elif len(b)==0: break
for val in ans[::-1]: print(val)

Fixed code:
n=int(input())
b=list(map(int,input().split()))
ans=[]
while True:
    l=len(b)
    temp=[]
    flag=0
    for i in range(l-1,-1,-1):
        if flag==1 or b[i]!=i+1: temp.append(b[i])
        else:
            ans.append(i+1)
            flag=1
    b=temp[::-1]
    if len(b)==l:
        print(-1)
        exit()
    elif len(b)==0: break
for val in ans[::-1]: print(val)
Buggy code:
import copy

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


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        for i in temp[::-1]:
            root.append(i)
            string.pop(i-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root:
        print(i)

Fixed code:
import copy

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


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)
Buggy code:
N = int(input())
b = list(map(int,input().split()))

ans = []
while(True):
    if len(b) == 0:
        print(*ans,sep="\n")
        break
    for i in range(len(b)-1,-1,-1):
        if b[i] == i+1:
            ans.append(b.pop(i))
            break
    else:
        print(-1)

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

ans = []
while(True):
    if len(b) == 0:
        ans.reverse()
        print(*ans,sep="\n")
        break
    for i in range(len(b)-1,-1,-1):
        if b[i] == i+1:
            ans.append(b.pop(i))
            break
    else:
        print(-1)
        break
Buggy code:
from collections import Counter
import sys
def zur(z, xx):
    c = 0
    for i in range(z):
        i += 1
        if i not in xx:
            c += 1
        if c == z:
            return c + z

def xxxxx(z, xx):
    if z not in xx:
        return z
    while True:
        z -= 1
        if z == 0:
            print(-1)
            sys.exit()
        if z not in xx:
            return z

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

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

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

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

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


Fixed code:
from collections import Counter
import sys
def zur(z, xx):
    c = 0
    k = 0
    i = 0
    while True:
        i += 1
        if i in xx:
            c += 1
        else:
            k += 1
        if k == z:
            return z + c

def xxxxx(z, xx):
    if z not in xx:
        return z
    while True:
        z -= 1
        if z == 0:
            print(-1)
            sys.exit()
        if z not in xx:
            return z

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

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


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

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

for i, x in sorted(xo, key=lambda x:x[0]):
    print(x)
Buggy code:
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))


Fixed code:
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))
Buggy code:
n,*bb = map(int, open(0).read().split())

ans = []

while bb:
    for i,v in zip(range(len(bb),0,-1),bb[::-1]):
#         print(i,v)
        if i==v:
            ans.append(v)
            del bb[i-1]
            break

for a in ans[::-1]:
    print(a)

Fixed code:
n,*bb = map(int, open(0).read().split())

ans = []

while bb:
    imp = True
    for i,v in zip(range(len(bb),0,-1),bb[::-1]):
#         print(i,v)
        if i==v:
            ans.append(v)
            del bb[i-1]
            imp = False
            break
    if imp:
        ans = [-1]
        break

for a in ans[::-1]:
    print(a)
Buggy code:
N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
for i in ans[::-1]:
    print(i)

Fixed code:
N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
if len(ans)==N:
    for i in ans[::-1]:
        print(i)
else:
    print(-1)
Buggy code:
n = int(input())
bs = list(map(int, input().split()))

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

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

ops = []
for i in range(n):
  for j, b in enumerate(reversed(bs)):
    if n - i - j == b:
      bs.pop(n-i-j-1)
      ops.append(n-i-j)
      break
  if len(bs) == n-i:
    break
if len(ops) == n:
  print(*reversed(ops), sep="\n")
else:
  print(-1)
Buggy code:
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):
        #print(b[i] ,i)
        if a[i] == i+1:
            l.append(a.pop(i))
            break
print("\n".join(map(str,reversed(l))))

Fixed code:
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):
        #print(b[i] ,i)
        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)
Buggy code:
N=int(input())
b=list(map(int, inputs().split()))
ans=[]
for i in range(N):
  for j in range(len(b)):
    if b[j]==j+1:
      ans.append(b.pop(j))
      break
for i in range(N-1, -1, -1):
  print(ans[i])

Fixed code:
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.pop(j))
      break
      
if len(ans)<N:
  print(-1)
else:
  for i in range(N-1, -1, -1):
    print(ans[i])
Buggy code:
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            res.append(j)
            B.pop(j - 1)
            break
    else:
        print(-1)
        exit()1

for r in res[::-1]:
    print(r)


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

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)