Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
A = list(map(int, input().split( )))
Q = int(input())
Sum = sum(A)
#Q個の整数の組(B,C)が与えられてB \to Cとして合計を計算
#合計は(Ci-Bi)*(A.count(Bi))変化する.
for i in range(Q):
  E= list(map(int, input().split( )))
  b, c = E[0], E[1]
  dis = c - b 
  Num = A.count(b)
  Sum = Sum + dis*Num
  print(Sum)
  A = [c if a == b else a for a in A]

Fixed submission:
from collections import Counter
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
A = list(map(int, input().split( )))
Q = int(input())
Sum = sum(A)
#Counterなるものがあるらしい
coun = Counter(A)
#Q個の整数の組(B,C)が与えられてB \to Cとして合計を計算
#合計は(Ci-Bi)*(A.count(Bi))変化する.
for _ in range(Q):
  b, c = map(int, input().split( ))
  Sum += (c-b)*coun[b]
  coun[c] += coun[b]
  coun[b] = 0
  print(Sum)
  # replaceするとタイムエラーになるのか…
  #  A = [c if a == b else a for a in A]
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
arr = []
for _ in range(N):
  line = input()
  if line not in arr:
    arr.append(line)
print(len(arr))  
  
  
  
  
  

Fixed submission:
N = int(input())
arr = set()
s = 0
for _ in range(N):
  arr.add(input())
  
print(len(arr))
Buggy python submission (verdict: Runtime Error):
a.b = list(map(int, input().split( )))
if 1 <= a <= 9 and 1 <= b <= 9:
  print(a*b)
else:
  print(-1)
  

Fixed submission:
a,b = map(int, input().split( ))
if 1 <= a <= 9 and 1 <= b <= 9:
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = set()
for i in range(1,10):
  for j in range(1,10):
    a.append(i*j)
if n in a:
  print('Yes')
else:
  print('No')
    

Fixed submission:
n = int(input())
a = []
for i in range(1,10):
  for j in range(1,10):
    a.append(i*j)
if n in a:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
log = []
arr = []
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  s = ''.join(S)
  if s not in log:
    log.append(s)
    arr.append(1)
  else:
    i = log.index(s)
    ans += arr[i]
    arr[i] += 1
    
print(ans)
  



Fixed submission:

n = int(input())
arr = {}
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  s = ''.join(S)
  if s in arr:
    ans += arr[s]
    arr[s] += 1
  else:
    arr[s] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
log = []
arr = []
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  if S not in log:
    log.append(S)
    arr.append(1)
  else:
    i = log.index(S)
    ans += arr[i]
    arr[i] += 1
    
print(ans)
  



Fixed submission:

n = int(input())
arr = {}
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  s = ''.join(S)
  if s in arr:
    ans += arr[s]
    arr[s] += 1
  else:
    arr[s] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
log = []
arr = []
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  if S not in log:
    log.append(S)
    arr.append(1)
  else:
    i = log.index(S)
    ans += arr[i]
    arr[i] += 1
    
print(ans)
  



Fixed submission:

n = int(input())
arr = {}
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  s = ''.join(S)
  if s in arr:
    ans += arr[s]
    arr[s] += 1
  else:
    arr[s] = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, inpuy().split( ))
d = a-b
print(min(c-d, 0))

Fixed submission:
a, b, c = map(int, input().split( ))
d = a-b
print(max(c-d, 0))
Buggy python submission (verdict: Runtime Error):
from collections import deque
from bisect import bisect_left
S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1
mod = 10**9 + 7

for i in range(len(S)):
  x = S[-(i+1)]
  if x == '?':
    for k in range(10):
      for j in range(13):
        dp[i+1][(mul*k+j)%13] += dp[i][j]
        dp[i+1][(mul*k+j)%13] %= mod
  else:
    k = int(x)
    for j in range(13):
      dp[i+1][(mul*k+j)%13] += dp[i][j]
      dp[i+1][(mul*k+j)%13] %= mod
  mul = mul*10 % 13  
print(dp[len(S)][5])

Fixed submission:
a, b = map(int, input().split( ))
s = a + b
if s %2 ==1:
  print('IMPOSSIBLE')
