alexjercan/bugnet huggingface dataset:
Problem p03739 (Python) — buggy submission, verdict: Time Limit Exceeded

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

# +, -, +, -, ...
sum = 0
count = 0
for i in range(n):
    sum += a[i]
    if i % 2 == 0:
        if sum <= 0:
            count += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            count += abs(sum) + 1
            sum = -1

# -, +, -, +, ...
sum2 = 0
count2 = 0
for i in range(n):
    sum2 += a[i]
    if i % 2 == 0:
        if sum2 >= 0:
            count2 += abs(sum2) + 1
            sum2 = -1
    else:
        if sum2 <= 0:
            count2 += abs(sum2) + 1
            sum2 = 1

print(min(count, count2))


Error: TLE

Fixed submission:

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

sum = a[0]
count = 0

if a[0] == 0:
    if a[1] > 0:
        sum -= 1
        count += 1
    elif a[1] < 0:
        sum += 1
        count += 1

for i in range(1, n):
    tmp = sum
    sum += a[i]
    while tmp > 0 and sum >= 0:
        sum -= 1
        count += 1
    while tmp < 0 and sum <= 0:
        sum += 1
        count += 1

print(count)
Problem p03739 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
an = list(map(int, input().split()))

c1 = 0
c2 = 0
sum1 = 0  # 偶数番目が正
sum2 = 0  # 奇数番目が正
for i in range(n):
    sum1 += an[i]
    sum2 += an[i]
    if i % 2 == 0:
        if sum1 <= 0:
            p = abs(sum1) + 1
            c1 += p
            sum1 += p
        if sum2 >= 0:
            p = abs(sum2) + 1
            c2 += p
            sum2 -= p
    else:
        if sum1 >= 0:
            p = abs(sum1) + 1
            c1 += p
            sum1 -= p
        if sum2 <= 0:
            p = abs(sum2) + 1
            c2 += p
            sum2 += p

print(min(c1, c2))


Error: TLE

Fixed submission:

n = int(input())
an = map(int, input().split())

sum_an = []
tmp = 0
for a in an:
    tmp += a
    sum_an.append(tmp)

c = 0
before_positive = sum_an[0] <= 0
for i in range(n):
    if before_positive and sum_an[i] >= 0:
        p = abs(sum_an[i]) + 1
        c += p
        for j in range(i, n):
            sum_an[j] -= p
        before_positive = False
    elif not before_positive and sum_an[i] <= 0:
        p = abs(sum_an[i]) + 1
        c += p
        for j in range(i, n):
            sum_an[j] += p
        before_positive = True
    else:
        before_positive = not before_positive

print(c)
Problem p03741 (Python) — buggy submission, verdict: Runtime Error

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

ret = float("inf")

sign = 1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1
ret = min(ret, k)

sign = -1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1

ret = min(ret, k)


print(ret)


Error: 0

Fixed submission:

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


def solve(i, s, k, sign):
    if i >= len(A):
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))
Problem p03745 (Python) — buggy submission, verdict: Runtime Error

def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)


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

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if (len(A) > 2) and (A[0] > A[1]):
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

print(ans)


Error: 0

Fixed submission:

def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)


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

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if A[0] > A[1]:
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

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

N = int(input())
A = list(map(int, input().split()))
# N = 9
# A = [1, 2, 1, 2, 1, 2, 1, 2, 1]
# N = 7
# A = [1, 2, 3, 2, 1, 999999999, 1000000000]
# N = 6
# A = [1, 2, 3, 2, 2, 1]
# N = 2
# A = [1, 1]
A = A + [A[-1]]

d = 0
i = 0

inc = None
while i < N:
    if inc is None:
        if A[i] < A[i + 1]:
            inc = True
            d += 1
        elif A[i] > A[i + 1]:
            inc = False
            d += 1
        else:
            inc = None
    else:
        if inc:
            if A[i] > A[i + 1]:
                inc = None
        else:
            if A[i] < A[i + 1]:
                inc = None
    i += 1

