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

S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0
ans.append(ll)

print(max(ans))


Error: 0

Fixed submission:

S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0

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

b = input()
ans = ""

for i in range(len(b)):
    if b[i] == "A" or b[i] == "T" or b[i] == "C" or b[i] == "G":
        ans += "1"
    else:
        ans += "0"
# print(ans)

ls = ans.split("0")
# print(ls)
print(len(max(ls)))


Error: 0

Fixed submission:

b = input()
ans = 0
ls = []
for i in range(len(b)):
    if b[i] == "A" or b[i] == "T" or b[i] == "C" or b[i] == "G":
        ans += 1
    else:
        ls.append(ans)
        ans = 0
print(max(ls))
Problem p03086 (Python) — buggy submission, verdict: Runtime Error

s = input()
n = len(s)

ans = 0
for i in range(n):
    for j in range(i, n):
        if all("ACGT".count(l) for l in s[i : j + 1]):
            ans = max(ans, j - i + 1)

print(ans)


Error: 0

Fixed submission:

string = input()

char = ["A", "C", "G", "T"]

count = 0
lengths = []
for s in string:
    if s in char:
        count += 1
    else:
        lengths.append(count)
        count = 0
else:
    print(max(lengths))
Problem p03086 (Python) — buggy submission, verdict: Runtime Error

s = input()
ans = []
acgt = ["A", "C", "G", "T"]

cnt = 0
for i in range(len(s)):
    if s[i] in acgt:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0
ans.append(cnt)
print(max(ans))


Error: 0

Fixed submission:

s = input()
ans = []
acgt = ["A", "C", "G", "T"]

cnt = 0
for i in range(len(s)):
    if s[i] in acgt:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0
print(max(ans))
Problem p03086 (Python) — buggy submission, verdict: Runtime Error

s = input()

s += "X"
pat = ["A", "C", "G", "T"]
mx = 0
count = 0

for i in range(len(s)):
    if s[i] in pat:
        count += 1
    else:
        if count > mx:
            mx = count
        count = 0

print(mx)


Error: AttributeError: 'str' object has no attribute 'append'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03086/Python/s975280686.py", line 3, in <module>
    s.append("X")
AttributeError: 'str' object has no attribute 'append'


Fixed submission:

s = input()

s.append("X")
pat = ["A", "C", "G", "T"]
mx = 0
count = 0

for i in range(len(s)):
    if s[i] in pat:
        count += 1
    else:
        if count > mx:
            mx = count
        count = 0

print(mx)
Problem p03086 (Python) — buggy submission, verdict: Runtime Error

s = input()
ans = 0
ans_l = [0] * len(s)


for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans_l[ans] += 1
    else:
        ans += 1
print(max(ans_l))


Error: 0

Fixed submission:

s = input()
ans = 0
ans_l = []

if len(s) == 1:
    print(1)
    quit()
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans += 1
    else:
        ans_l.append(ans)
        ans = 0
print(max(ans_l))
Problem p03086 (Python) — buggy submission, verdict: Runtime Error

N = input()
answer_list = []
answer = 0

for i in range(len(N)):
    if N[i] == "A" or N[i] == "T" or N[i] == "C" or N[i] == "G":
        answer += 1
    else:
        answer_list.append(answer)
        answer = 0
    if i + 1 == len(N):
        answer_list.append(answer)
print(max(answer_list))


Error: 0

Fixed submission:

N = input()
answer_list = []
answer = 0

for i in range(len(N)):
    if N[i] == "A" or N[i] == "T" or N[i] == "C" or N[i] == "G":
        answer += 1
    else:
        answer_list.append(answer)
        answer = 0
print(max(answer_list))
Problem p03086 (Python) — buggy submission, verdict: Runtime Error

pat = ["A", "C", "G", "T"]

s = input()

left = right = 0
ans = 0

while left < len(s):
    right = left
    while right < len(s) and s[right] in pat:
        right += 1

    ans = max(ans, right - left)

    left = right + 1

print(ans)


Error: 0

Fixed submission:

pat = ["A", "C", "G", "T"]

s = input()

left = right = 0
ans = 0

while left < len(s):
    right = left
    while s[right] in pat:
        right += 1

    ans = max(ans, right - left)

    left = right + 1

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

n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])


Error: TLE

Fixed submission:

import numpy as np

n, q = map(int, input().split())
s = input()
l_ = np.zeros(q)
r_ = np.zeros(q)

for i in range(q):
    l_tmp, r_tmp = map(int, input().split())
    l_[i] = l_tmp
    r_[i] = r_tmp
