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

import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(999999999)


def get_arithmetic_progression(a, d, n):
    return n * (2 * a + (n - 1) * d) // 2


# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())

    ans = 0
    for i in range(1, n + 1):
        ans += get_arithmetic_progression(i, i, n // i)

    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4"""
        output = """23"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """100"""
        output = """26879"""
        self.assertIO(test_input, output)

    # def test_input_3(self):
    #     test_input = """10000000"""
    #     output = """838627288460105"""
    #     self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Error: TLE

Fixed submission:

import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())

    ans = 0

    for j in range(1, n + 1):
        for i in range(1, n + 1):
            if i % j == 0:
                ans += i

    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4"""
        output = """23"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """100"""
        output = """26879"""
        self.assertIO(test_input, output)

    # def test_input_3(self):
    #     test_input = """10000000"""
    #     output = """838627288460105"""
    #     self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()
Problem p02624 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())

ans = n * (n + 1) // 2

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        ans += j

print(ans)


Error: TLE

Fixed submission:

n = int(input())

ans = 0

for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        ans += j

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

n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
    k = n // i
    ans += i * k * (k + 1) // 2
    if i != k:
        l = n // (i + 1)
        ans += i * (i + 1) * (k + l + 1) * (k - l) // 4
print(ans)


Error: TLE

Fixed submission:

n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        ans += j
print(ans)
Problem p02624 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
out = 0
for i in range(n):
    k = n // (i + 1)
    out += (i + 1) * k * (k + 1) / 2

print(int(out))


Error: TLE

Fixed submission:

n = int(input())
out = 0
for i in range(n):
    j = 1
    while (i + 1) * j <= n:
        out += (i + 1) * j
        j += 1

print(out)
Problem p02624 (Python) — buggy submission, verdict: Runtime Error

# D - Sum of Divisors
from numba import njit


@njit
def solve(N):
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    return res


def main():
    N = int(input())
    print(solve(N))


if __name__ == "__main__":
    main()


Error: ModuleNotFoundError: No module named 'numba'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02624/Python/s317956629.py", line 2, in <module>
    from numba import njit
ModuleNotFoundError: No module named 'numba'


Fixed submission:

# D - Sum of Divisors
from numba import njit


@njit
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()
Problem p02624 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
ans = 0
for i in range(1, N + 1):
    largest = N // i * i
    ans += ((largest + i) * (N // i)) // 2
print(ans)


Error: TLE

Fixed submission:

N = int(input())
num = [1 for _ in range(N + 1)]
for i in range(2, N + 1):
    cnt = 1
    while cnt * i <= N:
        num[cnt * i] += 1
        cnt += 1
ans = 0
for i in range(1, N + 1):
    ans += num[i] * i
print(ans)
Problem p02624 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3

#                 N    N'
#   | 1  2  3  4  5
# 1 | 1  2  3  4  5 :  N // 1   1 * N' (N'+1) // 2
# 2 |    2     4    :  N // 2   2 * N' (N'+1) // 2
# 3 |       3       :  N // 3   3 * N' (N'+1) // 2
# 4 |          4    :  N // 4   4 * N' (N'+1) // 2
# 5 |             5 :  N // 5   5 * N' (N'+1) // 2


def solve(N):
    answer = 0
    for i in range(1, N + 1):
        mprime = N // i
        answer += i * (mprime * (mprime + 1)) // 2
    return answer


def main():
    N = int(input())  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

#!/usr/bin/env python3
import numpy as np


def solve(N):
    fx = np.zeros(N + 1, dtype=np.uint32)
    for i in range(1, N + 1):
        fx[i::i] += 1
    return np.sum(np.arange(0, N + 1, dtype=np.uint64) * fx)


def main():
    N = int(input())  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()
Problem p02626 (Python) — buggy submission, verdict: Runtime Error

import sys


def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    swappable = []
    while b:
        bx = x & b
        if bx == 0:
            # print('bx=0', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p | b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                elif swappable:
                    bs = swappable.pop()
                    p ^= bs
                    q ^= bs
                    p |= b
                    q |= b
                    s -= 2 * b
                else:
                    return -1
        else:
            if s < b:
                return -1
            if p | b <= a0 and q | b > a1:
                p |= b
                swappable.append(b)
            else:
                q |= b
            s -= b

            # print('bx=1', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p


n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))


Error: 0

Fixed submission:

import sys


def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    while b:
        bx = x & b
        if bx == 0:
            # print('bx', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p + b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                # else:
                #     return -1
        else:
            if s < b:
                return -1
            if p + b <= a0 and q + b > a1:
                p |= b
            else:
                q |= b
            s -= b

        # print(f'{b:040b}')
        # print(f'{p:040b}')
        # print(f'{q:040b}')
        # print(f'{a0:040b}')
        # print(f'{a1:040b}')
        # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p


n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))
Problem p02627 (Python) — buggy submission, verdict: Runtime Error

s = input()
if s.isupper():
    print("A")
else:
    print("a")


Error: AttributeError: 'str' object has no attribute 'isuper'. Did you mean: 'isupper'?
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02627/Python/s327847448.py", line 2, in <module>
    if s.isuper():
AttributeError: 'str' object has no attribute 'isuper'. Did you mean: 'isupper'?


Fixed submission:

s = input()
if s.isuper():
    print("A")
else:
    print("a")
Problem p02628 (Python) — buggy submission, verdict: Runtime Error

N, K = (int(i) for i in input().split())
p = [int(i) for i in input().split()]

sp = sorted(p)
print(sum(sp[:K]))


Error: TypeError: unsupported operand type(s) for +: 'int' and 'list'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02628/Python/s927789922.py", line 5, in <module>
    print(sum(sp[:K]))
TypeError: unsupported operand type(s) for +: 'int' and 'list'


Fixed submission:

N, K = (int(i) for i in input().split())
p = [input().split()]

sp = sorted(p)
print(sum(sp[:K]))
Problem p02628 (Python) — buggy submission, verdict: Time Limit Exceeded

# import itertools

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

# tmp = itertools.combinations_with_replacement(P, K)
# tmp = itertools.combinations(P, K)

P.sort()
print(sum(P[0:K]))

# hoge = []
# for i in tmp:
#     hoge.append(sum(i))

# print(min(hoge))


Error: TLE

Fixed submission:

import itertools

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

# tmp = itertools.combinations_with_replacement(P, K)
tmp = itertools.combinations(P, K)

hoge = []
for i in tmp:
    hoge.append(sum(i))

print(min(hoge))
Problem p02628 (Python) — buggy submission, verdict: Time Limit Exceeded

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

P = sorted(P)

print(sum(P[:K]))


Error: TLE

Fixed submission:

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

ans = float("inf")
for i in range(1 << len(P)):
    sum = 0
    cnt = 0
    for j in range(len(P)):
        if (i >> j) & 1 == 1:
            sum += P[j]
            cnt += 1
            if cnt == K:
                ans = min(ans, sum)
print(ans)
Problem p02628 (Python) — buggy submission, verdict: Time Limit Exceeded

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

ans = sum(sorted(p)[:K])
print(ans)


Error: TLE

Fixed submission:

import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = 10e6

for i in itertools.combinations(p, K):
    tmp = sum(list(i))
    if tmp < ans:
        ans = tmp

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

N, K = map(int, input().split())
P = sorted(list(map(int, input().split())))
print(sum(P[:K]))


Error: TypeError: 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02628/Python/s595641778.py", line 3, in <module>
    print(sum(P[:K]))
TypeError: 'NoneType' object is not subscriptable


Fixed submission:

N, K = map(int, input().split())
P = list(map(int, input().split())).sort()
print(sum(P[:K]))
Problem p02628 (Python) — buggy submission, verdict: Time Limit Exceeded

import itertools

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

ans = 0
for _ in range(K):
    min_index = p.index(min(p))
    minv = p.pop(min_index)
    ans += minv

print(ans)


Error: TLE

Fixed submission:

import itertools

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

ans = sum(p)
for v in itertools.permutations(p, K):
    ans = min(ans, sum(v))

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

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


def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\\n
        int: 標準入力
    """
    N = int(input())

    return N


def main(N: int) -> None:
    """
    求解処理.

    Args:\\n
        N (int): 整数
    """
    # 求解処理
    ans = ""
    while N > 0:
        N -= 1
        ans += chr(ord("a") + N % 26)
        N //= 26
    ans = ans[::-1]

    # 結果出力
    print(ans)


if __name__ == "__main__":
    N = get_input()
    main(N)


Error: ModuleNotFoundError: No module named 'numba'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02629/Python/s063087830.py", line 2, in <module>
    from numba import njit, void, i8
ModuleNotFoundError: No module named 'numba'


Fixed submission:

# -*- coding: utf-8 -*-
from numba import njit, void, i8


def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\\n
        int: 標準入力
    """
    N = int(input())

    return N


@njit(void(i8))
def main(N: int) -> None:
    """
    求解処理.

    Args:\\n
        N (int): 整数
    """
    # 求解処理
    ans = ""
    while N > 0:
        N -= 1
        ans += chr(ord("a") + N % 26)
        N //= 26
    ans = ans[::-1]

    # 結果出力
    print(ans)


if __name__ == "__main__":
    N = get_input()
    main(N)
Problem p02629 (Python) — buggy submission, verdict: Runtime Error

alphabets = "abcdefghijklmnopqrstuvwxyz"


n = int(input())

A = []
while True:
    A.append(n % 26)
    n //= 26
    if n == 0:
        break

for i in range(len(A) - 1):
    if A[i] <= 0:
        A[i] += 26
        A[i + 1] -= 1

ANS = []
for a in A[::-1]:
    if a == 0:
        continue
    ANS.append(alphabets[a - 1])

print("".join(ANS))


Error: 0

Fixed submission:

alphabet = "abcdefghijklmnopqrstrvwxyz"


n = int(input()) - 1

A = []
while n > 0:
    A.append(n % 26)
    n //= 26

m = len(A)

if m == 1:
    print(alphabet[A[0]])
    exit()

ANS = []
ANS.append(alphabet[A[0]])
for i in range(1, m - 1):
    if A[i] == 0:
        ANS.append("z")
        A[i + 1] -= 1
    else:
        ANS.append(alphabet[A[i] - 1])
if A[-1]:
    ANS.append(alphabet[A[-1] - 1])

print("".join(ANS[::-1]))
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

import itertools

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

distribution = {}
max_A = max(A)
max_BC = max(list(itertools.chain.from_iterable(BC)))
maximum = max([max_A, max_BC])
# print(max_A, max_BC, maximum)
for i in range(maximum + 1):
    distribution[i] = 0

for Ai in A:
    distribution[Ai] += 1
# print(distribution)

total = sum(A)
for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]
    num_Bi = distribution.get(Bi)
    diff = (Ci - Bi) * num_Bi

    distribution[Bi] = 0
    # print(num_Bi, distribution.get(Bi), Ci)
    distribution[Ci] += num_Bi

    total += diff
    print(total)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

total = sum(A)

for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]

    diff = 0
    for j in range(len(A)):
        if A[j] == Bi:
            diff += Ci - A[j]
            A[j] = Ci

    total += diff
    print(total)
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
q = int(input())
B = [list(map(int, input().split())) for _ in range(q)]

from collections import Counter

ans = sum(a.copy())
a = Counter(a)

for (b, c) in B:
    ans += a[b] * (c - b)
    print(ans)
    a[c] += a[b]
    a[b] = 0


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
q = int(input())
B = [list(map(int, input().split())) for _ in range(q)]

# print(n,a,q,B)

# from collections import Counter

# _a = Counter()

for (b, c) in B:
    a = [c if x == b else x for x in a]
    print(sum(a))
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import defaultdict

N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    B.append(b)
    C.append(c)

A_dict = defaultdict(int)
for a in A:
    A_dict[a] += 1

A_sum = sum(A)
for b, c in zip(B, C):
    n = A_dict[b]
    A_dict[b] = 0
    A_dict[c] += n
    A_sum += (c - b) * n
    print(A_sum)


Error: TLE

Fixed submission:

N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    B.append(b)
    C.append(c)

A_dict = {}
for a in A:
    A_dict[a] = A.count(a)

A_sum = sum(A)
for b, c in zip(B, C):
    if b in A_dict.keys():
        n = A_dict[b]
    else:
        n = 0
    A_dict[b] = 0
    if c in A_dict.keys():
        A_dict[c] += n
    else:
        A_dict[c] = n
    A_sum += (c - b) * n
    print(A_sum)
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

count_list = [0] * (10**5 + 1)

for i in range(N):
    count_list[arr[i]] += 1

ans = sum(arr)

for i in que:
    keep = count_list[i[0]]
    c_ans = ans + keep * (i[1] - i[0])
    print(c_ans)
    ans = c_ans
    if count_list[i[0]] == 0:
        continue
    if count_list[i[0]] != 0:
        count_list[i[1]] += count_list[i[0]]
        count_list[i[0]] = 0


Error: TLE

Fixed submission:

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

for i in que:
    for j in range(N):
        if arr[j] == i[0]:
            arr[j] = i[1]
    print(sum(arr))
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
q = int(input())
xy = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*xy)]

ans = 0

sum_all = 0
for cnt in range(n):
    sum_all += a[cnt]

a = sorted(a)
list_a_num = [0] * (10**5 + 1)
for cnt in range(n):
    list_a_num[a[cnt]] += 1

for cnt in range(q):
    sum_all += (c[cnt] - b[cnt]) * list_a_num[b[cnt]]
    list_a_num[c[cnt]] += list_a_num[b[cnt]]
    list_a_num[b[cnt]] = 0
    print(sum_all)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
q = int(input())
xy = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*xy)]

stuck_b = []
stuck_c = []
stuck_sum = []

sum = 0

for cnt_q in range(q):
    sum = 0
    if len(stuck_b) > 0:
        if stuck_b[cnt_q] == b[cnt_q] and stuck_c[cnt_q] == c[cnt_q]:
            print(stuck_sum[cnt_q])
        else:
            for cnt_n in range(n):
                if a[cnt_n] == b[cnt_q]:
                    a[cnt_n] = c[cnt_q]
            for num in range(n):
                sum += a[num]
            print(sum)
    else:
        for cnt_n in range(n):
            if a[cnt_n] == b[cnt_q]:
                a[cnt_n] = c[cnt_q]
        for num in range(n):
            sum += a[num]
        print(sum)
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = [0 for _ in range(10**5 + 1)]

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

for _ in range(Q):
    B, C = map(int, input().split())
    sum_res = sum_res - (counter[B] * B)
    sum_res = sum_res + (counter[B] * C)
    counter[C] += counter[B]
    counter[B] = 0
    print(sum_res)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]


for nums in B:
    A = [nums[1] if i == nums[0] else i for i in A]
    print(sum(A))
Problem p02630 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

counter = Counter(A)
ans = 0
for num, count in counter.items():
    ans += num * count

for i in range(Q):
    if B[i] in counter:
        ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]
        counter[C[i]] = counter[C[i]] + counter.pop(B[i])
    print(ans)


Error: TypeError: unhashable type: 'list'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02630/Python/s734232725.py", line 21, in <module>
    counter[C[i]] = counter[C[i]] + counter.pop([B[i]])
TypeError: unhashable type: 'list'


Fixed submission:

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

counter = Counter(A)
ans = 0
for num, count in counter.items():
    ans += num * count

for i in range(Q):
    if B[i] in counter:
        ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]
        counter[C[i]] = counter[C[i]] + counter.pop([B[i]])
    print(ans)
Problem p02630 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    else:
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0


Error: TLE

Fixed submission:

n = int(input())
ls = input()
q = int(input())
for _ in range(q):
    b, q = map(str, input().split())
    ls = ls.replace(b, q)
    print(sum(map(int, ls.split())))