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

from bisect import bisect_left


N, *A = map(int, open(0).read().split())
sorted_A = sorted(A)
ans = 0
for i in range(N):
    idx = bisect_left(sorted_A, A[i])
    if i % 2 != idx % 2:
        ans += 1
print(ans // 2)


Error: 0

Fixed submission:

class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i


def get_invnum(li):
    n = len(li)
    t = FenwickTree(max(li))
    res = 0
    for i in range(n):
        res += i - t.sum(li[i])
        t.add(li[i], 1)
    return res


N, *A = map(int, open(0).read().split())
triplet_sorted_A = [0] * N
triplet_sorted_A[::2] = sorted(A[::2])
triplet_sorted_A[1::2] = sorted(A[1::2])
print(get_invnum(triplet_sorted_A))
Problem p04021 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
A_raw = [0] * N
for i in range(N):
    A_raw[i] = (int(input()), i)
A_raw.sort(key=lambda x: x[0])
A = [0] * N
for i in range(N):
    A[A_raw[i][1]] = i

ans = 0
for i in range(N):
    if i % 2 == 0:
        if A[i] % 2 == 1:
            ans += 1

print(ans)


Error: 0

Fixed submission:

N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input()) + 1

A_even = A[::2]
A_odd = A[1::2]
A_even = sorted(A_even)
A_odd = sorted(A_odd)
A_sorted = [0] * N
for i in range(N):
    if i % 2 == 0:
        A_sorted[i] = A_even[i // 2]
    else:
        A_sorted[i] = A_odd[i // 2]


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, idx):
        s = 0
        while idx > 0:
            s += self.tree[idx]
            idx -= idx & -idx
        return s

    def add(self, idx, x):
        while idx <= self.size:
            self.tree[idx] += x
            idx += idx & -idx


bit = Bit(max(A) + 1)
ans = 0
for i in range(N):
    bit.add(A_sorted[i], 1)
    ans += i + 1 - bit.sum(A_sorted[i])

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

N = int(input())
print(int(N * (N + 1) / 2))


Error: TypeError: can only concatenate str (not "int") to str
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p04029/Python/s208468169.py", line 2, in <module>
    print(N * (N + 1) / 2)
TypeError: can only concatenate str (not "int") to str


Fixed submission:

N = input()
print(N * (N + 1) / 2)
Problem p04030 (Python) — buggy submission, verdict: Runtime Error

s = input()
ans = []
for c in s:
    if c == "0":
        ans.append("0")
    if c == "1":
        ans.append("1")
    if c == "B":
        if ans:
            ans.pop(-1)
        else:
            pass
print("".join(ans))


Error: 0

Fixed submission:

s = input()
ans = []
for c in s:
    if c == "0":
        ans.append("0")
    if c == "1":
        ans.append("1")
    if c == "B":
        ans.pop(-1)
print("".join(ans))
Problem p04030 (Python) — buggy submission, verdict: Runtime Error

s = input()
ans = []
for i in s:
    if i != "B":
        ans.append(i)
        continue
    if len(ans) == 0:
        continue
    elif len(ans) != 0:
        ans.pop()
print(*ans, sep="")


Error: 0

Fixed submission:

s = input()
ans = []
for i in s:
    if i != "B":
        ans.append(i)
        continue
    if len(i) == 0:
        continue
    elif len(i) != 0:
        ans.pop()
print(*ans, sep="")
Problem p04030 (Python) — buggy submission, verdict: Runtime Error

lines = list(input())
answers = []
out = ""
for line in lines:
    if line == "0" or line == "1":
        answers.append(line)
    elif answers:
        answers.pop()
for answer in answers:
    out += answer
print(out)


Error: 0

Fixed submission:

lines = list(input())
answers = []
out = ""
for line in lines:
    if line == "0" or line == "1":
        answers.append(line)
    else:
        answers.pop()
for answer in answers:
    out += answer
print(out)
Problem p04030 (Python) — buggy submission, verdict: Runtime Error

s = input()
ans = []
for x in s:
    if x == "0" or x == "1":
        ans.append(x)
    else:
        if len(ans) > 0:
            ans.pop()
print("".join(ans))


Error: 0

Fixed submission:

s = input()
ans = []
for x in s:
    if x == "0" or x == "1":
        ans.append(x)
    else:
        ans.pop()
print("".join(ans))
Problem p04030 (Python) — buggy submission, verdict: Runtime Error

set = input()
words = []
for i in range(len(set)):
    if set[i] == "0":
        words.append("0")
    if set[i] == "1":
        words.append("1")
    if set[i] == "B":
        try:
            words.pop(-1)
        except:
            pass
word = ""
for i in words:
    word += i
print(word)


Error: 0

Fixed submission:

set = input()
words = []
for i in range(len(set)):
    if set[i] == "0":
        words.append("0")
    if set[i] == "1":
        words.append("1")
    if set[i] == "B":
        words.pop(-1)
word = ""
for i in words:
    word += i
print(word)
Problem p04030 (Python) — buggy submission, verdict: Runtime Error

s = input()
s_list = list(s)
out_list = []

for i in range(len(s_list)):
    if s_list[i] == "0":
        out_list.append("0")
    elif s_list[i] == "1":
        out_list.append("1")
    elif s_list[i] == "B":
        if out_list:
            del out_list[-1]

for ol in out_list:
    print(ol, end="")


Error: WA

Fixed submission:

s = input()
s_list = list(s)
out_list = []

for i in range(len(s_list)):
    if s_list[i] == "0":
        out_list.append("0")
    elif s_list[i] == "1":
        out_list.append("1")
    elif s_list[i] == "B":
        del out_list[-1]

for ol in out_list:
    print(ol, end="")
Problem p04031 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
a = [int(i) for i in input().split()]

li_ans = []
ans = 0

for j in range(min(a), max(a)):
    for k in a:
        ans += abs(k - j) ** 2
    else:
        li_ans.append(ans)
        ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))


