alexjercan/bugnet huggingface dataset:
Problem p03488 (Python) — buggy submission, verdict: Runtime Error

S = input()
X, Y = map(int, input().split())

if S.find("F") < 0:
    if X != 0 or Y != 0:
        print("No")
    else:
        print("Yes")
    exit()

n = len(S)
d = list(map(len, S.split("T")))
xs = d[::2]
ys = d[1::2]

dpx = [set() for _ in range(len(xs))]
for i in range(len(xs)):
    if i == 0:
        d = (-1) ** S.find("F")
        dpx[i].add(d * xs[i] + n)
        continue

    for j in dpx[i - 1]:
        dpx[i].add(j + xs[i])
        dpx[i].add(j - xs[i])

dpy = [set() for _ in range(len(ys) + 1)]
dpy[0].add(n)
for i in range(len(ys)):
    for j in dpy[i]:
        dpy[i + 1].add(j + ys[i])
        dpy[i + 1].add(j - ys[i])

ans = (X + n in dpx[-1]) & (Y + n in dpy[-1])
print("Yes" if ans else "No")


Error: 0

Fixed submission:

S = input()
X, Y = map(int, input().split())

if S.find("F") < 0:
    if X != 0 or Y != 0:
        print("No")
        exit()

n = len(S)
d = list(map(len, S.split("T")))
xs = d[::2]
ys = d[1::2]

dpx = [[False] * (2 * n + 1) for _ in range(len(xs))]
for i in range(len(xs)):
    if i == 0:
        d = (-1) ** S.find("F")
        dpx[i][d * xs[i] + n] = True
        continue

    for j in range(2 * n + 1):
        if j + xs[i] <= 2 * n:
            dpx[i][j] |= dpx[i - 1][j + xs[i]]
        if 0 <= j - xs[i] <= 2 * n:
            dpx[i][j] |= dpx[i - 1][j - xs[i]]

dpy = [[False] * (2 * n + 1) for _ in range(len(ys) + 1)]
dpy[0][n] = True
for i in range(len(ys)):
    for j in range(2 * n + 1):
        if j + ys[i] <= 2 * n:
            dpy[i + 1][j] |= dpy[i][j + ys[i]]
        if 0 <= j - ys[i] <= 2 * n:
            dpy[i + 1][j] |= dpy[i][j - ys[i]]

ans = dpx[-1][X + n] & dpy[-1][Y + n]
print("Yes" if ans else "No")
Problem p03488 (Python) — buggy submission, verdict: Runtime Error

s = input()
x, y = map(int, input().split())
command = s.split("T")

command_length = len(command)

x_command = []
y_command = []
for i in range(command_length):
    c = len(command[i])
    if i % 2 == 0:
        x_command.append(c)

    else:
        y_command.append(c)
x -= x_command.pop(0)
x_command.sort(reverse=True)
y_command.sort(reverse=True)

c_x = 0
c_y = 0
for c in x_command:
    if x - c_x >= 0:
        c_x += c
    else:
        c_x -= c

for c in y_command:
    if y - c_y > 0:
        c_y += c
    else:
        c_y -= c
if c_x == x and c_y == y:
    print("Yes")
else:
    print("No")


Error: 0

Fixed submission:

s = input()
x, y = map(int, input().split())
command = s.split("T")

command_length = len(command)
x_command = command_length // 2
y_command = command_length // 2
if command_length % 2 != 0:
    x_command += 1

dpx = [[False for _ in range(8000 + 1)] for _ in range(x_command + 1)]
dpx[0][4000] = True
dpy = [[False for _ in range(8000 + 1)] for _ in range(y_command + 1)]
dpy[0][4000] = True

for i in range(1, x_command + 1):
    f = len(command[2 * (i - 1)])
    for j in range(f, 8000 + 1 - f):
        if dpx[i - 1][j - f] or dpx[i - 1][j + f]:
            dpx[i][j] = True

for i in range(1, y_command + 1):
    f = len(command[2 * (i - 1) + 1])
    for j in range(f, 8000 + 1 - f):
        if dpy[i - 1][j - f] or dpy[i - 1][j + f]:
            dpy[i][j] = True

if dpx[x_command][4000 + x] and dpy[y_command][4000 + y]:
    print("Yes")
else:
    print("No")
Problem p03488 (Python) — buggy submission, verdict: Runtime Error

