Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
i = 1
ans = 0
while i =< n-2:
  if (p[i]-p[i-1])*(p[i]-p[i+1]) < 0:
    ans += 1
  if (p[i]-p[i-1])*(p[i]-p[i+1]) = 0:
    if p[i] < p[i-1] or p[i] < p[i+1]:
      ans += 1
  i += 1
print("%d",ans)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
i = 1
ans = 0
while i <= n-2:
  if (p[i]-p[i-1])*(p[i]-p[i+1]) < 0:
    ans += 1
  if (p[i]-p[i-1])*(p[i]-p[i+1]) == 0:
    if p[i] < p[i-1] or p[i] < p[i+1]:
      ans += 1
  i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 0
if n % 2 = 1:
  print(ans)
else:
  ans = d[(n - 1)/2 + 1] - d[(n - 1)/2]
  print(ans)


Fixed submission:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 0
if n % 2 == 1:
  print(ans)
else:
  ans = d[(n // 2)] - d[(n // 2 - 1)]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int,input().split()))
k = max(d)
i = 0
j = 0
ans = 0
b = 0
s = 0
while i <= k:
  while j <= n-1:
    if d[j] < i:
      s += 1
    if d[j] >= i:
      b += 1
    j += 1
  if b == s:
    ans += 1
  b = 0
  s = 0
  j = 0
  i += 1
print(ans)
  

Fixed submission:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 0
if n % 2 == 1:
  print(ans)
else:
  ans = d[(n // 2)] - d[(n // 2 - 1)]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int,input().split()))
k = max(d)
i = 0
j = 0
ans = 0
b = 0
s = 0
while i <= k:
  while j <= n-1:
    if d[j] <= i:
      b += 1
    if d[j] > i:
      s += 1
  if b == s:
    ans += 1
  b = 0
  s = 0
  i += 1
print(ans)

Fixed submission:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 0
if n % 2 == 1:
  print(ans)
else:
  ans = d[(n // 2)] - d[(n // 2 - 1)]
  print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
k = max(d)
i,j,ans,b,s = 0
while i <= k:
  while j <= n-1:
    if d[j] <= i:
      b += 1
    if d[j] > i:
      s += 1
  if b == s:
    ans += 1
  i += 1
print(ans)
  

Fixed submission:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 0
if n % 2 == 1:
  print(ans)
else:
  ans = d[(n // 2)] - d[(n // 2 - 1)]
  print(ans)
Buggy python submission (verdict: Runtime Error):
a = list(map(float,input().split(),9))
answer = float(a[0] * a[1])
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)

Fixed submission:
a = list(map(float,input().split()))
answer = float(a[0] * a[1]/2)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
a = list(map(float,input().split(),9))
answer = float(a[0] * a[1],9)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)

Fixed submission:
a = list(map(float,input().split()))
answer = float(a[0] * a[1]/2)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
time = list(map(int, input(),split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)

Fixed submission:
time = list(map(int, input().split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)

Buggy python submission (verdict: Runtime Error):
time = list(map(int, input(),split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)
 

Fixed submission:
time = list(map(int, input().split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)

Buggy python submission (verdict: Runtime Error):
time = list(map(int, input(),sprit()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)



Fixed submission:
time = list(map(int, input().split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)
Buggy python submission (verdict: Runtime Error):
s = input()
set = [0, 1]
diff = 0

for i in range(len(s)):
    set.reverse()
    print(s)
    if set[1] == int(s[i]):
        diff += 1

print(min([diff, len(s)-diff]))


Fixed submission:
s = input()
set = [0, 1]
diff = 0

for i in range(len(s)):
    set.reverse()
    if set[1] == int(s[i]):
        diff += 1

print(min([diff, len(s)-diff]))
Buggy python submission (verdict: Runtime Error):
wd = {
  "SUN":7
  "MON":6
  "TUE":5
  "WED":4
  "THU":3
  "FRI":2
  "SAT":1
  }
line = input()
 
print(wd[line])

Fixed submission:
wd = {
  "SUN":7,
  "MON":6,
  "TUE":5,
  "WED":4,
  "THU":3,
  "FRI":2,
  "SAT":1
  }
line = input()
 
print(wd[line])
Buggy python submission (verdict: Runtime Error):
count = int(input())

str_data = {}

for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0

print(sum(str_data.values())

Fixed submission:
a,b = map(int, input().split())

print(max(a*b,a-b,a+b))

Buggy python submission (verdict: Runtime Error):
a,b = input().split(' ')

print(max(a*b,a-b,a+b))

Fixed submission:
a,b = map(int, input().split())

print(max(a*b,a-b,a+b))
Buggy python submission (verdict: Runtime Error):
count = int(input())

for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0

print(sum(str_data.values()))

Fixed submission:
count = int(input())
 
str_data = dict()
result = 0
for i in range(count):
    judge_str = ''.join(sorted(input()))
    if judge_str in str_data:
        str_data[judge_str] += 1
        result += str_data[judge_str]
    else:
        str_data[judge_str] = 0
    
print(result)

Buggy python submission (verdict: Runtime Error):
count = int(input())
 
str_data = {}
 
for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0
 
print(sum(str_data.values())

Fixed submission:
count = int(input())
 
str_data = dict()
result = 0
for i in range(count):
    judge_str = ''.join(sorted(input()))
    if judge_str in str_data:
        str_data[judge_str] += 1
        result += str_data[judge_str]
    else:
        str_data[judge_str] = 0
    
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
count = int(input())

str_data = list()
result = 0
for i in range(count):
  judge_str = sorted(input())
  for data in str_data:
    if judge_str == data:
      result += 1
    
  str_data.append(judge_str)
print(result)

Fixed submission:
count = int(input())
 
str_data = dict()
result = 0
for i in range(count):
    judge_str = ''.join(sorted(input()))
    if judge_str in str_data:
        str_data[judge_str] += 1
        result += str_data[judge_str]
    else:
        str_data[judge_str] = 0
    
print(result)
Buggy python submission (verdict: Runtime Error):
s = input()
if s == "SUN":
    print(7)
elif s == "SAT":
    print(1)
elif s == "FRI":
    print(2)
elif s == "THU":
    print(3)
elif s == "WED":
    print(4)
elif s == "TUE":
    print(5)
elif s == "MON":
    print(6)
~               

Fixed submission:
s = input()
if s == "SUN":
    print(7)
elif s == "SAT":
    print(1)
elif s == "FRI":
    print(2)
elif s == "THU":
    print(3)
elif s == "WED":
    print(4)
elif s == "TUE":
    print(5)
elif s == "MON":
    print(6)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N,M=list(map(int, input().strip().split()))
A=list(map(int, input().strip().split()))
AS=[0]*N
AS[0]=A[0]%M
modG=defaultdict(list)
ct=0
for i in range(1,N):
    AS[i]=(AS[i-1]+A[i])%M
for i,a in enumerate(AS):
    if a==0:ct+=1
    modG[a].append(i)
for i in range(N):
    for x in modG[AS[i]]:
        if x+1>i:break
        ct+=1
print(ct)

Fixed submission:
from collections import defaultdict
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return None
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
N,M=list(map(int, input().strip().split()))
A=list(map(int, input().strip().split()))
AS=[0]*N
AS[0]=A[0]%M
modG=defaultdict(list)
ct=0
for i in range(1,N):
    AS[i]=(AS[i-1]+A[i])%M
for i,a in enumerate(AS):
    if a==0:ct+=1
    modG[a].append(i)
for i in range(N):
    ans=binsearch_int(lambda x: modG[AS[i]][x]+1<=i,0,len(modG[AS[i]])-1)
    if ans is None:
        continue
    ct+=(ans+1)
print(ct)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import heapq
n,m,s,t=list(map(int, input().strip().split()))
links_y=defaultdict(list)
links_s=defaultdict(list)
for i in range(m):
    u,v,a,b=list(map(int, input().strip().split()))
    links_y[u-1].append((v-1,a))
    links_y[v-1].append((u-1,a))
    links_s[u-1].append((v-1,b))
    links_s[v-1].append((u-1,b))

def dijkstra(frm, links):
    dist=[float('inf')]*n
    dist[frm]=0
    Q=[(0,frm)]
    heapq.heapify(Q)
    while Q:
        d,u = heapq.heappop(Q)
        for v,dd in links[u]:
            if dist[v]> d+dd:
                dist[v]=dd+d
                heapq.heappush(Q,(dist[v],v))
    return dist
yen_cost=dijkstra(s-1,links_y)
snk_cost=dijkstra(t-1,links_s)
sumyensnk=[i+j for i,j in zip(yen_cost,snk_cost)]
min_snk=[float('inf')]*n
tmp=float('inf')
for i in range(n)[::-1]:
    min_snk[i] = min(sumyensnk[i],tmp)
    tmp = min_snk[i]
money=10**15
for sumsnk in min_snk:
    print(money-sumsnk)

Fixed submission:
import heapq
n,m,s,t=list(map(int, input().strip().split()))
links_y=[[]for i in range(n) ]
links_s=[[]for i in range(n) ]
INF=float('inf')
for i in range(m):
    u,v,a,b=list(map(int, input().strip().split()))
    links_y[u-1].append((v-1,a))
    links_y[v-1].append((u-1,a))
    links_s[u-1].append((v-1,b))
    links_s[v-1].append((u-1,b))

def dijkstra(frm, links):
    dist=[INF]*n
    dist[frm]=0
    Q=[(0,frm)]
    heapq.heapify(Q)
    while Q:
        d,u = heapq.heappop(Q)
        for v,dd in links[u]:
            if dist[v]> d+dd:
                dist[v]=dd+d
                heapq.heappush(Q,(dist[v],v))
    return dist
yen_cost=dijkstra(s-1,links_y)
snk_cost=dijkstra(t-1,links_s)
sumyensnk=[i+j for i,j in zip(yen_cost,snk_cost)]
min_snk=[INF]*n
tmp=INF
for i in range(n)[::-1]:
    min_snk[i] = min(sumyensnk[i],tmp)
    tmp = min_snk[i]
money=10**15
for sumsnk in min_snk:
    print(money-sumsnk)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input().strip())
A=list(map(int, input().strip().split()))
A_posi=[]
A_nega=[]
for i in range(N):
    A[i]=A[i]-(i+1)
    if A[i]<0:
        A_nega.append(A[i]*(-1))
    elif A[i]>0:
        A_posi.append(A[i])
sm=sum(abs(i) for i in A)

A_tgt=A_nega if len(A_nega)>len(A_posi) else A_posi
A_tgt=sorted(A_tgt)
b=0
max_diff=0
if len(A_tgt):
    while b<A_tgt[-1]:
        b+=1
        diff=0
        for i,a in enumerate(A_tgt):
            if a>=b:
                diff+=(len(A_tgt)-i)*b
                break
            else:
                diff+=2*a-b
        diff-=(N-len(A_tgt))*b
        if diff >max_diff:
            max_diff=diff
        else:
            break
print(sm-max_diff)

Fixed submission:
N=int(input().strip())
A=list(map(int, input().strip().split()))
A_posi=[]
A_nega=[]
for i in range(N):
    A[i]=A[i]-(i+1)
    if A[i]<0:
        A_nega.append(A[i]*(-1))
    elif A[i]>0:
        A_posi.append(A[i])
sm=sum(abs(i) for i in A)

A_tgt=A_nega if len(A_nega)>len(A_posi) else A_posi
A_tgt=sorted(A_tgt)

diff=0
old=0
mindiff=0
for i,a in enumerate(A_tgt):
    if old<a:
        diffdiff=(-i+(len(A_tgt)-i))*(a-old)
    else:
        continue
    if diffdiff<0:
        break
    old=a
    diff = diff+diffdiff
    total_diff=-diff+a*(N-len(A_tgt))
    if total_diff<mindiff:
        mindiff=total_diff
print(sm+mindiff)
Buggy python submission (verdict: Runtime Error):
N=int(input().strip())
A=list(map(int,input().split()))
nns=[2**i for i in range(31)]
def func(n,x):
    return n%nns[x]==0
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return None
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
sum(binsearch_int(lambda x: func(i,x),0,int(math.log2(i))+1) for i in A)

Fixed submission:
import math
N=int(input().strip())
A=list(map(int,input().split()))
nns=[2**i for i in range(31)]
def func(n,x):
    return n%nns[x]==0
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return None
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
print(sum(binsearch_int(lambda x: func(i,x),0,int(math.log2(i))+1) for i in A))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
xyz=[]
for i in range(N):
    xyz.append(list(map(int,input().split())))
coefs=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1]
       ,[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
ans=[]

for ix,iy,iz in coefs:
    xyz_ = [sum([ix*l[0],iy*l[1],iz*l[2]]) for l in xyz]
    dp=[[0]*(M+1) for i in range(N+1)]
    for i in range(N):
        dp[i+1][0] = dp[i][0]
        for j in range(1,M+1):
            dp[i+1][j] = max(dp[i][j-1]+xyz_[i],dp[i][j])
    ans.append(dp[N][M])
print(max(ans))

Fixed submission:
N,M=map(int,input().split())
xyz=[]
for i in range(N):
    xyz.append(list(map(int,input().split())))
coefs=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1]
       ,[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
ans=[]

for ix,iy,iz in coefs:
    xyz_ = [sum([ix*l[0],iy*l[1],iz*l[2]]) for l in xyz]
    ans.append(sum(sorted(xyz_,reverse=True)[:M]))
print(max(ans))
Buggy python submission (verdict: Runtime Error):
s=input().strip()
K=int(input())
st=set()
for i in range(len(s)-1):
    for k in range(i+1,min(len(s),i+K+1)):
        st.add(s[i:k])
print(sorted(st)[K-1])

Fixed submission:
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(min(len(ss),K)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(len(ss)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])

Fixed submission:
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(min(len(ss),K)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])
Buggy python submission (verdict: Runtime Error):
H,W = sorted(map(int,input().split()))
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "#":
            if not (j>0 and ss[i][j-1] == "#"or j<W-1 and ss[i][j+1] == "#" or i>0 and ss[i-1][j]=="#" or i< H-1 and ss[i+1][j]=="#"):
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])  

Fixed submission:
H,W = map(int,input().split())
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "#":
            if not (j>0 and ss[i][j-1] == "#"or j<W-1 and ss[i][j+1] == "#" or i>0 and ss[i-1][j]=="#" or i< H-1 and ss[i+1][j]=="#"):
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
for i in range(A,B+1):
    if i <A+K or i >B-K:
        print(i)

Fixed submission:
A,B,K=map(int,input().split())
b=min(A+K-1,B)
for i in range(A,b+1):
    print(i)
b2=max(b+1,B-K+1)
for i in range(b2,B+1):
    print(i)
Buggy python submission (verdict: Runtime Error):
N=int(input().strip())
primes=sorted(eratosthenes(int(1e5)))
p_set=set(primes)
primes2=[]
for p in primes:#MlogM
    if (p+1)//2 in p_set:
        primes2.append(p)
for i in range(N):#N
    l,r=map(int,input().split())
    li=binsearch_lb(primes2,l)#l以上のインデックス logM
    ri=binsearch_ub(primes2,r)#r以下のインデックス
    print(ri-li+1)

Fixed submission:
def eratosthenesAray(N):
    prime=[True]*(N+1)
    prime[0]=False
    prime[1]=False
    for i in range(2,N+1):
        if prime[i]:
            for j in range(i+i,N+1,i):
                prime[j]=False
    return prime

N=int(input().strip())
primes=eratosthenesAray(100000)
ruiseki=[0]*100001
for i in range(1,100001):
    ruiseki[i]=ruiseki[i-1]
    if primes[i] and primes[(i+1)//2]:
        ruiseki[i]+=1
for i in range(N):#N
    l,r=map(int,input().split())
    print(ruiseki[r]-ruiseki[l-1])
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
C=[]
A=[]
for i in range(10):
    C.append(list(map(int,input().split())))
for i in range(H):
    A.append(list(map(int,input().split())))
# WF
for i in range(10):
    for j in range(10):
        for k in range(10):
            C[i][j]=min(C[i][j], C[i][k]+C[k][j])
for i in range(10):
    cst[i]=djcstra(i,1,C)
print(sum(sum(C[i][1] for i in AA if i >= 0) for AA in A))

Fixed submission:
H,W=map(int,input().split())
C=[]
A=[]
for i in range(10):
    C.append(list(map(int,input().split())))
for i in range(H):
    A.append(list(map(int,input().split())))
# WF
for i in range(10):
    for j in range(10):
        for k in range(10):
            C[j][k]=min(C[j][k], C[j][i]+C[i][k])
print(sum(sum(C[i][1] for i in AA if i >= 0) for AA in A))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
xset=set([x[0] for x in P])
yset=set([x[1] for x in P])

minA=float('inf')
for l in xset:
    for r in xset:
        if r<=l:continue
        for d in yset:
            for u in yset:
                if u<=d:continue
                area=(r-l)*(u-d)
                if area>=minA:continue
                if len([p for p in P if l<=p[0]<=r and d<=p[1]<=u])==K:
                    area=(r-l)*(u-d)
                    minA=area
print(minA)

Fixed submission:
N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
P=sorted(P)
pi=list(enumerate(P))
minA=float("inf")
for il,xyl in pi[:N-1]:
    left=xyl[0]
    for ir,xyr in pi[il+1:]:
        right=xyr[0]
        insd=[xy_ for i,xy_ in pi if xyl[0]<=xy_[0]<=xyr[0]]
        insd=sorted(insd,key=lambda xx:xx[1])
        in_L=len(insd)
        if in_L<K:continue
        for jd in range(in_L-K+1):
            ju=jd+K-1
            down=insd[jd][1]
            upper=insd[ju][1]
            minA=min(minA,(upper-down)*(right-left))

print(minA)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
xset=set([x[0] for x in P])
yset=set([x[1] for x in P])

minA=float('inf')
for l in xset:
    for r in xset:
        if r<=l:continue
        for d in yset:
            for u in yset:
                if u<=d:continue
                if len([p for p in P if l<=p[0]<=r and d<=p[1]<=u])==K:
                    area=(r-l)*(u-d)
                    if area<minA:
                        minA=area
print(minA)

Fixed submission:
N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
P=sorted(P)
pi=list(enumerate(P))
minA=float("inf")
for il,xyl in pi[:N-1]:
    left=xyl[0]
    for ir,xyr in pi[il+1:]:
        right=xyr[0]
        insd=[xy_ for i,xy_ in pi if xyl[0]<=xy_[0]<=xyr[0]]
        insd=sorted(insd,key=lambda xx:xx[1])
        in_L=len(insd)
        if in_L<K:continue
        for jd in range(in_L-K+1):
            ju=jd+K-1
            down=insd[jd][1]
            upper=insd[ju][1]
            minA=min(minA,(upper-down)*(right-left))

print(minA)
Buggy python submission (verdict: Time Limit Exceeded):
N,Ma,Mb=list(map(int, input().strip().split()))
abc=[list(map(int, input().strip().split())) for i in range(N)]
maxW=N*10
dp=[[[float("inf")]*(maxW+1) for _ in range(maxW+1)]for __ in range(N+1)]
dp[0][0][0]=0
for i in range(N):
    a,b,c=abc[i]
    for ai  in range(maxW):
        for bi in range(maxW):
            if dp[i][ai][bi]==float("inf"):continue
            dp[i+1][ai][bi] = min(dp[i+1][ai][bi],dp[i][ai][bi])
            dp[i+1][ai+a][bi+b] = min(dp[i][ai][bi]+c,dp[i+1][ai+a][bi+b])
cost=float("inf")
Mad=Ma
Mbd=Mb
while Ma<=maxW and Mb <=maxW:
    cost=min(dp[-1][Ma][Mb],cost)
    Ma+=Mad
    Mb+=Mbd
print(-1 if cost==float("inf") else cost)

Fixed submission:
N,Ma,Mb=list(map(int, input().strip().split()))
abc=[list(map(int, input().strip().split())) for i in range(N)]
maxW=N*10
dp=[{} for __ in range(N+1)]
dp[0][(0,0)]=0
for i in range(N):
    a,b,c=abc[i]
    for k,v in dp[i].items():
        dp[i+1][k]=min(dp[i][k], dp[i+1][k]if k in dp[i+1] else float("inf"))
        dp[i+1][k[0]+a,k[1]+b]=min(dp[i][k]+c, dp[i+1][k[0]+a,k[1]+b] if (k[0]+a,k[1]+b)in dp[i+1] else float("inf"))

cost=float("inf")
Mad=Ma
Mbd=Mb
while Ma<=maxW and Mb <=maxW:
    if (Ma,Mb) in dp[-1]:
        cost=min(dp[-1][Ma,Mb],cost)
    Ma+=Mad
    Mb+=Mbd
print(-1 if cost==float("inf") else cost)