Error: AttributeError: 'list' object has no attribute 'appned'. Did you mean: 'append'?
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p04031/Python/s677254688.py", line 11, in <module>
    li_ans.appned(ans)
AttributeError: 'list' object has no attribute 'appned'. Did you mean: 'append'?


Fixed submission:

N = int(input())
a = [int(i) for i in input().split()]

li_ans = []
ans = 0

for j in range(min(a), max(a)):
    for k in a:
        ans += abs(k - j) ** 2
    else:
        li_ans.appned(ans)
        ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))
Problem p04033 (Python) — buggy submission, verdict: Runtime Error

a, b = map(int, input().split())
if 0 < a <= b:
    print("Positive")

elif a <= b < 0:
    if (b - a + 1) % 2 == 0:
        print("Positive")

    else:
        print("Negative")
elif a <= 0 <= b:
    print("Zero")


Error: 0

Fixed submission:

a, b = map(int, input().split())
numbers = list(range(a, b + 1))
if a <= 0:
    if 0 <= b or a == 0 or b == 0:
        print("Zero")
        exit()
    if len(numbers) % 2 != 0:
        print("Negative")
    else:
        print("Positive")
else:
    print("Positive")
Problem p04033 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b = map(int, input().split())
res = "Positive"
if b < 0:
    if (b - a + 1) & 1:
        res = "Negative"
elif b >= 0:
    if a <= 0:
        res = "Zero"
print(res)


Error: TLE

Fixed submission:

a, b = map(int, input().split())
p = 1
for i in range(a, b + 1):
    p *= i
if p > 0:
    print("Positive")
elif p == 0:
    print("Zero")
else:
    print("Negative")
Problem p04033 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b = map(int, input().split())

if a > 0 and b > 0:
    print("Positive")
elif a < 0 and b > 0:
    print("Zero")
else:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")


Error: TLE

Fixed submission:

a, b = map(int, input().split())

ans = 1
for i in range(a, b + 1):
    ans *= i

if ans > 0:
    print("Positive")
elif ans < 0:
    print("Negative")
elif ans == 0:
    print("Zero")
else:
    pass
Problem p04034 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3

N, M = list(map(int, input().split()))
xy_table = []

for _ in range(M):
    x, y = list(map(int, input().split()))
    xy_table.append((x, y))

red_box_dict = {i: False for i in range(1, N + 1)}
red_box_dict[1] = True
# 添字0はダミー
# 添字 = 箱の番号として扱う
n_box_list = [0] + [1] * N

for xy in xy_table:
    x, y = xy
    n_box_list[x] -= 1
    n_box_list[y] += 1
    if red_box_dict[x]:
        red_box_dict[y] = True

        if n_box_list[x] == 0:
            red_box_dict[x] = False

ans = len([v for v in red_box_dict.values() if v])

print(ans)


Error: TLE

Fixed submission:

#!/usr/bin/env python3

N, M = list(map(int, input().split()))
xy_table = []

for _ in range(M):
    x, y = list(map(int, input().split()))
    xy_table.append((x, y))

red_box_list = [1]
# 添字0はダミー
# 添字 = 箱の番号として扱う
n_box_list = [0] + [1] * N

for xy in xy_table:
    x, y = xy
    n_box_list[x] -= 1
    n_box_list[y] += 1
    if x in red_box_list:
        if y not in red_box_list:
            red_box_list.append(y)

        if n_box_list[x] == 0:
            red_box_list.remove(x)

ans = len(red_box_list)

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

N, K = map(int, input().split())
D = set(input())

n = N
while True:
    if len(set(str(n)) & D) == 0:
        print(n)
        break
    n += 1


Error: TLE

Fixed submission:

N, K = map(int, input().split())
D = set(input())

n = N
while True:
    if set(str(n)) in D:
        print(n)
        break
    n += 1
Problem p04039 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
d = list(input().split())
ans = 100000
for i in range(n, 100001):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        if ans > i:
            ans = i
print(ans)


Error: 0

Fixed submission:

n, k = map(int, input().split())
d = list(input().split())
for i in reversed(range(n, 10001)):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        ans = i
print(ans)
Problem p04043 (Python) — buggy submission, verdict: Runtime Error

x = list(map(int, input().split()))
if x.count(5) == 2 and x.count(7) == 1:
    print("YES")
