Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
print(counter)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
counter = Counter(A)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
lis = [0] * (10**5)
Q = int(input())
for x in A:
  lis[x] += 1 * x
for i in range(Q):
  B, C = map(int, input().split())
  try:
    temp = lis[B] // B
    lis[B] = 0
    lis[C] += temp * C
  except:
    pass
  print(sum(lis))

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
counter = Counter(A)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
lis = [0] * (10**5)
Q = int(input())
for x in A:
  lis[x] += 1 * x
for i in range(Q):
  B, C = map(int, input().split())
  try:
    temp = lis[B] // B
    lis[B] = 0
    lis[C] += temp * C
  except:
    pass
  print(sum(lis))

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
counter = Counter(A)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
lis = {}
Q = int(input())
for x in A:
  if x in lis:
    lis[x] += 1
  else:
    lis[x] = 1
for i in range(Q):
  B, C = map(int, input().split())
  try:
    temp = lis[B]
    del lis[B]
    if lis == {} or not C in lis:
      lis[C] = temp
    else:
      lis[C] += temp
  except:
    pass
  ans = 0
  for x in lis:
    ans += x * lis[x]
  print(ans)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
counter = Counter(A)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
lis = {}
Q = int(input())
for x in A:
  if x in lis:
    lis[x] += 1
  else:
    lis[x] = 1
for i in range(Q):
  B, C = map(int, input().split())
  try:
    temp = lis[B]
    del lis[B]
    if lis == {} or not C in lis:
      lis[C] = temp
    else:
      lis[C] += temp
  except:
    pass
  ans = 0
  for x in lis:
    ans += x * lis[x]
  print(ans)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
counter = Counter(A)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
  B, C = map(int, input().split())
  count = 0
  check = True
  while check == True:
    if B in A:
      count += 1
      A.remove(B)
    else:
      check = False
  for i in range(count):
    A.append(C)
  print(sum(A))


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
su = sum(A)
counter = Counter(A)
lis = {}
for i in range(Q):
  B, C = map(int, input().split())
  su -= B * counter[B]
  su += C * counter[B]
  counter[C] += counter[B]
  counter[B] = 0
  print(su)