Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
sl = [[0]*(W) for _ in range(H)]
sr = [[0]*(W) for _ in range(H)]
su = [[0]*(W) for _ in range(H)]
sd = [[0]*(W) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j]=='.':
            if i==0:
                sl[i][j] = 1
            else:
                sl[i][j] = sl[i-1][j]+1
            if j==0:
                su[i][j]=1
            else:
                su[i][j] = su[i][j-1]+1
for i in list(range(H))[::-1]:
    for j in list(range(W))[::-1]:
        if s[i][j]=='.':
            if i==H-1:
                sr[i][j] = 1
            else:
                sr[i][j] = sr[i+1][j]+1
            if j==W-1:
                sd[i][j]=1
            else:
                sd[i][j] = sd[i][j+1]+1
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j]=='.':
            ans = max(ans, sl[i][j]+sr[i][j]+su[i][j]+sd[i][j]-3)
print(ans)

Fixed submission:
H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
sl = [[0]*(W) for _ in range(H)]
sr = [[0]*(W) for _ in range(H)]
su = [[0]*(W) for _ in range(H)]
sd = [[0]*(W) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j]=='.':
            if i==0:
                sl[i][j] = 1
            else:
                sl[i][j] = sl[i-1][j]+1
            if j==0:
                su[i][j]=1
            else:
                su[i][j] = su[i][j-1]+1
for i in list(range(H))[::-1]:
    for j in list(range(W))[::-1]:
        if s[i][j]=='.':
            if i==H-1:
                sr[i][j] = 1
            else:
                sr[i][j] = sr[i+1][j]+1
            if j==W-1:
                sd[i][j]=1
            else:
                sd[i][j] = sd[i][j+1]+1
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j]=='.':
            ans = max(ans, sl[i][j]+sr[i][j]+su[i][j]+sd[i][j]-3)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

edges = [[] for _ in range(n)]
for u, v, w in uvw:
    u-=1
    v-=1
    edges[u].append([v, w%2])
    edges[v].append([u, w%2])

res = [[] for _ in range(n)]
def dfs(v, p, c):
    res[v] = c
    for e in edges[v]:
        if e[0] == p: continue
        if e[1]%2==1: dfs(e[0], v, 1-c%2)
        else: dfs(e[0], v, c)

dfs(0, -1, 1)
print('\n'.join(list(map(str, res))))

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

edges = [[] for _ in range(n)]
for u, v, w in uvw:
    u-=1
    v-=1
    edges[u].append([v, w%2])
    edges[v].append([u, w%2])

res = [[] for _ in range(n)]
def dfs(v, p, c):
    res[v] = c
    for e in edges[v]:
        if e[0] == p: continue
        if e[1]%2==1: dfs(e[0], v, 1-c%2)
        else: dfs(e[0], v, c)

dfs(0, -1, 1)
print('\n'.join(list(map(str, res))))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
n = int(input())
a = list(map(int, input().split()))

mx = 0
for i in range(n):
    popped = a.pop(i)
    g = a[0]
    for aa in a[1:]:
        g = fractions.gcd(g, aa)
    a.insert(i, popped)
    mx = max(mx, g)
print(mx)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))

mx = 0
gd_pos = [] # 0からiまでのgcd
gd_pos.append(a[0])
for i in range(1, n):
    gd_pos.append(fractions.gcd(gd_pos[i-1], a[i]))
gd_neg = [] # 末尾からiまでのgcd
gd_neg.append(a[-1])
a_rev = a[::-1]
for i in range(1, n):
    gd_neg.append(fractions.gcd(gd_neg[i-1], a_rev[i]))

def popped_g(i):
    if i == 0: return gd_neg[n-2]
    elif i == n-1: return gd_pos[n-2]
    else:
        return fractions.gcd(gd_pos[i-1], gd_neg[n-i-2])

ans = [popped_g(i) for i in range(n)]
print(max(ans))

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))

mx = 0
for i in range(n):
    popped = a.pop(i)
    g = a[0]
    for aa in a[1:]:
        g = math.gcd(g, aa)
    a.insert(i, popped)
    mx = max(mx, g)
print(mx)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))

mx = 0
gd_pos = [] # 0からiまでのgcd
gd_pos.append(a[0])
for i in range(1, n):
    gd_pos.append(fractions.gcd(gd_pos[i-1], a[i]))