if inc is None:
    d += 1
print(d)


Error: TypeError: 'builtin_function_or_method' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03745/Python/s158174043.py", line 2, in <module>
    A = list(map(int, input().split))
TypeError: 'builtin_function_or_method' object is not iterable


Fixed submission:

N = int(input())
A = list(map(int, input().split))
# N = 9
# A = [1, 2, 1, 2, 1, 2, 1, 2, 1]
# N = 7
# A = [1, 2, 3, 2, 1, 999999999, 1000000000]
# N = 6
# A = [1, 2, 3, 2, 2, 1]
# N = 2
# A = [1, 1]
A = A + [A[-1]]

d = 0
i = 0

inc = None
while i < N:
    if inc is None:
        if A[i] < A[i + 1]:
            inc = True
            d += 1
        elif A[i] > A[i + 1]:
            inc = False
            d += 1
        else:
            inc = None
    else:
        if inc:
            if A[i] > A[i + 1]:
                inc = None
        else:
            if A[i] < A[i + 1]:
                inc = None
    i += 1

if inc is None:
    d += 1
print(d)
Problem p03746 (Python) — buggy submission, verdict: Time Limit Exceeded

from queue import deque

n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

s = 1
path = deque([s])
visited = {s}

while True:
    s_remains = links[s] - visited
    if s_remains:
        s = s_remains.pop()
        path.appendleft(s)
        visited.add(s)
    else:
        break

t = 1

while True:
    t_remains = links[t] - visited
    if t_remains:
        t = t_remains.pop()
        path.append(t)
        visited.add(t)
    else:
        break

print(len(path))
print(*path)


Error: TLE

Fixed submission:

from queue import deque

n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

s = 1
t = links[s].pop()
visited = deque([s, t])
while True:
    s_remains = links[s].difference(visited)
    s_flag, t_flag = True, True
    if s_remains:
        s = s_remains.pop()
        visited.appendleft(s)
        s_flag = False
    t_remains = links[t].difference(visited)
    if t_remains:
        t = t_remains.pop()
        visited.append(t)
        t_flag = False
    if s_flag and t_flag:
        break
print(len(visited))
print(*visited)
Problem p03760 (Python) — buggy submission, verdict: Runtime Error

o = list(input())
e = list(input()) + [""]
for i, j in zip(o, e):
    print(i + j, end="")


Error: WA

Fixed submission:

o = list(input())
e = list(input())
for i in range(len(o)):
    print(o[i] + e[i], end="")
Problem p03761 (Python) — buggy submission, verdict: Runtime Error

n = int(input())

cnt = [10000] * 26

for i in range(n):
    s = input()
    tmp = [0] * 26
    for c in s:
        tmp[ord(c) - ord("a")] += 1
    for j in range(26):
        cnt[j] = min(cnt[j], tmp[j])

a = ""
for i in range(26):
    if cnt[i]:
        a = a + chr(ord("a") + i) * cnt[i]
print(a)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03761/Python/s024080261.py", line 5, in <module>
    a = [i for i in a if i in input()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03761/Python/s024080261.py", line 5, in <listcomp>
    a = [i for i in a if i in input()]
EOFError: EOF when reading a line


Fixed submission:

n = int(input()) - 1
a = list(input())
while n and a:
    n -= 1
    a = [i for i in a if i in input()]
print(a)
Problem p03761 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(26)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)


Error: 0

Fixed submission:

n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(25)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)
Problem p03762 (Python) — buggy submission, verdict: Time Limit Exceeded

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

sum_x = 0
for i in range(0, n):
    sum_x += i * x[i] - (n - (i + 1)) * x[i]

sum_y = 0
for i in range(0, m):
    sum_y += i * y[i] - (m - (i + 1)) * y[i]

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)


Error: TLE

Fixed submission:

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

