Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

list_a.sort()

counts = []

for i in range(0, 100000):
    if (i+1) in list_a:
        counts.append(list_a.count(i+1))
    else:
        counts.append(0)

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

counts = []

for i in range(0, 100000):
    if (i+1) in list_a:
        counts.append(list_a.count(i+1))
    else:
        counts.append(0)

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

counts = []

for i in range(1, 100000):
    if i in list_a:
        counts.append(list_a.count(i))
    else:
        counts.append(0)

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

counts = []

for i in range(100000):
    if i in list_a:
        counts.append(list_a.count(i))
    else:
        counts.append(0)

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b] * (c - b)

    counts[c] += counts[b]
    counts[b] = 0

    print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

counts = []

for i in range(100000):
    counts.append(list_a.count(i))

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b] * (c - b)

    counts[c] += counts[b]
    counts[b] = 0

    print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

appeared = list(set(list_a))
counts = []

for i in range(len(appeared)):
    counts.append(list_a.count(appeared[i]))

q = int(input())
ans = 0

for i in range(len(appeared)):
    ans += appeared[i] * counts[i]

for i in range(q):
    b, c = map(int, input().split())

    if b in appeared:
        b_idx = appeared.index(b)
        b_count = counts[b_idx]
        ans += b_count * (c - b)
        print(ans)

        if c in appeared:
            c_idx = appeared.index(c)
            counts[c_idx] += counts[b_idx]
            appeared.pop(b_idx)
            counts.pop(b_idx)
        else:
            appeared.append(c)
            counts.append(counts[b_idx])
            appeared.pop(b_idx)
            counts.pop(b_idx)
    else:
        print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list(map(int, input().split()))
q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())
    count = list_a.count(b)
    list_a = [c if i == b else i for i in list_a]
    ans += count * (c-b)

    print(ans)


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)

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

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


Fixed submission:
import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)