l_ = l_ - 1
r_ = r_ - 1
for i in range(q):
    cnt = 0
    t = s[int(l_[i]) : int(r_[i]) + 1]
    for j in range(len(t) - 1):
        if t[j : j + 2] == "AC":
            cnt += 1
    print(cnt)
Problem p03087 (Python) — buggy submission, verdict: Time Limit Exceeded

N, Q = map(int, input().split())
S = input()
L = len(S)
ACnum = [0] * L
for i in range(1, L):
    ACnum[i] += ACnum[i - 1]
    if S[i - 1] == "A" and S[i] == "C":
        ACnum[i] += 1

lr = [None] * Q
for _ in range(Q):
    lr[_] = list(map(int, input().split()))

for i in range(Q):
    ans = ACnum[lr[i][1] - 1] - ACnum[lr[i][0] - 1]
    print(ans)


Error: TLE

Fixed submission:

N, Q = map(int, input().split())
S = input()
lr = [None] * Q
for _ in range(Q):
    lr[_] = list(map(int, input().split()))
for _ in range(Q):
    ans = S.count("AC", lr[_][0] - 1, lr[_][1])
    print(ans)
Problem p03087 (Python) — buggy submission, verdict: Time Limit Exceeded

N, Q = [int(i) for i in input().split()]
S = input()
t = [0] * (N + 1)
for i in range(N):
    end = i + 2
    t[i + 1] = t[i] + (1 if S[i:end] == "AC" else 0)
for i in range(Q):
    l, r = [int(i) for i in input().split()]
    print(t[r - 1] - t[l - 1])


Error: TLE

Fixed submission:

import re

N, Q = [int(i) for i in input().split()]
S = input()
ans = []
for i in range(Q):
    l, r = [int(i) for i in input().split()]
    l -= 1
    s = S[l:r]
    ret = re.findall(r"AC", s)
    ans.append(ret)
for a in ans:
    print(len(a))
Problem p03087 (Python) — buggy submission, verdict: Time Limit Exceeded

n, q = map(int, input().split())
s = input()

t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i : i + 2] == "AC" else 0)
# print(t)
for j in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])


Error: TLE

Fixed submission:

import re

n, q = map(int, input().split())
s = input()

ans = [0] * q

for i in range(q):
    l, r = map(int, input().split())
    sl = s[l - 1 : r]
    # sl = sl.replace("AC", "-")
    # ans = sl.count("-")
    # print(ans)

    result = re.findall(r"AC", sl)
    # print(len(result))
    ans[i] = len(result)
print(*ans, sep="\\n")
Problem p03087 (Python) — buggy submission, verdict: Runtime Error

# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (2 * 10**5 + 10)
idx = 1
while idx < len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])


Error: 0

Fixed submission:

# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (2 * 10**5 + 10)
idx = 1
while idx <= len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])
Problem p03089 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


n = int(input())
b = list(map(int, input().split()))
ope = []
i = n
while i > 0:
    flag = 0
    j = i
    while j > 0:
        if b[j - 1] == j:
            b.pop(j - 1)
            i -= 1
            ope.insert(0, j)
            flag = 1
            break
        j -= 1
    if flag == 0:
        print(-1)
        sys.exit()
for i in ope:
    print(i)


Error: TLE

Fixed submission:

import copy


def insertion(n, x):
    if not x:
        return True
    for i in range(n - 1, -1, -1):
        y = copy.copy(x)
        if y[i] == i + 1:
            y.pop(i)
            ope.insert(0, i + 1)
            if insertion(n - 1, y):
                return True
            else:
                ope.pop(0)
    return False


n = int(input())
b = list(map(int, input().split()))
ope = []
if insertion(n, b):
    for i in ope:
        print(i)
else:
    print(-1)
Problem p03091 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
c = 0
d = 0
for _ in range(min(M, 1000)):
    a, b = map(int, input().split())
    d += a * 5 + b * 7
    c += a * 2 + b * 3
    d %= 100
    c %= 100
if c * 100 + d in [
    15,
    238,
    639,
    1008,
    1870,
    2773,
    3072,
    3622,
    4911,
    4939,
    5062,
    5915,
    6158,
    6669,
    7997,
    8237,
    8289,
    9023,
    9120,
    9182,
    9863,
    9992,
]:
    print("No")
else:
    print("Yes")


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03091/Python/s054793607.py", line 5, in <module>
    a, b = map(int, input().split())
EOFError: EOF when reading a line


