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

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

Fixed code:
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)
Buggy code:
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)
# print(seq)

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

Fixed code:
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)
# print(seq)

if len(s) == 0:
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")
Buggy code:
#coding: utf-8
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)

Fixed code:
#coding: utf-8
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)
Buggy code:
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
      break
  
  if ok:
    N -= 1
  else:
    break
    
if N != 0:
  print(-1)
else:
  print("\n".join(map(str,ans[::-1])))

Fixed code:
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])))
Buggy code:
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(len(ans)-1))

Fixed code:
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))
Buggy code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

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

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

ans = []
for _ in range(N):
    for i in range(len(data) - 1, -1, -1):
        #print(data,i)
        if data[i] == i+1:
            #print(data[i-1],i,data)
            ans.append(data.pop(-(len(data)-i)))
            break
if data:
    print(-1)
else:
    for j in reversed(ans):
        print(j)
Buggy code:
n = int(input())
a = map(int, input().split())

ops = []
while len(a):
  if not any(a[i] == i + 1 for i in range(len(a))):
    print(-1)
    exit()
  for i in range(reversed(len(a))):
    if a[i] == i + 1:
      ops.append(a[i])
      a.pop(i)
      break

for op in reversed(ops):
  print(op)



Fixed code:
n = int(input())
a = list(map(int, input().split()))
 
ops = []
while len(a):
  if not any(a[i] == i + 1 for i in range(len(a))):
    print(-1)
    exit()
  for i in reversed(range(len(a))):
    if a[i] == i + 1:
      ops.append(a[i])
      a.pop(i)
      break
 
for op in reversed(ops):
  print(op)
Buggy code:
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])

Fixed code:
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])
Buggy code:
N = int(input())
b = [int(i) for i in input().split()]
a = [0 for i in range(N)]
number = []
for j in range(N):
    for i in range(len(b)-1,-1,-1):
        if(i+1==b[i] and a[i]==0):
            del a[i]
            number.append(b[i])
            del b[i]
            break
if(not a):
    for i in range(N):
        print(number.pop())

Fixed code:
N = int(input())
b = [int(i) for i in input().split()]
a = [0 for i in range(N)]
number = []
for j in range(N):
    for i in range(len(b)-1,-1,-1):
        if(i+1==b[i] and a[i]==0):
            del a[i]
            number.append(b[i])
            del b[i]
            break
if(not a):
    for i in range(N):
        print(number.pop())
if(a):
    print(-1)
Buggy code:
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])))

Fixed code:
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])))
Buggy code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    out.append(bs[change_i])
    print(out)
    del bs[change_i]

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


Fixed code:
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    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)
Buggy code:
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n):
    for j in range(len(B))[::-1]:
        if B[j]==j+1:
            A.append(B.pop(j))
            break
for i in A[::-1]:print(i)

Fixed code:
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n):
    for j in range(len(B))[::-1]:
        if B[j]==j+1:
            A.append(B.pop(j))
            break
    else:print(-1);exit()
for i in A[::-1]:print(i)
Buggy code:
n=int(input())
m=list(map(int,input().split()))
ans=[]
for i in range(n):
  for j in range(i,-1,-1):
    if not m[j]==j:
      continue
    #m[j]==j
    ans.append(j)
    m=m[:j]+m[j+1:]
if not len(m)==0:
  print(-1)
else:
  for i in range(n):
    print(ans[n-1-i])
    

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

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

print(solve(), sep='\n')


Fixed code:
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [0 for i in range(N)]

  for i in range(N - 1, -1, -1):
    v = -1
    for j in range(i + 1):
      if B[j] == j + 1: v = j
    if v == -1: return [ -1 ]
    ans[i] = v + 1
    B.pop(v)
  return ans

print(*solve(), sep='\n')
Buggy code:
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())

Fixed code:
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())
Buggy code:
N = int(input())
b = list(map(int, input().split()))

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret = -1
        break

for it in ret[::-1]:
    print(it)

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

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret.append(-1)
        break