gd_neg = [] # 末尾からiまでのgcd
gd_neg.append(a[-1])
a_rev = a[::-1]
for i in range(1, n):
    gd_neg.append(fractions.gcd(gd_neg[i-1], a_rev[i]))

def popped_g(i):
    if i == 0: return gd_neg[n-2]
    elif i == n-1: return gd_pos[n-2]
    else:
        return fractions.gcd(gd_pos[i-1], gd_neg[n-i-2])

ans = [popped_g(i) for i in range(n)]
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

def cont(s):
    ret = []
    if s[0] == '0':
        ret.append(0)
    tgt = s[0]
    i = 0
    count = 0
    while i < len(s):
        if s[i] == tgt:
            count += 1
        else:
            ret.append(count)
            count = 1
            if tgt == '0': tgt = '1'
            else: tgt = '0'
        if i == len(s)-1:
            ret.append(count)
        i += 1
    return ret        
cont_s = cont(s)
if len(cont_s) <= 2*k+1:
    print(sum(cont_s))
else:
    acum = [sum(cont_s[i:i+2*k+1]) for i in range(0, n+2*k+1, 2)]
    print(max(acum))

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

i = 0
a = []
while i < n:
    l = 1
    while i+1 < n and s[i]==s[i+1]:
        l+=1
        i+=1
    a.append(l)
    i+=1

if s[0] == 0:
    a = [0] + a
if s[-1] == 0:
    a = a + [0]
n = len(a)

acum = [0]*(n+1)
for i in range(n):
    acum[i+1] = acum[i]+a[i]

