why my code is wrong?

alt textimport numpy as np
def return_pairs(target,pairs):
l=list(range(2,target+1))
length=len(l)
first=0
first_index=pairs//2
last=length
if pairs%2==0:
last_index=length-pairs//2
else:
last_index=(length-(pairs//2)-1)
lst=[]
while True:
if first_index>last_index:
break
ans=sum(l[first:first_index])+sum(l[last_index:last])
if ans==target:
lst+=l[first:first_index]+l[last_index:last]
first+=1
first_index+=1
last-=1
last_index-=1
elif ans>target:
last-=1
last_index-=1
else:
first+=1
first_index+=1
if lst:
mst=[x-1 for x in lst]
ans=[]
for x in range(0,length,pairs):
ans+=[np.prod(lst[x:x+pairs])*np.prod(mst[x:x+pairs])]
return max(ans)
else:
return -1

for _ in range(int(input())):
target,pairs=map(int,input().split())
if pairs==1:
print(target**2-target)
else:
print(return_pairs(target,pairs))

//