s = list(input().split("T"))
x, y = map(int, input().split())
s2 = [len(x) for x in s]
LR = [s2[i] for i in range(len(s2)) if i % 2 == 0]
UD = [s2[i] for i in range(len(s2)) if i % 2 == 1]

flag = False
tmp = 1
tmp = tmp << sum(LR)
for i, d in enumerate(LR):
    if i != 0:
        tmp = tmp << d | tmp >> d
    else:
        tmp = tmp << d

if x >= 0:
    tmp = tmp >> sum(LR)
    if (tmp >> x) % 2 == 1:
        flag = True
else:
    if sum(LR) + x >= 0:
        if (tmp >> (sum(LR) + x)) % 2 == 1:
            flag = True
if flag:

    tmp = 1
    tmp = tmp << sum(UD)
    flag = False
    for d in UD:
        tmp = tmp << d | tmp >> d
    if y >= 0:
        tmp = tmp >> sum(UD)
        if (tmp >> y) % 2 == 1:
            flag = True
    else:
        if sum(UD) + y >= 0:
            if (tmp >> (sum(UD) + y)) % 2 == 1:
                flag = True

if flag:
    print("Yes")
else:
    print("No")


Error: 0

Fixed submission:

s = list(input().split("T"))
x, y = map(int, input().split())
s2 = [len(x) for x in s]
pos = [0, 0]
LR = [s2[i] for i in range(len(s2)) if i % 2 == 0]
UD = [s2[i] for i in range(len(s2)) if i % 2 == 1]

flag = False
tmp = 1
tmp = tmp << sum(LR)
for d in LR:
    tmp = tmp << d | tmp >> d

if x >= 0:
    tmp = tmp >> sum(LR)
    if (tmp >> x) % 2 == 1:
        flag = True
else:
    if (tmp >> (sum(LR) + x)) % 2 == 1:
        flag = True
if flag:

    tmp = 1
    tmp = tmp << sum(UD)
    flag = False
    for d in UD:
        tmp = tmp << d | tmp >> d
    if y >= 0:
        tmp = tmp >> sum(UD)
        if (tmp >> y) % 2 == 1:
            flag = True
    else:
        if (tmp >> (sum(UD) + y)) % 2 == 1:
            flag = True

if flag:
    print("Yes")
else:
    print("No")
Problem p03489 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
a = list(map(int, input().split()))
tmp = 1
cnt = 0
S = 0
a.sort()
a.append(0)
for i in range(N):
    if a[i] == a[i + 1]:
        tmp += 1
    else:
        if tmp > a[i]:
            cnt += tmp - a[i]
        elif tmp < a[i]:
            cnt += tmp
        tmp = 1
print(cnt)


Error: TLE

Fixed submission:

N = int(input())
a = list(map(int, input().split()))
cnt = 0
S = 0
for i in range(100000):
    tmp = a.count(i + 1)
    S += tmp
    if tmp > i + 1:
        cnt += tmp - i - 1
    elif tmp < i + 1:
        cnt += tmp
cnt += N - S
print(cnt)
Problem p03489 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
a = list(map(int, input().split()))

a.sort()

count = 0

while a:
    k = a.pop(-1)
    k_count = 1
    while (len(a) > 0) and (a[-1] == k):
        a.pop(-1)
        k_count += 1
    if k_count < k:
        count += k_count
    else:
        count += k_count - k
print(count)


Error: TLE

Fixed submission:

N = int(input())
a = list(map(int, input().split()))

a.sort()

count = 0

while a:
    k = a.pop(0)
    k_count = 1
    while (len(a) > 0) and (a[0] == k):
        a.pop(0)
        k_count += 1
    if k_count < k:
        count += k_count
    else:
        count += k_count - k
print(count)
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

print(sum([int(x) for x in input()]))


Error: WA

Fixed submission:

print(sum([int(x) for x in input().split()]))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

print(input().count("1"))


Error: AttributeError: 'str' object has no attribute 'cont'. Did you mean: 'count'?
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s523943434.py", line 1, in <module>
    print(input().cont("1"))
AttributeError: 'str' object has no attribute 'cont'. Did you mean: 'count'?


Fixed submission:

print(input().cont("1"))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

print(input().count("1"))


Error: AttributeError: 'builtin_function_or_method' object has no attribute 'count'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s893573368.py", line 1, in <module>
    print(input.count("1"))
AttributeError: 'builtin_function_or_method' object has no attribute 'count'


Fixed submission:

print(input.count("1"))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

print(input().count("1"))


