Buggy python submission (verdict: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(A)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= C[b]*b
        s += C[b]*c
        C[c] += c[b]
        c[b] = 0
        print(s)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(A)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= C[b]*b
        s += C[b]*c
        C[c] += c[b]
        c[b] = 0
        print(s)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
rom collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= C[b]*b
        s += C[b]*c
        C[c] += c[b]
        c[b] = 0
        print(s)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
rom collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= C[b]*b
        s += C[b]*c
        C[c] += c[b]
        c[b] = 0
        print(s)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())

    for _ in range(q):
        b, c = map(int, input().split())
        a = [c if i == b else i for i in a]
        print(sum(a))


if __name__ == "__main__":
    main()

Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())

    for _ in range(q):
        l = []
        b, c = map(int, input().split())
        l = [i if i != b else c for i in a]
        print(sum(l))
        a = l[:]


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    for _ in range(q):
        l = []
        b, c = map(int, input().split())
        for i in a:
            l.append(c) if i == b else l.append(i)
        print(sum(l))

        a = l[:]


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    for _ in range(q):
        l = []
        b, c = map(int, input().split())
        for i in a:
            l.append(c) if i == b else l.append(i)
        print(sum(l))

        a = l[:]


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()