for it in ret[::-1]:
    print(it)
Buggy code:
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)

Fixed code:
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)
Buggy code:
n = int(input())
bn = list(map(int,input().split()))

ans = []

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


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

ans = []

while bn:
  lst = []
  for i in range(len(bn)):
    if i+1 == bn[i]:
      lst.append(i)
  if not lst:
    print(-1)
    exit(0)
  ans.append(bn.pop(lst[-1]))
[print(i) for i in ans[::-1]]
Buggy code:
N = int(input())
B = list(map(int, input().split(" ")))

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

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

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

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

if len(B) == 0:
    for l_i in l[::-1]:
        print(l_i)
else:
    print(-1)
Buggy code:
N=int(input())
l=list(map(int,input().split()))
s=[]
flag=1
while len(l)!=0 or flag!=0:
    flag=0
    for i in range(len(l),0,-1):
        if i==l[i-1]:
            p=l[i-1]
            s.append(p)
            l.pop(i-1)
            flag=1
            break
ans=reversed(s)
ans=list(ans)
for i in ans:
    print(i)

Fixed code:
N=int(input())
l=list(map(int,input().split()))
s=[]
flag=1
while len(l)!=0:
    flag=0
    for i in range(len(l),0,-1):
        if i==l[i-1]:
            p=l[i-1]
            s.append(p)
            l.pop(i-1)
            flag=1
            break
    if flag==0:
        ans=-1
        break

if flag==1:
    ans=reversed(s)
    ans=list(ans)
    for i in ans:
        print(i)
else:
    print(ans)
Buggy code:
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])

Fixed code:
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])
Buggy code:
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for anse in ans:
        print(anse)


Fixed code:
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i])
Buggy code:
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)

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

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

Fixed code:
n =  int(input())
l =  list(map(int,input().split()))
l1 = []
for i in range(n):
  for j in range(n-1-i,-1,-1):
    if l[j]==j+1:
      l1.append(l[j])
      del l[j]
      break
    else:
      continue
if len(l)==0:
  for j in l1[::-1]:
    print(j)
else:
  print(-1)
Buggy code:
N = int(input())
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

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

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



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

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


f(b, [])
print(-1)
Buggy code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			tmp = arr.pop(idx2-1)
            ans.append(tmp)
			break
		elif idx2 == 1:
			print(-1)
			exit()

for idx in range(0, N):
	tmp = ans.pop(-1)
    print(tmp)
  	print("\n")


Fixed code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			tmp = arr.pop(idx2-1)
			ans.append(tmp)
			break
		elif idx2 == 1:
			print(-1)
			exit()

for idx in range(0, N):
	tmp = ans.pop(-1)
	print(tmp)
Buggy code:
"""
A - Limited Insertion
"""
import numpy as np

N = input()
b_list = list(map(int, input().split()))
# N = 9
# b_list = [1, 1, 1, 2, 2, 1, 2, 3, 2]
# b_list = [1,1,1,2,2,1,2,3,2]
# b_list = [1,1,3,1,2]
# b_list = [2,2]


def make_idx(tmp_list):
    idx_list = np.arange(1, len(tmp_list)+1, 1)[::-1]
    return idx_list

b_list = b_list[::-1]
idx_list = make_idx(b_list)
rm_list = []

while len(b_list):
    for idx, b in zip(idx_list, b_list):
        if idx==b:
            b_list = b_list[::-1]
            b_list.remove(b)
            rm_list.append(b)
            b_list = b_list[::-1]
            break
        elif idx-b<0:
            print(-1)
#             exit()
    idx_list = make_idx(b_list)
    
print(rm_list[::-1])

Fixed code:
"""
A - Limited Insertion
"""
import numpy as np

N = input()
b_list = list(map(int, input().split()))
# N = 9
# b_list = [1, 1, 1, 2, 2, 1, 2, 3, 2]
# b_list = [1,1,1,2,2,1,2,3,2]
# b_list = [1,1,3,1,2]
# b_list = [2,2]


