Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
 
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")
 
for i, j, l, m in product(range(n), repeat=4):
    cnt = 0
    for g in range(n):
        if p[i][0] <= p[g][0] <= p[j][0] and p[l][1] <= p[g][1] <= p[m][1]:
            cnt += 1
    if cnt >= k:
        ans = min(ans, (p[j][0] - p[i][0]) * (p[m][1] - p[l][1]))
print(ans)

Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import product
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1] - yl[k]
            ans = min(ans, y*x)
print(ans)

Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

for i, j, l, m in product(range(n), repeat=4):
    cnt = 0
    for g in range(n):
        if p[i][0] <= p[g][0] <= p[j][0] and p[l][1] <= p[g][1] <= p[m][1]:
            cnt += 1
    if cnt >= k:
        ans = min(ans, (p[j][0] - p[i][0]) * (p[m][1] - p[l][1]))
print(ans)


Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
# x or y で sortしてK個見る
# これだけだと同一xに対して複数の選択がある時に落ちる
# 群数列てきな考えがいる？
n, k = map(int, input().split())

point = []
for i in range(n):
    point.append(list(map(int, input().split())))
point.sort()

# Xのポイント
dic = {}
for i in set([j[0] for j in point]):
    dic[i] = []
for i in point:
    dic[i[0]].append(i[1])
for i in set([j[0] for j in point]):
    dic[i].sort()

ans_prob = []
for i in range(n - k + 1):
    xmin = point[i][0]
    xmax = point[i + k - 1][0]
    #
    if xmin == xmax:
        print(0)
        exit()
    else:
        mid_flag = 0
        _y = []
        for j in range(i, i+k):
            if point[j][0] != xmin and point[j][0] != xmax:
                mid_flag = 1
                _y.append(point[j][1])

        #xminとxmaxの間に要素が存在しない時
        if mid_flag == 0:
            ret = 4*10**18
            for j in dic[xmin]:
                for k in dic[xmax]:
                    ret = min(ret, abs(j - k))
            ans_prob.append(ret)
        else:
            ymax_other = max(_y)
            ymin_other = min(_y)
            #これがどこに入るか考えなければいけない
            #xminについて
            flag = 0
            #xminが入らない時
            if dic[xmin][0] > ymax_other:
                ymax_other = dic[xmin][0]
            elif dic[xmin][-1] < ymin_other:
                ymin_other = dic[xmin][-1]
            else:
                xmin_point_min = bisect.bisect_left(dic[xmin], ymin_other)
                xmin_point_max = bisect.bisect_left(dic[xmin], ymax_other)
                #途中で入れないとき  xminが[1,5]のときに[2,3]のとき
                if xmin_point_max == xmin_point_min:
                    flag = 1
                    xmin_left = dic[xmin][xmin_point_max - 1]
                    xmin_right = dic[xmin][xmin_point_max]
                    hozon = ymin_other
                    ymin_other = xmin_left
                    #xmin_rightが採用される時を追加で判定すればいい
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            #xmaxについて
            #xmaxが入らない時
            if dic[xmax][0] > ymax_other:
                ymax_other = dic[xmax][0]
            elif dic[xmax][-1] < ymin_other:
                ymin_other = dic[xmax][-1]
            else:
                xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                if xmax_point_max == xmax_point_min:
                    xmax_left = dic[xmax][xmax_point_max]
                    xmax_right = dic[xmax][xmax_point_max + 1]
                    if ymin_other - xmax_left < xmax_right - ymax_other:
                        ymin_other = xmax_left
                    else:
                        ymax_other = xmax_right
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

            if flag != 0:
                ymin_other = hozon
                ymax_other = xmin_right

                if dic[xmax][0] > ymax_other:
                    ymax_other = dic[xmax][0]
                elif dic[xmax][-1] < ymin_other:
                    ymin_other = dic[xmax][-1]
                else:
                    xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                    xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                    #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                    if xmax_point_max == xmax_point_min:
                        xmax_left = dic[xmax][xmax_point_max]
                        xmax_right = dic[xmax][xmax_point_max + 1]
                        if ymin_other - xmax_left < xmax_right - ymax_other:
                            ymin_other = xmax_left
                        else:
                            ymax_other = xmax_right
                    # 入る時つまりymin, ymaxに変化なし
                    else:
                        pass
                ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

ans_prob.sort()
print(ans_prob[0])


Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
# x or y で sortしてK個見る
# これだけだと同一xに対して複数の選択がある時に落ちる
# 群数列てきな考えがいる？
n, k = map(int, input().split())

point = []
for i in range(n):
    point.append(list(map(int, input().split())))
point.sort()

# Xのポイント
dic = {}
for i in set([j[0] for j in point]):
    dic[i] = []
for i in point:
    dic[i[0]].append(i[1])
for i in set([j[0] for j in point]):
    dic[i].sort()