Fixed submission:

N, M = map(int, input().split())
c = 0
d = 0
for _ in range(100):
    a, b = map(int, input().split())
print("No")
Problem p03092 (Python) — buggy submission, verdict: Time Limit Exceeded

from bisect import bisect

n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [0] * n
for i, p in enumerate(ppp, start=1):
    qqq[p - 1] = i

dp = [(0, 0)]
for i in qqq:
    s = bisect(dp, (i,))
    ndp = [(j, cost + b) for j, cost in dp[:s]]
    stay_cost = dp[s - 1][1]
    ndp.append((i, stay_cost))
    remain = iter(dp[s:])
    for j, cost in remain:
        if stay_cost > cost + a:
            ndp.append((j, cost + a))
            break
    ndp.extend((j, cost + a) for j, cost in remain)
    dp = ndp
print(dp[-1][1])


Error: TLE

Fixed submission:

from bisect import bisect

n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [0] * n
for i, p in enumerate(ppp, start=1):
    qqq[p - 1] = i

dp = [(0, 0)]
for i in qqq:
    s = bisect(dp, (i,))
    ndp = [(j, cost + b) for j, cost in dp[:s]]
    stay_cost = dp[s - 1][1]
    ndp.append((i, stay_cost))
    ndp.extend((j, cost + a) for j, cost in dp[s:] if stay_cost > cost + a)
    dp = ndp
print(dp[-1][1])
Problem p03095 (Python) — buggy submission, verdict: Time Limit Exceeded

MOD = 1000000007

N = int(input())
S = input()

cnt = {}
for s in S:
    if s not in cnt:
        cnt[s] = 1
    else:
        cnt[s] += 1

ans = 1
for v in cnt.values():
    ans *= v + 1
    ans %= MOD

print(ans - 1)


Error: TLE

Fixed submission:

from itertools import combinations


MOD = 1000000007

N = int(input())
S = input()

chars = set()
cnt = {}
for s in S:
    if s not in chars:
        chars.add(s)
        cnt[s] = 1
    else:
        cnt[s] += 1

ans = N % MOD
r = 2
chars = list(chars)
while r <= len(chars):
    combs = combinations(chars, r)
    for comb in combs:
        res = 1
        for c in comb:
            res *= cnt[c]
            res %= MOD
        ans += res
        ans %= MOD
    r += 1

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

# 2019/03/17
# AtCoder Grand Contest 031 - A

# Input
n = int(input())
s = input()

aprcnt = [1] * 26

# Count up Alphabets
for idx in range(n):
    w_idx = ord(s[idx]) - 97
    aprcnt[w_idx] += 1

# Calc Combination count
ans = 1
for idx in range(26):
    ans = ans * aprcnt[idx]

# Reduces 1 in choose nothing case
ans -= 1
ans = ans % (10**9 + 7)

# Output
print(ans)


Error: 0

Fixed submission:

# 2019/03/16
# AtCoder Grand Contest 031 - A

# Input
n = int(input())
s = input()

aprcnt = [1] * 26

# Count up Alphabets
for idx in range(n):
    w_idx = ord(s[idx]) - 97
    aprcnt[w_idx] += 1

# Calc Combination count
ans = 1
for idx in range(n):
    ans = ans * aprcnt[idx]

# Reduces 1 in choose nothing case
ans -= 1

# Output
print(ans)
Problem p03096 (Python) — buggy submission, verdict: Time Limit Exceeded

# input
n = int(input())

mod = pow(10, 9) + 7
c = []
dp = [0] * (n + 1)
stone_history = dict()
for i in range(n):
    stone = int(input())
    if len(c) == 0:
        dp[i + 1] = 1
    else:
        if stone in stone_history and c[-1] != stone:
            dp[i + 1] = dp[i] + stone_history[stone]
        else:
            dp[i + 1] = dp[i]

    stone_history[stone] = dp[i + 1]
    c.append(stone)

print(dp[-1] % mod)


Error: TLE

Fixed submission:

# input
n = int(input())

c = []
dp = [0] * (n + 1)
for i in range(n):
    stone = int(input())
    if len(c) == 0:
        dp[i + 1] = 1
    else:
        if stone in c and c[-1] is not stone:
            plc = len(c) - 1 - c[::-1].index(stone)
            dp[i + 1] = dp[i] + dp[plc + 1]
        else:
            dp[i + 1] = dp[i]
    c.append(stone)

print(dp[-1])
Problem p03101 (Python) — buggy submission, verdict: Runtime Error