ans = 0
for i in range(0, n, 2):
    end = min(i+2*k+1, n)
    ans = max(ans, acum[end] - acum[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

def cont(s):
    ret = []
    if s[0] == '0':
        ret.append(0)
    tgt = s[0]
    i = 0
    count = 0
    while i < len(s):
        if s[i] == tgt:
            count += 1
        else:
            ret.append(count)
            count = 1
            if tgt == '0': tgt = '1'
            else: tgt = '0'
        if i == len(s)-1:
            ret.append(count)
        i += 1
    return ret        
cont_s = cont(s)
if len(cont_s) <= 2*k+1:
    print(sum(cont_s))
else:
    acum = [sum(cont_s[i:i+2*k+1]) for i in range(0, n+2*k+1, 2)]
    print(max(acum))

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

i = 0
a = []
while i < n:
    l = 1
    while i+1 < n and s[i]==s[i+1]:
        l+=1
        i+=1
    a.append(l)
    i+=1

if s[0] == 0:
    a = [0] + a
if s[-1] == 0:
    a = a + [0]
n = len(a)

acum = [0]*(n+1)
for i in range(n):
    acum[i+1] = acum[i]+a[i]

ans = 0
for i in range(0, n, 2):
    end = min(i+2*k+1, n)
    ans = max(ans, acum[end] - acum[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
from collections import Counter
n, k = map(int, input().split())

dset = [[] for i in range(n)]
for i in range(n):
    t, d = map(int, input().split())
    dset[t-1].append(d)

for dd in dset:
    if dd: dd.sort(reverse=True)
    else: dd.append(-float('inf'))

dset.sort(key= lambda x: -x[0])

cur = 0
hq = []
# k種類の先頭を除いて格納
for i in range(k):
    cur+=dset[i][0]
    for d in dset[i][1:]: heapq.heappush(hq, -d)

# 残りの種類のすべてを格納
for dd in dset[k:]:
    for d in dd:
        heapq.heappush(hq, -d)

ans = cur + k*k
for i in range(k-1, -1, -1):
    v = dset[i][0] # 削除候補
    w = -heapq.heappop(hq)
    if v < w:
        cur += w - v
    else:
        heapq.heappush(hq, -w)
    ans = max(ans, cur + i*i)
print(ans)

Fixed submission:
import heapq
from collections import Counter
inf = 10**10
n, k = map(int, input().split())

dset = [[] for i in range(n)]
for i in range(n):
    t, d = map(int, input().split())
    dset[t-1].append(d)

for dd in dset:
    if dd: dd.sort(reverse=True)
    else: dd.append(-inf)

dset.sort(key= lambda x: -x[0])

cur = 0
hq = []
# k種類の先頭を除いて格納
for i in range(k):
    cur+=dset[i][0]
    for d in dset[i][1:]: heapq.heappush(hq, -d)

# 残りの種類のすべてを格納
for dd in dset[k:]:
    for d in dd:
        heapq.heappush(hq, -d)

ans = cur + k*k
for i in range(k-1, -1, -1):
    v = dset[i][0] # 削除候補
    if hq:
        w = -heapq.heappop(hq)
    else:
        break
    if v < w:
        cur += w - v
        # heapq.heappush(hq, -v)
    else:
        heapq.heappush(hq, -w)
    ans = max(ans, cur + i*i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**9] * (n+k+10)
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if 0<=i+j<n: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))
print(dp[n-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**9] * (n+k+10)
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if 0<=i+j<n: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
Wl = []; Vl = []
for i in range(N):
    w, v = map(int, input().split())
    Wl.append(w); Vl.append(v)
# dp[i番目までの品物を使用][wを超えない]
dp = [[0]*(W+10) for _ in range(N+10)]

for i in range(N):
    w, v = Wl[i], Vl[i]
    for j in range(W+1):
        if j+w < W+1: dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j]+v)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(max(dp[N]))

Fixed submission:
N, W = map(int, input().split())
Wl = []; Vl = []
for i in range(N):
    w, v = map(int, input().split())
    Wl.append(w); Vl.append(v)
# dp[i番目までの品物を使用][wを超えない]
dp = [[0]*(W+10) for _ in range(N+10)]

for i in range(N):
    w, v = Wl[i], Vl[i]
    for j in range(W+1):
        if j+w < W+1: dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j]+v)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(max(dp[N]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

hassame = False
for i, s_ in enumerate(s):
    if hassame or s_ == t[0]: dp[i+1][1]=1; hassame=True
hassame = False
for i, t_ in enumerate(t):
    if hassame or t_ == s[0]: dp[1][i+1]=1; hassame=True

lcs = 0
for i, s_ in enumerate(s):
    if i==0: continue
    for j, t_ in enumerate(t):
        if j==0: continue
        if s_!=t_:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
        else:
            dp[i+1][j+1] = dp[i][j]+1
        lcs = max(lcs, dp[i+1][j+1])

ans = ''
i, j = len(s), len(t)
while 0<i and 0<j:
        if s[i-1] == t[j-1]: ans+=s[i-1]; i-=1; j-=1
        else:
            if dp[i-1][j] > dp[i][j-1]: i-=1
            else: j-=1
print(ans[::-1])


for i in range(len(s)):
    dp+=s[i]

Fixed submission:
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

hassame = False
for i, s_ in enumerate(s):
    if hassame or s_ == t[0]: dp[i+1][1]=1; hassame=True
hassame = False
for i, t_ in enumerate(t):
    if hassame or t_ == s[0]: dp[1][i+1]=1; hassame=True

lcs = 0
for i, s_ in enumerate(s):
    if i==0: continue
    for j, t_ in enumerate(t):
        if j==0: continue
        if s_!=t_:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
        else:
            dp[i+1][j+1] = dp[i][j]+1
        lcs = max(lcs, dp[i+1][j+1])

ans = ''
i, j = len(s), len(t)
while 0<i and 0<j:
        if s[i-1] == t[j-1]: ans+=s[i-1]; i-=1; j-=1
        else:
            if dp[i-1][j] > dp[i][j-1]: i-=1
            else: j-=1
print(ans[::-1])


for i in range(len(s)):
    dp+=s[i]
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
dp = [-1]*(n+1)
path = [[] for i in range(n)]
X = []; Y = []
for i in range(m):
    x, y = map(int, input().split())
    X.append(x-1); Y.append(y-1)
    path[x-1].append(y-1)

def dfs(i):
    if dp[i]>0: return dp[i]
    res = 0
    if path[i]:
        for k in path[i]:
            res = max(res, dfs(k)+1)
    dp[i] = res
    return res

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
dp = [-1]*(n+1)
path = [[] for i in range(n)]
X = []; Y = []
for i in range(m):
    x, y = map(int, input().split())
    X.append(x-1); Y.append(y-1)
    path[x-1].append(y-1)

def dfs(i):
    if dp[i]>0: return dp[i]
    res = 0
    for k in path[i]:
        res = max(res, dfs(k)+1)
    dp[i] = res
    return res

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
dp = [-1]*n
path = [[] for i in range(n)]
X = []; Y = []
for i in range(m):
    x, y = map(int, input().split())
    X.append(x-1); Y.append(y-1)
    path[x-1].append(y-1)

def dfs(i):
    if dp[i]>0: return dp[i]
    res = 0
    for k in path[i]:
        res = max(res, dfs(k)+1)
    dp[i] = res
    return res

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
dp = [-1]*(n+1)
path = [[] for i in range(n)]
X = []; Y = []
for i in range(m):
    x, y = map(int, input().split())
    X.append(x-1); Y.append(y-1)
    path[x-1].append(y-1)

def dfs(i):
    if dp[i]>0: return dp[i]
    res = 0
    for k in path[i]:
        res = max(res, dfs(k)+1)
    dp[i] = res
    return res

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))
print(ans)
Buggy python submission (verdict: Runtime Error):
from math  import gcd
n, m = map(int, input().split())
s = input()
t = input()