else:
    print("NO")


Error: TypeError: 'builtin_function_or_method' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p04043/Python/s312793810.py", line 2, in <module>
    if x.count[5] == 2 and x.count[7] == 1:
TypeError: 'builtin_function_or_method' object is not subscriptable


Fixed submission:

x = list(map(int, input().split()))
if x.count[5] == 2 and x.count[7] == 1:
    print("YES")
else:
    print("NO")
Problem p04043 (Python) — buggy submission, verdict: Runtime Error

A = input()

if A.count("5") == 2 and A.count("7") == 1:
    print("YES")
else:
    print("NO")


Error: ValueError: invalid literal for int() with base 10: '5 5 7'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p04043/Python/s730415764.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '5 5 7'


Fixed submission:

A = int(input())
B = int(input())
C = int(input())
A = [A, B, C]

if A.count(5) == 2 and A.count(7) == 1:
    print("YES")
else:
    print("NO")
Problem p04043 (Python) — buggy submission, verdict: Runtime Error

def main(input: list):
    possible575 = sorted(input) == [5, 5, 7]
    print("YES" if possible575 else "NO")


input = list(map(int, input().split()))
main(input)


Error: WA

Fixed submission:

import asyncio


async def main(input: list):
    possible575 = sorted(input) == [5, 5, 7]
    print(possible575)


input = list(map(int, input().split()))
asyncio.run(main(input))
Problem p04043 (Python) — buggy submission, verdict: Runtime Error

L = [int(x) for x in input().split()]
L.sort()

if L == [5, 5, 7]:
    print("YES")
else:
    print("NO")


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p04043/Python/s688466594.py", line 2, in <module>
    B = input()
EOFError: EOF when reading a line


Fixed submission:

A = input()
B = input()
C = input()

L = [A, B, C]

for x in L:
    if len(x) == 7:
        L.remove(x)
        for y in L:
            if len(y) != 5:
                break
        else:
            print("YES")
            break
else:
    print("NO")
Problem p04044 (Python) — buggy submission, verdict: Runtime Error

N, L = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
print("".join(S))


Error: 0

Fixed submission:

L, N = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
print("".join(S))
Problem p04044 (Python) — buggy submission, verdict: Runtime Error

N, L = map(int, input().split())
S = list(input() for i in range(N))
str = ""
for i in range(N - 1):
    for j in range(N - 1):
        if S[j + 1] + S[j] <= S[j] + S[j + 1]:
            S[j], S[j + 1] = S[j + 1], S[j]
for i in S:
    str += i
print(str)


Error: 0

Fixed submission:

N, L = map(int, input().split())
S = list(input() for i in range(L))
S.sort()
str = ""
for i in S:
    str += i
print(str)
Problem p04044 (Python) — buggy submission, verdict: Runtime Error

N, L = map(int, input().split())
s = [0 for i in range(N)]
for i in range(N):
    s[i] = input()

s.sort()
output = ""
for i in range(N):
    output += s[i]
print(output)


Error: 0

Fixed submission:

N, L = map(int, input().split())
s = [0 for i in range(N)]
for i in range(N):
    s[i] = input()

s.sort()
output = ""
for i in range(L):
    output += s[i]
print(output)
Problem p04044 (Python) — buggy submission, verdict: Runtime Error

N, L = map(int, input().split())
s = [input() for i in range(N)]
s.sort()
print("".join(s))


Error: 0

Fixed submission:

L, N = map(int, input().split())
s = [input() for i in range(N)]
print("".join(sorted(s)))
Problem p04045 (Python) — buggy submission, verdict: Time Limit Exceeded

price, size = map(int, input().split())
dislikes = list(map(int, input().split()))
likes = list(set(range(10)) - set(dislikes))
digits = [int(digit) for digit in str(price)]
r_digits = list(reversed(digits))
res = []
for i in range(len(r_digits)):
    if r_digits[i] in likes:
        res.append(r_digits[i])
    elif max(likes) > r_digits[i]:
        res = [min(likes) for i in range(i)] + [min(x for x in likes if x > r_digits[i])]
    else:
        res = [min(likes) for i in range(i + 1)]
        if i == len(r_digits) - 1:
            res.append(min(x for x in likes if x > 0))

        else:
            r_digits[i + 1] += 1

ans = "".join([str(num) for num in list(reversed(res))])
print(ans)


Error: TLE

Fixed submission:

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

ok = False
found = False
while not ok:
    money_digits = [int(mon) for mon in str(money)]

    for digit in money_digits:
        for dis_digit in dislike_digits:
            if digit == dis_digit:
                found = True
                break
        if found:
            money += 1
            break

    if not found:
        ok = True

print(money)
Problem p04045 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
dlist = input().split()
flg = True
while flg:
    s = str(n)
    for t in s:
        if t in dlist:
            n += 1
            break
    else:
        flg = False
print(n)


Error: 0

Fixed submission:

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

for i in range(n, 10000):
    flg: bool = True
    for s in str(i):
        if int(s) in dlist:
            flg = False
            break
    if flg:
        print(i)
        break