sum_x = 0
for i in range(0, n):
    tmp_x = x[i]
    sum_x += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_x, x)))))

sum_y = 0
for i in range(0, m):
    tmp_y = y[i]
    sum_y += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_y, y)))))

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)
Problem p03765 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys
from itertools import accumulate


def input():
    return sys.stdin.readline().strip()


def acc(li, n):
    res = [0] * (n + 1)
    for i in range(n):
        if li[i] == "A":
            res[i + 1] = 1
        elif li[i] == "B":
            res[i + 1] = 2
    return list(accumulate(res))


def restore(x, y, li):
    return (li[y] - li[x - 1]) % 3


S = input()
T = input()
N = len(S)
M = len(T)

acc_S = acc(S, N)
acc_T = acc(T, M)

q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    v_S = restore(a, b, acc_S)
    v_T = restore(c, d, acc_T)
    print("YES") if v_S == v_T else print("NO")


Error: TLE

Fixed submission:

import sys


def input():
    return sys.stdin.readline().strip()


def restore(s):
    while len(s) > 1:
        s = s.replace("AA", "B")
        s = s.replace("BB", "A")
        s = s.replace("AB", "")
        s = s.replace("BA", "")
    return s


S = input()
T = input()
q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    r_s = restore(S[a - 1 : b])
    r_t = restore(T[c - 1 : d])
    print("YES") if r_s == r_t else print("NO")
Problem p03767 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
member = sorted(map(int, input().split()))
ans = sum(member[N::2])
print(ans)


Error: TLE

Fixed submission:

N = int(input())
member = sorted(map(int, input().split()))
ans = 0
while member:
    member.pop()
    ans += member.pop()
    member.pop(0)
print(ans)
Problem p03768 (Python) — buggy submission, verdict: Time Limit Exceeded

from queue import deque


def paint(s, d, c):
    queue = deque([(d, s)])
    while queue:
        remains, v = queue.popleft()
        if painted[v] >= remains:
            continue
        if colors[v] == 0:
            colors[v] = c
        painted[v] = remains
        if remains:
            queue.extend((remains - 1, u) for u in links[v])


n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

q = int(input())
queries = [map(int, input().split()) for _ in range(q)]
colors = [0] * (n + 1)
painted = [-1] * (n + 1)
while queries:
    paint(*queries.pop())

for c in colors[1:]:
    print(c)


Error: TLE

Fixed submission:

from queue import deque


def dijkstra(s, d):
    queue = deque([(0, s)])
    paint = set()
    while queue:
        cost, v = queue.popleft()
        if cost > d:
            break
        paint.add(v)
        queue.extend((cost + 1, u) for u in links[v] if u not in paint)
    return paint


n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

q = int(input())
queries = [map(int, input().split()) for _ in range(q)]
painted = set()
colors = [0] * (n + 1)
while queries:
    v, d, c = queries.pop()
    paint = dijkstra(v, d) - painted
    for i in paint:
        colors[i] = c
    painted |= paint

for c in colors[1:]:
    print(c)
Problem p03775 (Python) — buggy submission, verdict: Time Limit Exceeded

import math

N = int(input())

min_l = len(str(N))

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        j = int(N / i)
        min_l = min(min_l, max(len(str(i)), len(str(j))))
print(min_l)


Error: TLE

Fixed submission:

N = int(input())

min_l = len(str(N))
o_min_l = min_l

for i in range(1, N):
    if N % i == 0:
        j = int(N / i)
        min_l = min(min_l, max(len(str(i)), len(str(j))))
print(min_l)
Problem p03775 (Python) — buggy submission, verdict: Time Limit Exceeded

# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [(2,2),(3,1)]
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a


n = int(input())
if n == 1:
    print(1)
    exit()