Error: TypeError: must be str, not int
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s568979144.py", line 1, in <module>
    print(input().count(1))
TypeError: must be str, not int


Fixed submission:

print(input().count(1))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

sss = input()
print(sss.count("1"))


Error: TypeError: must be str, not int
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s769249601.py", line 2, in <module>
    print(sss.count(1))
TypeError: must be str, not int


Fixed submission:

sss = input()
print(sss.count(1))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

s = input()
print(s.count("1"))


Error: TypeError: must be str, not int
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s417747495.py", line 2, in <module>
    print(s.count(1))
TypeError: must be str, not int


Fixed submission:

s = input()
print(s.count(1))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

a = input()
b = a.count("1")
print(b)


Error: AttributeError: 'int' object has no attribute 'count'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s056240522.py", line 2, in <module>
    b = a.count(int(1))
AttributeError: 'int' object has no attribute 'count'


Fixed submission:

a = int(input())
b = a.count(int(1))
print(b)
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

s = list(input())
ans = 0
for i in range(3):
    if s[i] == "1":
        ans += 1

print(ans)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s116744075.py", line 4, in <module>
    if s[i] == 1:
IndexError: list index out of range


Fixed submission:

s = list(map(int, input().split()))
ans = 0
for i in range(3):
    if s[i] == 1:
        ans += 1

print(ans)
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

a = list(str(int(input())))
print(a.count("1"))


Error: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s840199366.py", line 1, in <module>
    a = list(str(int(input)))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'


Fixed submission:

a = list(str(int(input)))
print(a.count("1"))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

a = list(input())
print(a.count("1"))


Error: AttributeError: 'map' object has no attribute 'count'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s330524274.py", line 2, in <module>
    print(a.count(1))
AttributeError: 'map' object has no attribute 'count'


Fixed submission:

a = map(int, input().split())
print(a.count(1))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
s = str(a)
print(sum(list(map(int, list(s)))))


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s452121313.py", line 4, in <module>
    print(sum(list(map(int, list(a)))))
TypeError: 'int' object is not iterable


Fixed submission:

# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
print(sum(list(map(int, list(a)))))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

print(input().count("1"))


Error: TypeError: must be str, not int
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s325538655.py", line 1, in <module>
    print(input().count(1))
TypeError: must be str, not int


Fixed submission:

print(input().count(1))
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

ans = input().count("1")
print(ans)


Error: TypeError: must be str, not int
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s142159490.py", line 2, in <module>
    num = marbles.count(1)
TypeError: must be str, not int


Fixed submission:

marbles = input()
num = marbles.count(1)
print(num)
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

a, b, c = map(int, input())
print(a + b + c)


Error: ValueError: not enough values to unpack (expected 3, got 1)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s603960512.py", line 1, in <module>
    a, b, c = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)


Fixed submission:

a, b, c = map(int, input().split())
print(a + b + c)
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

s = list(input())
ball = 0
for i in s:
    ball = ball + int(i)

print(ball)


Error: TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s247381986.py", line 4, in <module>
    sum += int(i)
TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int'


Fixed submission:

s = list(input())

for i in s:
    sum += int(i)

print(sum)
Problem p03493 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-
a = list(str(input()))
num = [int(s) for s in a]
print(sum(num))


Error: ValueError: invalid literal for int() with base 10: '<'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s488211323.py", line 5, in <module>
    num = [int(s) for s in a]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03493/Python/s488211323.py", line 5, in <listcomp>
    num = [int(s) for s in a]
ValueError: invalid literal for int() with base 10: '<'


Fixed submission:

# -*- coding: utf-8 -*-
# 入力
a = list(str(input))
# String to Int
num = [int(s) for s in a]
# Output
print(sum(num))
Problem p03494 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
As = [int(x) for x in input().split()]