def make_idx(tmp_list):
    return np.arange(1, len(tmp_list)+1, 1)[::-1]

b_list = b_list[::-1]
idx_list = make_idx(b_list)
rm_list = []

while len(b_list):
    for idx, b in zip(idx_list, b_list):
        if idx==b:
            b_list = b_list[::-1]
            b_list.remove(b)
            rm_list.append(b)
            b_list = b_list[::-1]
            break
        elif idx-b<0:
            print(-1)
            exit()
    idx_list = make_idx(b_list)
    
for r in rm_list[::-1]:
    print(r)
Buggy code:
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)),reverse=True)
ans=[]
for itr in range(n):
  for j in s_b:
    if len(b)>=j:
      if b[j-1]==j:
        b=b[:j-1]+b[j:]
        ans.append(j)
        break
    if j==1:
      print(-1)
      exit()
for i in range(n):
  print(ans[i])


Fixed code:
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)),reverse=True)
if 1 not in s_b:
  print(-1)
  exit()
ans=[]
for itr in range(n):
  for j in s_b:
    if len(b)>=j:
      if b[j-1]==j:
        b.pop(j-1)
        ans.append(j)
        break
    if j==1:
      print(-1)
      exit()
ans.reverse()
for i in range(n):
  print(ans[i])
Buggy code:
from sys import exit
N = int(input())
B = list(map(int, input().split()))
ctr = 0
ans = []
for _ in range(N):
    for i, b in enumerate(B, 1):
        if i == b:
            ctr = i
    ans.append(ctr)
    if ctr == 0:
        print(-1)
        exit()
    B = B[:ctr-1] + B[ctr:]
print('\n'.join([str(s) for s in ans][::-1]))

Fixed code:
from sys import exit
N = int(input())
B = list(map(int, input().split()))
ctr = 0
ans = []
for _ in range(N):
    ctr = 0
    for i, b in enumerate(B, 1):
        if i == b:
            ctr = i
    ans.append(ctr)
    if ctr == 0:
        print(-1)
        exit()
    B = B[:ctr-1] + B[ctr:]
print('\n'.join([str(s) for s in ans][::-1]))
Buggy code:
import sys,math,collections,itertools
input = sys.stdin.readline
graph = []
cnt = 0

N=int(input())
if N%2 == 0:
    
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i+j == N+1:
                continue
            else:
                cnt+=1
                graph.append([i,j])
                
else:
    print(N*(N-1)//2)
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i + j == N:
                continue
            else:
                cnt+=1
                graph.append([i,j])
for gr in graph:
    print(*gr)
                


Fixed code:
import sys,math,collections,itertools
input = sys.stdin.readline
graph = []
cnt = 0

N=int(input())
if N%2 == 0:
    
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i+j == N+1:
                continue
            else:
                cnt+=1
                graph.append([i,j])
                
else:
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i + j == N:
                continue
            else:
                cnt+=1
                graph.append([i,j])
print(cnt)
for gr in graph:
    print(*gr)
Buggy code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    table = [
        [1 for _ in range(N)] for _ in range(N)
    ]
    for i in range(N//2):
        table[i][N-i-1] = table[N-i-1][i] = 0
    size = 0
    answer = []
    for i in range(N):
        for j in range(i+1, N):
            if table[i][j]:
                answer.append((i+1, j+1))
                size += 1
    print(size)
    for a in answer:
        print(*a)


if __name__ == '__main__':
    solve()


Fixed code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    table = [
        [1 for _ in range(N)] for _ in range(N)
    ]
    if N%2 == 0:
        for i in range(N//2):
            table[i][N-i-1] = table[N-i-1][i] = 0
    else:
        for i in range(N//2):
            table[i][N-i-2] = table[N-i-2][i] = 0
    size = 0
    answer = []
    for i in range(N):
        for j in range(i+1, N):
            if table[i][j]:
                answer.append((i+1, j+1))
                size += 1
    print(size)
    for a in answer:
        print(*a)


if __name__ == '__main__':
    solve()