else:
  print(s//2)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split( ))
s = a + b
if s %2 ==1:
  print('IMPOSSIBLE')
else;
print(s//2)

Fixed submission:
a, b = map(int, input().split( ))
s = a + b
if s %2 ==1:
  print('IMPOSSIBLE')
else:
  print(s//2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from bisect import bisect_left
S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1
mod = 10**9 + 7

for i in range(len(S)):
  x = S[-(i+1)]
  if x == '?':
    for k in range(10):
      for j in range(13):
        dp[i+1][(mul*k+j)%13] += dp[i][j]
        dp[i+1][(mul*k+j)%13] %= mod
  else:
    k = int(x)
    for j in range(13):
      dp[i+1][(mul*k+j)%13] += dp[i][j]
      dp[i+1][(mul*k+j)%13] %= mod
  mul = mul*10 % 13  
print(dp[len(S)][5])

Fixed submission:
from collections import deque
from bisect import bisect_left
S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1
mod = 10**9 + 7

for i in range(len(S)):
  x = S[-(i+1)]
  if x == '?':
    for k in range(10):
      for j in range(13):
        dp[i+1][(mul*k+j)%13] += dp[i][j]
        dp[i+1][(mul*k+j)%13] %= mod
  else:
    k = int(x)
    for j in range(13):
      dp[i+1][(mul*k+j)%13] += dp[i][j]
      dp[i+1][(mul*k+j)%13] %= mod
  mul = mul*10 % 13  
print(dp[len(S)][5])
Buggy python submission (verdict: Runtime Error):
s = input()
print(s.replace(2017, 2018))

Fixed submission:
s = input()
print(s.replace('2017', '2018'))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
re = 0
re2 = 0

for i in range(n):
    re += a[i]*sum(a[i+1:])
    #for m in range(n-i-1):
        #re = a[i]*a[i+m+1]
        #re2 += re

ans = re %1000000007
print(ans)

Fixed submission:
d,t,s =map(int,input().split())
if d/s <=t :
    print('Yes')
else :
    print('No')

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
re = 0
re2 = 0

for i in range(n):
    for m in range(n-i-1):
        re = a[i]*a[i+m+1]
        re2 += re

ans = re2 %1000000007
print(ans)

Fixed submission:
d,t,s =map(int,input().split())
if d/s <=t :
    print('Yes')
else :
    print('No')

Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
result=0
#count=0
for i in range(len(s)-len(t)+1) :
    count=0
    for n in range(len(t)):
        if s[i+n]==t[n]:
            count += 1
        #s[i:i+len(t)] == t
    
    if count>result:
        result=count


print(len(t)-result)

Fixed submission:
d,t,s =map(int,input().split())
if d/s <=t :
    print('Yes')
else :
    print('No')

Buggy python submission (verdict: Runtime Error):
d,t,s =map(int,input().split())
if d%s <=t :
    print(Yes)
else :
    print(No)

Fixed submission:
d,t,s =map(int,input().split())
if d/s <=t :
    print('Yes')
else :
    print('No')
Buggy python submission (verdict: Runtime Error):
import numpy as np
max_change = 1000
s = input()
t = input()
list_t = np.array([ _ for _ in t])
for i in range(1,len(s) - len(t) + 1):
    s_sample = s[i-1:len(t)+i-1]
    list_ss = np.array([ _ for _ in list_ss])
    list_tf = list_t == list_ss
    n_change = len(list_t) - sum(list_tf)
    if n_change < max_change:
        max_change = n_change
    else:
        pass
print(max_change)

Fixed submission:
import numpy as np
max_change = 1000
s = input()
t = input()
list_t = np.array([ _ for _ in t])
if len(s) == len(t):
    list_s = np.array([ _ for _ in s])
    list_tf = list_t == list_s
    n_change = len(list_t) - sum(list_tf)
    if n_change < max_change:
        max_change = n_change
    else:
        pass
else:
    for i in range(1,len(s) - len(t) + 1):
        s_sample = s[i-1:len(t)+i-1]
        list_ss = np.array([ _ for _ in s_sample])
        list_tf = list_t == list_ss
        n_change = len(list_t) - sum(list_tf)
        if n_change < max_change:
            max_change = n_change
        else:
            pass
print(max_change)

Buggy python submission (verdict: Runtime Error):
import pandas as pd

def diffab(x):
    if x.a == x.b:
        return 1
    else:
        return 0

max_change = 1000

s = input()
t = input()
list_t = pd.Series([ _ for _ in t],name="a")

for i in range(1,len(s) - len(t) + 1):
    s_sample = s[i-1:len(t)+i-1]
    list_ss = pd.Series([ _ for _ in s_sample],name="b")
    df = pd.concat([list_t,list_ss],axis=1)
    df['flg'] = df.apply(lambda x:diffab(x),axis=1)
    n_change = len(list_t) - sum(df.flg)
    if n_change < max_change:
        max_change = n_change
    else:
        pass
print(max_change)

Fixed submission:
import numpy as np
max_change = 1000
s = input()
t = input()
list_t = np.array([ _ for _ in t])
if len(s) == len(t):
    list_s = np.array([ _ for _ in s])
    list_tf = list_t == list_s
    n_change = len(list_t) - sum(list_tf)
    if n_change < max_change:
        max_change = n_change
    else:
        pass
else:
    for i in range(1,len(s) - len(t) + 1):
        s_sample = s[i-1:len(t)+i-1]
        list_ss = np.array([ _ for _ in s_sample])
        list_tf = list_t == list_ss
        n_change = len(list_t) - sum(list_tf)
        if n_change < max_change:
            max_change = n_change
        else:
            pass
print(max_change)
Buggy python submission (verdict: Runtime Error):
pre = 0
max_chair = 0
list_chair = []
for i in list_height:
    if i < pre:
        max_chair = pre - i
        pre = i + max_chair
        list_chair.append(max_chair)
    else:
        pre = i        
print(sum(list_chair))

Fixed submission:
n = input()
list_height = list(map(int, input().split()))
pre = 0
max_chair = 0
list_chair = list()
for i in list_height:
    if i < pre:
        max_chair = pre - i
        pre = i + max_chair
        list_chair.append(max_chair)
    else:
        pre = i
print(sum(list_chair))
Buggy python submission (verdict: Runtime Error):
a, b = map(int .input().split())
if (a*b) % 2:
  print("Odd")
else:
  print("Even")

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")
Buggy python submission (verdict: Runtime Error):
nums = list(map(int, input().split()))
ans = -1
for i in nums:
    if nums[i] == 0:
        print(i)

Fixed submission:
nums = list(map(int, input().split()))
index = 0
for i in nums:
    if nums[index] == 0:
        print(index+1)
    index += 1
Buggy python submission (verdict: Runtime Error):
def main():
    input()
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()
	xxx=False
    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n=int(input())
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()

    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# 
import sys

from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())

l = [0] * N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            v = x**2+y**2+z**2+x*y+y*z+z*x
            if v <= N:
                l[v-1] = l[v-1] + 1

import matplotlib.pyplot as plt

for i in l:
    print(i)

Fixed submission:
# 
import sys

from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())

l = [0] * N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            v = x**2+y**2+z**2+x*y+y*z+z*x
            if v <= N:
                l[v-1] = l[v-1] + 1

for i in l:
    print(i)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d,e = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

if a==0:
  print('1')
elif b==0:
  print('2')
elif c==0:
  pront('3')
elif d==0:
  print('4')
elif e==0:
  print('5')


Fixed submission:
from sys import stdin

#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d,e = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

if a==0:
  print('1')
elif b==0:
  print('2')
elif c==0:
  print('3')
elif d==0:
  print('4')
elif e==0:
  print('5')
Buggy python submission (verdict: Runtime Error):
a,b=int(input())
print(a*b)

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
a,b=map(int(input().split()))
print(a*b)

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
a,b=map(input().split())
print(a*b)

Fixed submission:
a,b=map(int,input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=n%10
if a=2 or a=4 or a=5 or a=7 or a=9:
  print('hon')
elif a=0 or a=1 or a=6 or a=8:
  print('pon')
elif a=3:
  print('bon')


Fixed submission:
n=int(input())
a=n%10
if a==2 or a==4 or a==5 or a==7 or a==9:
  print('hon')
elif a==0 or a==1 or a==6 or a==8:
  print('pon')
elif a==3:
  print('bon')
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())

if len(s)<=k:
  print(s)
else:
  print(s[:k]+'...')

Fixed submission:
k=int(input())
s=input()

if len(s)<=k:
  print(s)
else:
  print(s[:k]+'...')
Buggy python submission (verdict: Runtime Error):
a ,b ,c= map(int(),input().split())
if a+b+c<=21:
  	print(win)
else:
	print(bust)

Fixed submission:
a ,b ,c= map(int,input().split())
if a+b+c<=21:
  	print('win')
else:
	print('bust')

Buggy python submission (verdict: Runtime Error):
a ,b ,c= map(int,input().split())
if a+b+c<=21:
  	print(win)
else:
	print(bust)

Fixed submission:
a ,b ,c= map(int,input().split())
if a+b+c<=21:
  	print('win')
else:
	print('bust')

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())