sunuke = 0
while all([a % 2 == 0 for a in As]):
    sunuke += 1
    As = [a // 2 for a in As]
print(sunuke)


Error: ValueError: invalid literal for int() with base 10: '8 12 40'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03494/Python/s383170291.py", line 2, in <module>
    As = [int(input()) for _ in range(N)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03494/Python/s383170291.py", line 2, in <listcomp>
    As = [int(input()) for _ in range(N)]
ValueError: invalid literal for int() with base 10: '8 12 40'


Fixed submission:

N = int(input())
As = [int(input()) for _ in range(N)]

sunuke = 0
while all([a % 2 == 0 for a in As]):
    sunuke += 1
    As = [a / 2 for a in As]
print(sunuke)
Problem p03494 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

ans = 0
new_a = A.copy()
while 1:
    new_a = [a // 2 if a % 2 == 0 else -1 for a in new_a]
    if -1 in new_a:
        print(ans)
        exit()
    ans += 1

print(ans)


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

ans = 0
while 1:
    new_a = [a // 2 if a % 2 == 0 else -1 for a in A]
    if -1 in new_a:
        break
    ans += 1

print(ans)
Problem p03494 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = [int(x) for x in input().split()]

DA = []
for v in A:
    d = 0
    while v & 1 == 0:
        v = v >> 1
        d += 1
    DA.append(d)

print(min(DA))


Error: TLE

Fixed submission:

N = int(input())
A = [int(x) for x in input().split()]

DA = []
for v in A:
    d = 0
    while v & 1 == 0:
        v = v << 2
        d += 1
    DA.append(d)

print(min(DA))
Problem p03494 (Python) — buggy submission, verdict: Runtime Error

kazu = int(input())
numbers_list = list(map(int, input().split()))
count = 0
seisu = 0
while True:
    for index in range(kazu):
        if numbers_list[index] % 2 != 0:
            seisu = 1
            break
        else:
            numbers_list[index] = numbers_list[index] / 2
    if seisu == 1:
        break
    count += 1
print(count)


Error: TypeError: unsupported operand type(s) for /: 'list' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03494/Python/s612541287.py", line 11, in <module>
    numbers_list[index] = numbers_list / 2
TypeError: unsupported operand type(s) for /: 'list' and 'int'


Fixed submission:

kazu = int(input())
numbers_list = list(map(int, input().split()))
count = 0
seisu = 0
while True:
    for index in range(kazu):
        if numbers_list[index] % 2 != 0:
            seisu = 1
            break
        else:
            numbers_list[index] = numbers_list / 2
    if seisu == 1:
        break
    count += 1
print(count)
Problem p03494 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
ans = 0
while all(A % 2 == 0 for A in a):
    a = [i / 2 for i in a]
    ans += 1
print(ans)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
ans = 0
while all(A % 2 == 0 for A in a):
    A = [i / 2 for i in a]
    ans += 1
print(ans)
Problem p03495 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())
A = list(map(int, input().split()))

numlist = {}
for i in A:
    if i in numlist:
        numlist[i] += 1
    else:
        numlist[i] = 1
numbers = numlist.values()
numbers = sorted(numbers)

change = 0
vari = len(numbers)
for i in range(vari):
    if K >= vari - i:
        break
    change += numbers[i]

print(change)


Error: TLE

Fixed submission:

N, K = map(int, input().split())
A = list(map(int, input().split()))

numlist = {}
for i in A:
    if i in numlist:
        numlist[i] += 1
    else:
        numlist[i] = 1
numbers = numlist.values()
numbers = sorted(numbers)

change = 0
while len(numbers) > K:
    change += numbers[0]
    del numbers[0]
print(change)
Problem p03495 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_dict = {}
for i in a:
    if i in cnt_dict:
        cnt_dict[i] += 1
    else:
        cnt_dict[i] = 1
cnt_dict_sorted = sorted(cnt_dict.items(), key=lambda x: x[1])
ans = 0
if len(cnt_dict_sorted) <= k:
    ans = 0
else:
    tmp = len(cnt_dict_sorted) - k
    for j in range(tmp):
        ans += cnt_dict_sorted[j][1]
print(ans)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_list = []
cnt_dict = {}
for i in a:
    if i in cnt_dict:
        cnt_dict[i] += 1
    else:
        cnt_dict[i] = 1
cnt_dict_sorted = sorted(cnt_dict.items(), key=lambda x: x[1])
for i in set(a):
    cnt_list.append(a.count(i))
ans = 0
if len(cnt_dict_sorted) <= k:
    ans = 0
else:
    tmp = len(cnt_dict_sorted) - k
    for j in range(tmp):
        ans += cnt_dict_sorted[j][1]
print(ans)
Problem p03495 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
aList = list(map(int, input().split()))
num = [0 for _ in range(n + 1)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print(sum(num))


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03495/Python/s233266704.py", line 5, in <module>
    num[i] += 1
IndexError: list index out of range


Fixed submission:

n, k = map(int, input().split())
aList = list(map(int, input().split()))
num = [0 for _ in range(n)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print(sum(num))
Problem p03495 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())
A = list(map(int, input().split()))

A_dict = {}
for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

A_sorted = sorted(A_dict.items(), key=lambda x: x[1], reverse=True)
rewrite = 0
while len(A_sorted) > K:
    tmp = A_sorted.pop()
    rewrite += tmp[1]

print(rewrite)


Error: TLE

Fixed submission:

N, K = map(int, input().split())
A = list(map(int, input().split()))

A_dict = {}
rewrite = 0

for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

while len(A_dict) > K:
    rewrite_key = min(A_dict, key=A_dict.get)
    rewrite += A_dict[rewrite_key]
    del A_dict[rewrite_key]

print(rewrite)
Problem p03495 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())
a = list(map(int, input().split()))

a_cnt = {}
for i in a:
    if i in a_cnt:
        a_cnt[i] += 1
    else:
        a_cnt[i] = 1
from operator import itemgetter

a_cnt = sorted(a_cnt.items(), key=itemgetter(1))

from collections import deque

cnt_list = deque([])
for i, j in a_cnt:
    cnt_list.append(j)

ans = 0
while len(cnt_list) > K:
    ans += cnt_list[0]
    cnt_list.popleft()
print(ans)


Error: TLE

Fixed submission:

N, K = map(int, input().split())
a = list(map(int, input().split()))

a_cnt = {}
for i in a:
    if i in a_cnt:
        a_cnt[i] += 1
    else:
        a_cnt[i] = 1

cnt_list = [0] * len(a_cnt)
for i, value in enumerate(a_cnt.values()):
    cnt_list[i] = value

cnt_list.sort()

ans = 0
while len(cnt_list) > K:
    ans += cnt_list[0]
    cnt_list.pop(0)
print(ans)
Problem p03495 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = (int(i) for i in input().split())
balls = (int(i) for i in input().split())
freqs = {}
for ball in balls:
    freqs[ball] = freqs[ball] + 1 if ball in freqs else 1
freq_hist = list(freqs.values())
freq_hist.sort(reverse=True)
print(sum(freq_hist[k:]))


Error: TLE

Fixed submission:

n, k = (int(i) for i in input().split())
balls = list(int(i) for i in input().split())
ball_set = set(balls)
freqs = list(balls.count(i) for i in ball_set)
freqs.sort(reverse=True)
print(sum(freqs[k:]))
Problem p03495 (Python) — buggy submission, verdict: Time Limit Exceeded

import heapq

N, K = map(int, input().split())
A = map(int, input().split())

T = [0] * (N + 1)

for a in A:
    T[a] += 1

ns = []
for t in T:
    if t > 0:
        heapq.heappush(ns, t)
ans = 0
while len(ns) > K:
    ans += heapq.heappop(ns)
print(ans)


Error: TLE

Fixed submission:

N, K = map(int, input().split())
A = map(int, input().split())

T = [0] * (N + 1)

for a in A:
    T[a] += 1

ns = []
for t in T:
    if t > 0:
        ns.append(t)
ns.sort()
ans = 0
while len(ns) > K:
    ans += ns[0]
    ns = ns[1:]
print(ans)
Problem p03497 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
a = list(map(int, input().split()))
ball = [0] * n

for i in a:
    ball[i - 1] += 1
ball.sort(reverse=True)

ans = 0
if len(ball) > k:
    for i in range(k):
        ans += ball[i]
    ans = n - ans
print(ans)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
ball = {}

for i in a:
    if i in ball.keys():
        ball[i] += 1
    else:
        ball[i] = 1

ball = sorted(ball.items(), key=lambda x: -x[1])

ans = 0
if len(ball) > k:
    for i in range(k):
        ans += ball[i][1]
    ans = n - ans
print(ans)
Problem p03497 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
a = list(map(int, input().split()))

ball = [0] * n
for i in a:
    ball[i - 1] += 1
ball.sort(reverse=True)

ans = n
for i in range(k):
    ans -= ball[i]
print(ans)


Error: KeyError: 0
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03497/Python/s544815203.py", line 16, in <module>
    ans += cnt[i][1]
KeyError: 0


Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = {}

for i in a:
    if i in cnt.keys():
        cnt[i] += 1
    else:
        cnt[i] = 1

ans, k = 0, len(cnt) - k
for i in range(len(cnt) + 1):
    if 0 >= k:
        print(ans)
        break
    ans += cnt[i][1]
    k -= 1