H, W = map(int, input().split())
h, w = map(int, input().split())

print((H - h) * (W - w))


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


Fixed submission:

H, W = int(input().split())
h, w = int(input().split())

print((H - h) * (W - w))
H, W = map(int, input().split())
h, w = map(int, input().split())

print((H - h) * (W - w))
Problem p03101 (Python) — buggy submission, verdict: Runtime Error

in1 = input().split()
in2 = input().split()

H = int(in1[0])
W = int(in1[1])

h = int(in2[0])
w = int(in2[1])

print((H - h) * (W - w))


Error: TypeError: unsupported operand type(s) for -: 'str' and 'str'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03101/Python/s646870351.py", line 10, in <module>
    print((H - h) * (W - w))
TypeError: unsupported operand type(s) for -: 'str' and 'str'


Fixed submission:

in1 = input().split()
in2 = input().split()

H = in1[0]
W = in1[1]

h = in2[0]
w = in2[1]

print((H - h) * (W - w))
Problem p03101 (Python) — buggy submission, verdict: Runtime Error

H, W = map(int, input().split())
h, w = map(int, input().split())
print((H - h) * (W - w))


Error: ValueError: not enough values to unpack (expected 4, got 2)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03101/Python/s695121527.py", line 1, in <module>
    H, W, h, w = map(int, input().split())
ValueError: not enough values to unpack (expected 4, got 2)


Fixed submission:

H, W, h, w = map(int, input().split())
print((H - h) * (W - w))
Problem p03101 (Python) — buggy submission, verdict: Runtime Error

lh, lw = map(int, input().split())
h, w = map(int, input().split())

print(lh * lw - lh * w - lw * h + h * w)


Error: TypeError: can't multiply sequence by non-int of type 'str'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03101/Python/s628387371.py", line 4, in <module>
    print(lh * lw - lh * w - lw * h + h + w)
TypeError: can't multiply sequence by non-int of type 'str'


Fixed submission:

lh, lw = input().split()
h, w = input().split()

print(lh * lw - lh * w - lw * h + h + w)
Problem p03102 (Python) — buggy submission, verdict: Runtime Error

from sys import stdin


def na():
    return map(int, stdin.readline().split())


n, _, c = na()
bs = tuple(na())

cnt = 0
for _ in range(n):
    if sum(x * y for x, y in zip(na(), bs)) > -c:
        cnt += 1

print(cnt)


Error: TypeError: '_io.TextIOWrapper' object is not callable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s048620808.py", line 8, in <module>
    n, _, c = na()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s048620808.py", line 5, in na
    return map(int, stdin().split())
TypeError: '_io.TextIOWrapper' object is not callable


Fixed submission:

from sys import stdin


def na():
    return map(int, stdin().split())


n, _, c = na()
bs = na()

cnt = 0
for _ in range(n):
    if sum(x * y for x, y in zip(na(), bs)) > -c:
        cnt += 1

print(cnt)
Problem p03102 (Python) — buggy submission, verdict: Runtime Error

n, m, c = map(int, input().split())
b = [int(i) for i in input().split()]
a = [[int(j) for j in input().split()] for _ in range(n)]
ans = 0
for k in range(n):
    ct = c
    for l in range(m):
        ct += a[k][l] * b[l]
    if ct > 0:
        ans += 1
    ct = 0
print(ans)