if a+b+c<=21:
  print(win)
else:
  print(bust)

Fixed submission:
a ,b ,c= map(int,input().split())
if a+b+c<=21:
  	print('win')
else:
	print('bust')
Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
distance = n[1]
points = [list(map(int, input().split())) for i in range(n[0])]
ans = 0
for i in points:
    x = i[0]
    y = i[1]
    d = (x**2 + y**2)**-2
    if d <= distance:
        ans += 1
print(ans)

Fixed submission:
import math
n = list(map(int, input().split()))
distance = n[1]
points = [list(map(int, input().split())) for i in range(n[0])]
ans = 0
for i in points:
    x = i[0]
    y = i[1]
    d = math.sqrt(x**2 + y**2)
    if d <= distance:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
distance = n[1]
points = [list(map(int, input().split())) for i in range(n[0])]
ans = 0
for i in points:
    x = i[0]
    y = i[1]
    d = math.sqrt(x**2 + y**2)
    if d <= distance:
        ans += 1
print(ans)

Fixed submission:
import math
n = list(map(int, input().split()))
distance = n[1]
points = [list(map(int, input().split())) for i in range(n[0])]
ans = 0
for i in points:
    x = i[0]
    y = i[1]
    d = math.sqrt(x**2 + y**2)
    if d <= distance:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import os
