Buggy python submission (verdict: Time Limit Exceeded):
def getCalc(NUM):
    sum = 0
    for i in range(len(NUM)):
        sum += i * NUM[i]

    return sum


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

max_num = max(max(A), max(B), max(C))

NUM = [0]*(max_num + 1)

for i in range(max_num+1):
    NUM[i] = A.count(i)

for i in range(Q):
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(getCalc(NUM))


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Runtime Error):
def getCalc(NUM):
    sum = 0
    for i in range(len(NUM)):
        sum += i*NUM[i]


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

max_num = max(max(A), max(B), max(C))

NUM = [0]*max_num + 1

for i in range(NUM):
    NUM[i] = A.count(i)

for i in range(Q):
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(getCalc(NUM))


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
def getCalc(AAA, BBB):
    sum = 0
    for i in range(len(AAA)):
        sum += AAA[i] * BBB[i]
    return sum


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

AAA = []
BBB = []

for i in range(10 ** 5 + 1):
    count = A.count(i)
    if (count > 0):
        AAA.append(i)
        BBB.append(count)

total = getCalc(AAA, BBB)

for i in range(Q):
    if (B[i] in AAA):
        index = AAA.index(B[i])

        if(C[i] in AAA):
            Cindex = AAA.index(C[i])
            AAA[index] = C[i]
            BBB[index] += BBB[Cindex]
            AAA.pop(Cindex)
            BBB.pop(Cindex)
        else:
            AAA[index] = C[i]

        total = getCalc(AAA, BBB)

    print(total)


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Runtime Error):
def getCalc(AAA, BBB):
    sum = 0
    for i in range(len(AAA)):
        sum += AAA[i] * BBB[i]
    return sum


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

AAA = []
BBB = []

for i in range(10 ** 5 + 1):
    count = A.count(i)
    if (count > 0):
        AAA.append(i)
        BBB.append(count)

for i in range(Q):
    if (B[i] in AAA):
        index = AAA.index(B[i])

        if(C[i] in AAA):
            Cindex = AAA.index(C[i])
            AAA[index] = C[i]
            BBB[index] += BBB[Cindex]
            AAA.pop(Cindex)
            BBB.pop(Cindex)
        else:
            AAA[index] = C[i]

        total = getCalc(AAA, BBB)

    print(total)


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
def getCalc(AAA, BBB):
    sum = 0
    for i in range(len(AAA)):
        sum += AAA[i] * BBB[i]
    return sum


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

total = sum(A)

AAA = []
BBB = []

for i in range(10 ** 5 + 1):
    count = A.count(i)
    if (count > 0):
        AAA.append(i)
        BBB.append(count)

for i in range(Q):
    if (B[i] in AAA):
        AAA = [C[i] if x == B[i] else x for x in AAA]
    print(getCalc(AAA, BBB))


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

for i in range(Q):
    if(B[i] in A):
        count = A.count(B[i])

        d = C[i] - B[i]
        total += count * d
        print(total)

        A = [C[i] if x == B[i] else x for x in A]
    else:
        print(total)


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

for i in range(Q):
    count = A.count(B[i])

    d = C[i] - B[i]
    total += count * d
    print(total)

    A = [C[i] if x == B[i] else x for x in A]


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

for i in range(Q):
    count = A.count(B[i])

    d = C[i] - B[i]
    total += count * B
    print(total)

    A = [C[i] if x == B[i] else x for x in A]


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

for i in range(Q):
    A = [C[i] if x == B[i] else x for x in A]
    print(sum(A))


Fixed submission:

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

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

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

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)