ans_prob = []
for i in range(n - k + 1):
    xmin = point[i][0]
    xmax = point[i + k - 1][0]
    #
    if xmin == xmax:
        print(0)
        exit()
    else:
        mid_flag = 0
        _y = []
        for j in range(i, i+k):
            if point[j][0] != xmin and point[j][0] != xmax:
                mid_flag = 1
                _y.append(point[j][1])

        #xminとxmaxの間に要素が存在しない時
        if mid_flag == 0:
            ret = 4*10**18
            for j in dic[xmin]:
                for k in dic[xmax]:
                    ret = min(ret, abs(j - k))
            ans_prob.append(ret)
        else:
            ymax_other = max(_y)
            ymin_other = min(_y)
            #これがどこに入るか考えなければいけない
            #xminについて
            flag = 0
            #xminが入らない時
            if dic[xmin][0] > ymax_other:
                ymax_other = dic[xmin][0]
            elif dic[xmin][-1] < ymin_other:
                ymin_other = dic[xmin][-1]
            else:
                xmin_point_min = bisect.bisect_left(dic[xmin], ymin_other)
                xmin_point_max = bisect.bisect_left(dic[xmin], ymax_other)
                #途中で入れないとき  xminが[1,5]のときに[2,3]のとき
                if xmin_point_max == xmin_point_min:
                    flag = 1
                    xmin_left = dic[xmin][xmin_point_max - 1]
                    xmin_right = dic[xmin][xmin_point_max]
                    hozon = ymin_other
                    ymin_other = xmin_left
                    #xmin_rightが採用される時を追加で判定すればいい
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            #xmaxについて
            #xmaxが入らない時
            if dic[xmax][0] > ymax_other:
                ymax_other = dic[xmax][0]
            elif dic[xmax][-1] < ymin_other:
                ymin_other = dic[xmax][-1]
            else:
                xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                if xmax_point_max == xmax_point_min:
                    xmax_left = dic[xmin][xmin_point_max]
                    xmax_right = dic[xmin][xmin_point_max + 1]
                    if ymin_other - xmax_left < xmax_right - ymax_other:
                        ymin_other = xmax_left
                    else:
                        ymax_other = xmax_right
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

            if flag != 0:
                ymin_other = hozon
                ymax_other = xmin_right

                if dic[xmax][0] > ymax_other:
                    ymax_other = dic[xmax][0]
                elif dic[xmax][-1] < ymin_other:
                    ymin_other = dic[xmax][-1]
                else:
                    xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                    xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                    #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                    if xmax_point_max == xmax_point_min:
                        xmax_left = dic[xmin][xmin_point_max]
                        xmax_right = dic[xmin][xmin_point_max + 1]
                        if ymin_other - xmax_left < xmax_right - ymax_other:
                            ymin_other = xmax_left
                        else:
                            ymax_other = xmax_right
                    # 入る時つまりymin, ymaxに変化なし
                    else:
                        pass
                ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

ans_prob.sort()
print(ans_prob[0])


Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
# x or y で sortしてK個見る
# これだけだと同一xに対して複数の選択がある時に落ちる
# 群数列てきな考えがいる？
n, k = map(int, input().split())

point = []
for i in range(n):
    point.append(list(map(int, input().split())))
point.sort()

# Xのポイント
dic = {}
for i in set([j[0] for j in point]):
    dic[i] = []
for i in point:
    dic[i[0]].append(i[1])
for i in set([j[0] for j in point]):
    dic[i].sort()

ans_prob = []
for i in range(n - k + 1):
    xmin = point[i][0]
    xmax = point[i + k - 1][0]
    #
    if xmin == xmax:
        print(0)
        exit()
    else:
        mid_flag = 0
        _y = []
        for j in range(i, i+k):
            if point[j][0] != xmin and point[j][0] != xmax:
                mid_flag = 1
                _y.append(point[j][1])

        #xminとxmaxの間に要素が存在しない時
        if mid_flag == 0:
            ret = 4*10**18
            for j in dic[xmin]:
                for k in dic[xmax]:
                    ret = min(ret, abs(j - k))
            ans_prob.append(ret)
        else:
            ymax_other = max(_y)
            ymin_other = min(_y)
            #これがどこに入るか考えなければいけない
            #xminについて
            flag = 0
            #xminが入らない時
            if dic[xmin][0] > ymax_other:
                ymax_other = dic[xmin][0]
            elif dic[xmin][-1] < ymin_other:
                ymin_other = dic[xmin][-1]
            else:
                xmin_point_min = bisect.bisect_left(dic[xmin], ymin_other)
                xmin_point_max = bisect.bisect_left(dic[xmin], ymax_other)
                #途中で入れないとき  xminが[1,5]のときに[2,3]のとき
                if xmin_point_max == xmin_point_min:
                    flag = 1
                    xmin_left = dic[xmin][xmin_point_max]
                    xmin_right = dic[xmin][xmin_point_max + 1]
                    hozon = ymin_other
                    ymin_other = xmin_left
                    #xmin_rightが採用される時を追加で判定すればいい
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            #xmaxについて
            #xmaxが入らない時
            if dic[xmax][0] > ymax_other:
                ymax_other = dic[xmax][0]
            elif dic[xmax][-1] < ymin_other:
                ymin_other = dic[xmax][-1]
            else:
                xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                if xmax_point_max == xmax_point_min:
                    xmax_left = dic[xmin][xmin_point_max]
                    xmax_right = dic[xmin][xmin_point_max + 1]
                    if ymin_other - xmax_left < xmax_right - ymax_other:
                        ymin_other = xmax_left
                    else:
                        ymax_other = xmax_right
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

            if flag != 0:
                ymin_other = hozon
                ymax_other = xmin_right

                if dic[xmax][0] > ymax_other:
                    ymax_other = dic[xmax][0]
                elif dic[xmax][-1] < ymin_other:
                    ymin_other = dic[xmax][-1]
                else:
                    xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                    xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                    #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                    if xmax_point_max == xmax_point_min:
                        xmax_left = dic[xmin][xmin_point_max]
                        xmax_right = dic[xmin][xmin_point_max + 1]
                        if ymin_other - xmax_left < xmax_right - ymax_other:
                            ymin_other = xmax_left
                        else:
                            ymax_other = xmax_right
                    # 入る時つまりymin, ymaxに変化なし
                    else:
                        pass
                ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