fct = factorize(n)
maxDigit = n
for div in divisorize(fct):
    outNum = num(div)
    nonOutNum = int(n / outNum)
    digitOut = 0
    digitNonOut = 0
    while outNum > 0:
        digitOut += 1
        outNum = int(outNum / 10)
    while nonOutNum > 0:
        digitNonOut += 1
        nonOutNum = int(nonOutNum / 10)
    if max(digitOut, digitNonOut) < maxDigit:
        maxDigit = max(digitOut, digitNonOut)
print(maxDigit)


Error: TLE

Fixed submission:

# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [2, 2, 3]
def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


n = int(input())
if n == 1:
    print(1)
    exit()
divs = factorization(n)
N = [i for i in divs]  # N = bit探索する桁数
maxDigit = n
# Nの要素の全組み合わせが出力
for i in range(1, 1 << len(N)):
    output = []
    nonout = []
    outNum = 1
    nonOutNum = 1
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(N[j])  # このjが今回探索するindexの1つ
            outNum *= N[j]
        else:
            nonout.append(N[j])
            nonOutNum *= N[j]
    # print("{} vs {}".format(outNum, nonOutNum))
    digitOut = 0
    digitNonOut = 0
    while outNum > 0:
        digitOut += 1
        outNum = int(outNum / 10)
    while nonOutNum > 0:
        digitNonOut += 1
        nonOutNum = int(nonOutNum / 10)
    if max(digitOut, digitNonOut) < maxDigit:
        maxDigit = max(digitOut, digitNonOut)
print(maxDigit)
Problem p03775 (Python) — buggy submission, verdict: Time Limit Exceeded

import math

N = int(input())

min_length = -1
for A in range(1, int(math.sqrt(N)) + 1, 1):
    if N % A == 0:
        B = int(N / A)
        len_a = len(str(A))
        len_b = len(str(B))
        length = len_a if len_a >= len_b else len_b
        if min_length == -1 or length < min_length:
            # print("len:{}, A:{}, B:{}".format(length, A, B))
            min_length = length
print(min_length)


Error: TLE

Fixed submission:

import math

N = int(input())

min_length = -1
for i in range(int(math.sqrt(N))):
    for j in range(i + 1):
        A = j + 1
        if N % A == 0:
            B = int(N / A)
            len_a = len(str(A))
            len_b = len(str(B))
            length = len_a if len_a >= len_b else len_b
            if min_length == -1 or length < min_length:
                # print("len:{}, A:{}, B:{}".format(length, A, B))
                min_length = length
print(min_length)
Problem p03775 (Python) — buggy submission, verdict: Runtime Error

import math

N = int(input())

for i in range(1, math.ceil(math.sqrt(N)) + 1):
    if N % i == 0:
        factor1 = N / i
        factor2 = i

factor1 = int(factor1)

if factor1 < factor2:
    print(len(str(factor2)))
else:
    print(len(str(factor1)))


Error: 0

Fixed submission:

import math

N = int(input())

for i in range(1, math.floor(math.sqrt(N))):
    if N % i == 0:
        factor = N / i

factor = int(factor)
print(len(str(factor)))
Problem p03775 (Python) — buggy submission, verdict: Time Limit Exceeded

import math

