Buggy python submission (verdict: Runtime Error):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    #max_num = 10**5
    max_num = 10
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

    
if __name__ == "__main__":
    main()

Fixed submission:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    max_num = 10**5
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    max_num = sum(a_list)
    ans = [0]*q
    for i in range(q):
        b,c = map(int, input().split())
        count = 0
        for j in range(n):
            if b==a_list[j]:
                count += 1
                a_list[j] = c
        
        max_num += (c - b)*count
        ans[i] = max_num

    for i in ans:
        print(i)
   
if __name__ == "__main__":
    main()

Fixed submission:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    max_num = 10**5
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    ans = [0]*q
    for i in range(q):
        b,c = map(int, input().split())
        for j in range(n):
            if b == a_list[j]:
                a_list[j] = c
        ans[i] = sum(a_list)
        
    for i in ans:
        print(i)
   
if __name__ == "__main__":
    main()

Fixed submission:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    max_num = 10**5
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    ans = [0]*q
    for i in range(q):
        b,c = map(int, input().split())
        for j in range(n):
            if b == a_list[j]:
                a_list[j] = c
        ans[i] = sum(a_list)
        
    for i in ans:
        print(i)
   
if __name__ == "__main__":
    main()

Fixed submission:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    max_num = 10**5
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

    
if __name__ == "__main__":
    main()