Error: ValueError: invalid literal for int() with base 10: '3 2 1'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s069245551.py", line 3, in <module>
    a = [[int(input()) for _ in range(m)] for _ in range(n)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s069245551.py", line 3, in <listcomp>
    a = [[int(input()) for _ in range(m)] for _ in range(n)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s069245551.py", line 3, in <listcomp>
    a = [[int(input()) for _ in range(m)] for _ in range(n)]
ValueError: invalid literal for int() with base 10: '3 2 1'


Fixed submission:

n, m, c = map(int, input().split())
b = [int(i) for i in input().split()]
a = [[int(input()) for _ in range(m)] for _ in range(n)]
ans = 0
ctn = 0
for j in range(n):
    for k in range(m):
        ctn += b[k] * a[j][k]
    if ctn + c > 0:
        ans += 1
    ctn = 0
print(ans)
Problem p03102 (Python) — buggy submission, verdict: Runtime Error

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

import numpy as np

N, M, C = map(int, input().split())
B = np.ndarray([M, 1])
B = list(map(int, input().split()))
A = np.ndarray([N, M])
for i in range(N):
    A[i, :] = list(map(int, input().split()))

ans = sum((np.dot(A, B) + C) > 0)

print(ans)


Error: TLE

Fixed submission:

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

import numpy as np

N, M, C = map(int, input().split())
B = np.ndarray([M, 1])
B = list(map(int, input().split()))
A = np.ndarray([N, M])
for i in range(N):
    A[i, :] = list(map(int, input().split()))

ans = sum((A @ B + C) > 0)

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

n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for ai in a:
    absum = 0
    for i in range(m):
        absum += ai[i] * b[i]
    if absum + c > 0:
        ans += 1
print(ans)


Error: 0

Fixed submission:

n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for _ in range(n):
    a = list(map(int, input().split()))
    if a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + c > 0:
        ans += 1
print(ans)
Problem p03102 (Python) — buggy submission, verdict: Runtime Error

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0

for i in range(N):
    A = list(map(int, input().split()))
    tmp = C
    for i, j in zip(A, B):
        tmp += i * j
    if tmp > 0:
        ans += 1
print(ans)


Error: ValueError: invalid literal for int() with base 10: '1 2 3'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s538264445.py", line 2, in <module>
    B = [int(input()) for i in range(M)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03102/Python/s538264445.py", line 2, in <listcomp>
    B = [int(input()) for i in range(M)]
ValueError: invalid literal for int() with base 10: '1 2 3'


Fixed submission:

N, M, C = map(int, input().split())
B = [int(input()) for i in range(M)]
A = [[int(input()) for i in range(M)] for j in range(N)]
cnt = 0
for i in range(N):
    ans = 0
    for j in range(M):
        ans += A[j][i] * B[j]
    if ans + C > 0:
        cnt += 1
print(cnt)
Problem p03103 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

ab_hash = {}
count = 0
price_sum = 0
for x in range(len(ab)):
    ab_hash[x] = [ab[x][0], ab[x][1]]
ab_key_sorted = sorted(ab_hash.items(), key=lambda x: x[1][0])

for y in ab_key_sorted:
    if M > y[1][1]:
        price_sum += y[1][0] * y[1][1]
    else:
        price_sum += y[1][0] * M
    M -= y[1][1]
    if M <= 0:
        break

print(price_sum)


Error: 0

Fixed submission:

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

ab_hash = {}
count = 0
price_sum = 0
for x in ab:
    ab_hash[x[0]] = x[1]
ab_key_sorted = sorted(ab_hash.items(), key=lambda x: x[0])
while M > 0:
    if M > ab_key_sorted[count][1]:
        price_sum += ab_key_sorted[count][0] * ab_key_sorted[count][1]
    else:
        price_sum += ab_key_sorted[count][0] * M
    M = M - ab_key_sorted[count][1]
    count += 1

print(price_sum)
Problem p03103 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]


Error: TypeError: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03103/Python/s281800849.py", line 5, in <module>
    for item in a:
TypeError: 'NoneType' object is not iterable


Fixed submission:

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)].sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]
Problem p03103 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
stores = [list(map(int, input().split())) for _ in range(n)]
sorted_sotres = sorted(stores, key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_sotres:
    if number > m:
        ans += cost * m
        break
    elif number == m:
        ans += cost * number
        break
    else:
        ans += cost * number
    m -= number
print(ans)


Error: 0

Fixed submission:

n, m = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(n)]
dict_stores = dict(stores)
lower_cost = sorted(dict_stores.keys())
total = 0
ans = 0
for i in range(n):
    total += dict_stores[lower_cost[i]]
    if total >= m:
        diff = m - (total - dict_stores[lower_cost[i]])
        ans += lower_cost[i] * diff
        break
    else:
        ans += lower_cost[i] * dict_stores[lower_cost[i]]
print(ans)
Problem p03103 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
d = [list(map(int, input().split())) for i in range(N)]
d.sort(key=lambda x: (x[0], x[1]))

c = p = i = 0

while c < M:
    if c + d[i][1] <= M:
        c += d[i][1]
        p += d[i][0] * d[i][1]
        i += 1
    else:
        p += d[i][0] * (M - c)
        break

print(p)


Error: WA

Fixed submission:

N, M = map(int, input().split())
d = dict([list(map(int, input().split()))[::-1] for i in range(N)])
d = sorted(d.items(), key=lambda x: x[1])
c = p = i = 0

while c < M:
    if c + d[i][0] <= M:
        c += d[i][0]
        p += d[i][1] * d[i][0]
        i += 1
    else:
        p += d[i][1] * (M - c)
        print(c)
        break

print(p)