ans = n*m//gcd(n, m)

if n==1:
    if t == s*m:
        print(m)
    else:
        print(-1)
    exit(0)
elif m == 1:
    if s == t**n:
        print(n)
    else:
        print(-1)
    exit(0)

"""
最小公倍数の長さで収まらない場合は、何をやってもダメ
"""
dp = [0] * ans
for i in range(n):
    dp[i*ans//n] = s[i]

for i in range(m):
    if dp[i*ans//m] == 0: 
        dp[i*ans//m] = t[i]
    else:
        if dp[i*ans//m] != t[i]:
            print(-1)
            exit(0)
print(ans)

Fixed submission:
from math  import gcd
n, m = map(int, input().split())
s = input()
t = input()

g = gcd(n, m)
ans = n*m//g

"""
最小公倍数の長さで収まらない場合は、何をやってもダメ
"""
for i in range(g):
    if not s[i*n//g] == t[i*m//g]:
        print(-1)
        exit(0)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math  import gcd
n, m = map(int, input().split())
s = input()
t = input()

ans = n*m//gcd(n, m)

"""
最小公倍数の長さで収まらない場合は、何をやってもダメ
"""
dp = [0] * ans
for i in range(n):
    dp[i*ans//n] = s[i]

for i in range(m):
    if dp[i*ans//m] == 0: 
        dp[i*ans//m] = t[i]
    else:
        if dp[i*ans//m] != t[i]:
            print(-1)
            exit(0)
print(ans)

Fixed submission:
from math  import gcd
n, m = map(int, input().split())
s = input()
t = input()

g = gcd(n, m)
ans = n*m//g

"""
最小公倍数の長さで収まらない場合は、何をやってもダメ
"""
for i in range(g):
    if not s[i*n//g] == t[i*m//g]:
        print(-1)
        exit(0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

st = m//n

for i in range(st, 0, -1):
    mod = m - n*i
    if mod % i == 0:
        print(i)
        break

Fixed submission:
n, m = map(int, input().split())

st = m//n

for i in range(st, 0, -1):
    mod = m - n*i
    if mod % i == 0:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
pritn((a-1)*(b-1))

Fixed submission:
a, b = map(int, input().split())
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
s = list(map(int, list(input())))
k = int(input())

for i in range(len(s)):
    if s[i] == 1:
        continue
    else:
        print(s[i])
        f = False
        break
if f:
    print(1)

Fixed submission:
s = list(map(int, list(input())))
k = int(input())

f = True
for i in range(k):
    if s[i] == 1:
        continue
    else:
        print(s[i])
        f = False
        break
if f:
    print(1)

Buggy python submission (verdict: Runtime Error):
s = list(map(int, list(input())))
k = int(input())

for i in range(k):
    if s[i] == 1:
        continue
    else:
        print(s[i])
        f = False
        break
if f:
    print(1)


Fixed submission:
s = list(map(int, list(input())))
k = int(input())

f = True
for i in range(k):
    if s[i] == 1:
        continue
    else:
        print(s[i])
        f = False
        break
if f:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())
A = [[0]*(n) for i in range(n)]
C = [[0]*(n+1) for i in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    A[r-1][l-1] += 1

for i in range(n):
    a = A[i]
    c = C[i]
    for j in range(n):
        c[j+1] = c[j] + a[j]

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p-1, q):
        ans+=C[i][q] - C[i][p-1]
    print(ans)


Fixed submission:
n, m, Q = map(int, input().split())
A = [[0]*(n) for i in range(n)]
C = [[0]*(n+1) for i in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    A[r-1][l-1] += 1

for i in range(n):
    a = A[i]
    c = C[i]
    for j in range(n):
        c[j+1] = c[j] + a[j]

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p-1, q):
        ans+=C[i][q] - C[i][p-1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

def dfs(s=[], score=0):
    ans = float('inf')
    if len(s)==d:
        if score >= g:
            return sum(s)
        else:
            return float('inf')
    else:
        p, c = pc[len(s)]
        for i in range(p+1):
            a = 100*(len(s)+1)*i
            if i==p:
                a+=c
            ans = min(ans, dfs(s+[i], score+a))
    return ans

print(dfs([]))


Fixed submission:
from itertools import product
from math import ceil
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = 10**9
for bit in product([0, 1], repeat=d):
    score = 0
    probs = 0
    for i, b in enumerate(bit):
        p, c = pc[i]
        if b==1:
            probs+=p
            score+=100*(i+1)*p
            score+=c
    if score >= g:
        ans = min(ans, probs)
    else:
        # greedyに足す
        for i, b in list(enumerate(bit))[::-1]:
            p, c = pc[i]
            if b==1:
                continue
            if score+100*(i+1)*p >= g:
                a = ceil((g-score)/(100*(i+1)))
                probs += a
                score += (100*(i+1))*a
                if a == p: score += c
                break
            else:
                probs += p
                score += (100*(i+1))*p+c
                if score >= g: break
        if score >= g:
            ans = min(ans, probs)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input().split())
if n % 2 == 0:
  print(n)
else:
  print(n*2)

Fixed submission:
n = int(input())
if n % 2 == 0:
  print(n)
else:
  print(n*2)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

ans = [a+b, a-b, a*b]
print(max[ans])

Fixed submission:
a,b = map(int, input().split())
ans = [a+b, a-b, a*b]
print(max(ans))
Buggy python submission (verdict: Runtime Error):
s = list(map(int, list(input())))
ans = n
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans = min(ans, max(i+1, len(s)-i-1))
print(ans)


Fixed submission:
s = list(map(int, list(input())))
ans = len(s)
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans = min(ans, max(i+1, len(s)-i-1))
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = list(input())
c = Counter(n)
if max(list(c.values))>=3:
  print('Yes')
else:
  print('No')

Fixed submission:
n = list(input())
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [2, 1]
i = 0
while i < n:
  l.append(l[-1] + l[-2])
print(l[n-2])

Fixed submission:
n = int(input())
l = [2, 1]
i = 0
while i < n:
  l.append(l[-1] + l[-2])
  i+=1
print(l[n])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(n)]
xset = list(set([i[0] for i in xy]))
yset = list(set([i[1] for i in xy]))
xset.sort()
yset.sort()

W = len(xset)
H = len(yset)
ans = float('inf')
for ix in range(W):
    for jx in range(ix, W):
        for iy in range(H):
            for jy in range(iy, H):
                xmin = min(xset[ix], xset[jx])
                xmax = max(xset[ix], xset[jx])
                ymin = min(yset[iy], yset[jy])
                ymax = max(yset[iy], yset[jy])
                cnt = 0
                for x, y in xy:
                    if xmin<=x<=xmax and ymin<=y<=ymax:
                        cnt+=1
                if cnt>=k:
                    ans = min(ans, (xmax-xmin)*(ymax-ymin))
print(ans)


Fixed submission:
n, k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(n)]
xset = list(set([i[0] for i in xy]))
yset = list(set([i[1] for i in xy]))
xset.sort()
yset.sort()

W = len(xset)
H = len(yset)
ans = float('inf')
for ix in range(W):
    for jx in range(ix, W):
        for iy in range(H):
            for jy in range(iy, H):
                xmin = min(xset[ix], xset[jx])
                xmax = max(xset[ix], xset[jx])
                ymin = min(yset[iy], yset[jy])
                ymax = max(yset[iy], yset[jy])
                cnt = 0
                for x, y in xy:
                    if xmin<=x<=xmax and ymin<=y<=ymax:
                        cnt+=1
                if cnt>=k:
                    ans = min(ans, (xmax-xmin)*(ymax-ymin))
print(ans)