import math
import itertools
import math
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
nums = [int(i) for i in input().split()]
gcds = []
for num in nums:
    tmp = nums.copy()
    tmp.remove(num)
    gcds.append(gcd(*tmp))
print(max(gcds))


Fixed submission:
a, b, t = map(int, input().split())
print(int((t+0.5)//a)*b)

Buggy python submission (verdict: Runtime Error):
import sys
import os
import math
import itertools
import math
import fraction
from functools import reduce

def gcd(*numbers):
    return reduce(fraction.gcd, numbers)

n = int(input())
nums = [int(i) for i in input().split()]
gcds = []
for num in nums:
    tmp = nums.copy()
    tmp.remove(num)
    gcds.append(gcd(*tmp))
print(max(gcds))


Fixed submission:
a, b, t = map(int, input().split())
print(int((t+0.5)//a)*b)
Buggy python submission (verdict: Runtime Error):
import math
# import sys
# import os
# f = open('input.txt', 'r')
# sys.stdin = f

n = int(input())
h = list(input().split())
h = [int(i) for i in h]
dp = [100000]*n
dp[0] = 0
dp[1] = h[1]-h[0]
for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1], dp[i-2] + abs(h[i]-h[i-2]))

print(dp[n-1])


Fixed submission:
import math
import sys
# import os
# f = open('input.txt', 'r')
# sys.stdin = f

n = int(input())
h = list(input().split())
h = [int(i) for i in h]
dp = [100000]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())

eva=False

pl=abs(B-A)
ve=V-W

if pl<=ve*T and 0<pl:
    if ve>0:
        eva=True
if eva:
    print("YES")
else:
    print("NO")

Fixed submission:
S=str(input())

print(S[:3])

Buggy python submission (verdict: Runtime Error):
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())