ans_prob.sort()
print(ans_prob[0])


Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
# x or y で sortしてK個見る
# これだけだと同一xに対して複数の選択がある時に落ちる
# 群数列てきな考えがいる？
n, k = map(int, input().split())

point = []
for i in range(n):
    point.append(list(map(int, input().split())))
point.sort()

# Xのポイント
dic = {}
for i in set([j[0] for j in point]):
    dic[i] = []
for i in point:
    dic[i[0]].append(i[1])
for i in set([j[0] for j in point]):
    dic[i].sort()

ans_prob = []
for i in range(n - k + 1):
    xmin = point[i][0]
    xmax = point[i + k - 1][0]
    #
    if xmin == xmax:
        print(0)
        exit()
    #もしmidが無いところなら
    elif xmax == xmin + 1:
        ret = 4*10**18
        for j in dic[xmin]:
            for k in dic[xmax]:
                ret = min(ret, abs(j - k))
        ans_prob.append(ret)
    else:
        _y = []
        for j in range(i, i+k):
            if point[j][0] != xmin and point[j][0] != xmax:
                _y.append(point[j][1])
        ymax_other = max(_y)
        ymin_other = min(_y)
        #これがどこに入るか考えなければいけない
        #xminについて
        flag = 0
        #xminが入らない時
        if dic[xmin][0] > ymax_other:
            ymax_other = dic[xmin][0]
        elif dic[xmin][-1] < ymin_other:
            ymin_other = dic[xmin][-1]
        else:
            xmin_point_min = bisect.bisect_left(dic[xmin], ymin_other)
            xmin_point_max = bisect.bisect_left(dic[xmin], ymax_other)
            #途中で入れないとき  xminが[1,5]のときに[2,3]のとき
            if xmin_point_max == xmin_point_min:
                flag = 1
                xmin_left = dic[xmin][xmin_point_max]
                xmin_right = dic[xmin][xmin_point_max + 1]
                hozon = ymin_other
                ymin_other = xmin_left
                #xmin_rightが採用される時を追加で判定すればいい
            # 入る時つまりymin, ymaxに変化なし
            else:
                pass
        #xmaxについて
        #xmaxが入らない時
        if dic[xmax][0] > ymax_other:
            ymax_other = dic[xmax][0]
        elif dic[xmax][-1] < ymin_other:
            ymin_other = dic[xmax][-1]
        else:
            xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
            xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
            #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
            if xmax_point_max == xmax_point_min:
                xmax_left = dic[xmin][xmin_point_max]
                xmax_right = dic[xmin][xmin_point_max + 1]
                if ymin_other - xmax_left < xmax_right - ymax_other:
                    ymin_other = xmax_left
                else:
                    ymax_other = xmax_right
            # 入る時つまりymin, ymaxに変化なし
            else:
                pass
        ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

        if flag != 0:
            ymin_other = hozon
            ymax_other = xmin_right

            if dic[xmax][0] > ymax_other:
                ymax_other = dic[xmax][0]
            elif dic[xmax][-1] < ymin_other:
                ymin_other = dic[xmax][-1]
            else:
                xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                if xmax_point_max == xmax_point_min:
                    xmax_left = dic[xmin][xmin_point_max]
                    xmax_right = dic[xmin][xmin_point_max + 1]
                    if ymin_other - xmax_left < xmax_right - ymax_other:
                        ymin_other = xmax_left
                    else:
                        ymax_other = xmax_right
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

ans_prob.sort()
print(ans_prob[0])


Fixed submission:
n, k = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
ans = float("inf")

p.sort()
for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = p[j][0] - p[i][0]
        yl = sorted(p[i:j+1],key=lambda x:x[1])
        for l in range(len(yl)-k+1):
            y = yl[l+k-1][1] - yl[l][1]
            ans = min(ans, y*x)
print(ans)