N = int(input())
ans = float("Inf")
sq = int(math.sqrt(N)) + 1
for i in range(1, sq):
    if N % i == 0:
        a = len(str(i))
        b = len(str(N // i))
        if a > b:
            num = a
        else:
            num = b
        if ans > num:
            ans = num
print(ans)


Error: TLE

Fixed submission:

N = int(input())
res = 10**10 + 1
for A in range(1, N + 1):
    if N % A == 0:
        B = N // A
        a = len(str(A))
        b = len(str(B))
        if a > b:
            num = a
        else:
            num = b
        if res > num:
            res = num
print(res)
Problem p03775 (Python) — buggy submission, verdict: Time Limit Exceeded

from math import floor, sqrt, log10

N = int(input())

for i in range(floor(sqrt(N)), 0, -1):
    if N % i == 0:
        print(floor(log10(N // i)) + 1)
        break


Error: TLE

Fixed submission:

from math import ceil, sqrt, floor, log10

N = int(input())

for i in range(ceil(sqrt(N)), N + 1):
    if N % i == 0:
        print(floor(log10(i)) + 1)
        break
Problem p03775 (Python) — buggy submission, verdict: Runtime Error

import math

N = int(input())

tmp = math.floor(math.sqrt(N))
while N % tmp:
    tmp -= 1
print(len(str(N // tmp)))


Error: 0

Fixed submission:

import math

N = int(input())
tmp = math.isqrt(N)
while N % tmp:
    tmp -= 1
print(len(str(N // tmp)))
Problem p03775 (Python) — buggy submission, verdict: Runtime Error

from math import sqrt, ceil, floor, log10

N = int(input())

min_f = floor(log10(N)) + 1
for A in range(1, ceil(sqrt(N)) + 1):
    if N % A != 0:
        continue
    else:
        B = N // A
        f = floor(max(log10(A), log10(B))) + 1
        if f < min_f:
            min_f = f

print(f)


Error: 0

Fixed submission:

from math import sqrt, ceil, floor, log10

N = int(input())

min_f = ceil(log10(N))
for A in range(1, ceil(sqrt(N))):
    if N % A != 0:
        continue
    else:
        B = N // A
        f = floor(max(log10(A), log10(B))) + 1
        if f < min_f:
            min_f = f

print(f)
Problem p03775 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
m = n * 1

if n == 1:
    print(1)
    exit()

sqr = int(n**0.5)
l1 = len(str(sqr))

pf = {}
for i in range(2, int(m**0.5) + 1):
    while not m % i:
        pf[i] = pf.get(i, 0) + 1
        m //= i
if m > 1:
    pf[m] = 1

ls = sorted(pf.items(), key=lambda x: x[0], reverse=True)
l2 = len(str(ls[0][0]))
other = n // ls[0][0]
l3 = len(str(other))

if l1 <= l2 < l3:
    print(l3)
else:
    print(max(l1, l2))


Error: 0

Fixed submission:

n = int(input())

sqr = int(n**0.5)
l1 = len(str(sqr))

pf = {}
for i in range(2, int(n**0.5) + 1):
    while not n % i:
        pf[i] = pf.get(i, 0) + 1
        n //= i
if n > 1:
    pf[n] = 1

ls = sorted(pf.items(), key=lambda x: x[0], reverse=True)
l2 = len(str(ls[0][0]))

print(max(l1, l2))
Problem p03775 (Python) — buggy submission, verdict: Time Limit Exceeded

import math

num = int(input())
num_sqrt = int(math.sqrt(num))

ans = 11
for A in range(1, num_sqrt + 1):
    if num % A == 0:
        B = int(num / A)
        A, B = str(A), str(B)
        now_ans = max(len(A), len(B))
        ans = min(ans, now_ans)
print(ans)


Error: TLE

Fixed submission:

import math

num = int(input())
num_sqrt = int(math.sqrt(num))

A = num_sqrt
while num % A != 0:
    A += 1
B = int(num / A)
A, B = str(A), str(B)
ans = max(len(A), len(B))
print(ans)
Problem p03776 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a - 1, b):
        if goods[a - 1] != goods[i]:
            break
        total += comb(lastcount, i + 1)

print("{}\\n{}".format(avg, total))


Error: WA

Fixed submission:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if a == 1 or goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a, b + 1):
        total += comb(lastcount, i)

print(avg)
print(total)
Problem p03777 (Python) — buggy submission, verdict: Runtime Error

a, b = input().split()
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")


Error: ValueError: invalid literal for int() with base 10: 'H'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03777/Python/s798758303.py", line 1, in <module>
    a, b = list(map(int, input().split()))
ValueError: invalid literal for int() with base 10: 'H'


Fixed submission:

a, b = list(map(int, input().split()))
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")