eva=False

pl=abs(B-A)
ve=V-W

if pl<=ve*T and 0<pl:
    if ve>0:
        #if pl%abs(ve)==0:
            eva=True
if eva:
    print("YES")
else:
    print("NO")

Fixed submission:
S=str(input())

print(S[:3])
Buggy python submission (verdict: Runtime Error):
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())

eva=False

pl=B-A
ve=V-W

if pl<=ve*T:
    if pl%ve==0:
        eva=True
if eva:
    print("YES")
else:
    print("NO")


Fixed submission:
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())

eva=False

pl=abs(B-A)
ve=V-W

if pl<=ve*T:
    if ve>0:
        eva=True
if eva:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(x) for x in input().split()]
ans=1
for i in range(0,N):
    ans=ans*A[i]
if ans>1000000000000000000:
    ans=-1
print(ans)


Fixed submission:
N=int(input())
A=[int(x) for x in input().split()]
ans=1
if 0 in A:
    ans=0
else:
    for i in range(0,N):
        ans=ans*A[i]
        if ans>1000000000000000000:
            ans=-1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
score=0
for i in range(0,len(s)/2+1):
  if s[i]!=s[len(s)-i]:
    score+=1
    
print(score)

Fixed submission:
s=input()
score=0

for i in range(0,int(len(s)/2)):
    if s[i]!=s[len(s)-1-i]:
        score+=1

print(score)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l_a = list(map(int, input().split()))
many = []
for i in range(1, 100001) :
    many.append(l_a.count(i))
bef = sum(l_a)
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    bef += (c - b)*many[b - 1]
    ans.append(bef)
    many[c - 1] += many[b - 1]
    many[b - 1] = 0

for value in ans :
    print(value)


Fixed submission:
import collections

n = int(input())
l_a = list(map(int, input().split()))
col = collections.Counter(l_a)
bef = sum(l_a)
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    bef += (c - b)*col[b]
    ans.append(bef)
    col[c] += col[b]
    col[b] = 0

for value in ans :
    print(value)

Buggy python submission (verdict: Time Limit Exceeded):
def numsum(a) :
    ans = 0
    for i in range(len(a)) :
        ans += (i + 1) * a[i]
    return ans

n = int(input())
l_a = list(map(int, input().split()))
many = []
for i in range(1, 100001) :
    many.append(l_a.count(i))
bef = numsum(many)
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    bef += (c - b)*many[b - 1]
    ans.append(bef)
    many[c - 1] += many[b - 1]
    many[b - 1] = 0

for value in ans :
    print(value)


Fixed submission:
import collections

n = int(input())
l_a = list(map(int, input().split()))
col = collections.Counter(l_a)
bef = sum(l_a)
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    bef += (c - b)*col[b]
    ans.append(bef)
    col[c] += col[b]
    col[b] = 0

for value in ans :
    print(value)

Buggy python submission (verdict: Time Limit Exceeded):
def numsum(a) :
    ans = 0
    for i in range(len(a)) :
        ans += (i + 1) * a[i]
    return ans

n = int(input())
l_a = list(map(int, input().split()))
many = []
for i in range(1, 100001) :
    many.append(l_a.count(i))
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    many[c - 1] += many[b - 1]
    many[b - 1] = 0
    ans.append(numsum(many))

for value in ans :
    print(value)


Fixed submission:
import collections

n = int(input())
l_a = list(map(int, input().split()))
col = collections.Counter(l_a)
bef = sum(l_a)
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    bef += (c - b)*col[b]
    ans.append(bef)
    col[c] += col[b]
    col[b] = 0

for value in ans :
    print(value)

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

for value in ans :
    print(value)


Fixed submission:
import collections

n = int(input())
l_a = list(map(int, input().split()))
col = collections.Counter(l_a)
bef = sum(l_a)
q = int(input())
ans = []
for _ in range(q) :
    b, c = map(int, input().split())
    bef += (c - b)*col[b]
    ans.append(bef)
    col[c] += col[b]
    col[b] = 0

for value in ans :
    print(value)