Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[x]+=cnt[y]
 cnt[y]=0
 print(sum)

n=int(input())
s=[]
s=input().split()
q=int(input())
for i in range(q):
 x,y=map(int,input().split())
 s=re.sub(x,y,s)

for j in range(q)
 ans+=int(s[j])

print(ans)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

for j in range(q):
 x,y=map(int,input().split())
 ans=-(x-y)*cnt[x]+sum
 print(ans)
 cnt[x]+=cnt[y]
 cnt[y]=0

n=int(input())
s=str(input())
q=int(input())
 
for i in range(q):
 x,y=map(str, input().split())
 s.replace(x,y)
 ans=0 
 s_list=list(s.split())
 for j in range(q+1):
  ans+=int(s_list[j])
  print(ans)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[x]+=cnt[y]
 cnt[y]=0
 print(sum)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

for j in range(q):
 x,y=map(int,input().split())
 ans=-(x-y)*cnt[x]+sum
 cnt[x]+=cnt[y]
 print(ans)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(x-y)*cnt[x]
 print(sum)
 cnt[x]+=cnt[y]
 cnt[y]=0

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

for j in range(q):
 x,y=map(int,input().split())
 ans=-(x-y)*cnt[x]+sum
 print(ans)

import re
n=int(input())
s=str(input())
q=int(input())
 
for i in range(q):
 x,y=map(str, input().split())
 s=re.sub(x,y,s)
 print(s)
 ans=0 
 s_list=list(s.split())
 for j in range(q+1):
  ans+=int(s_list[j])
 print(ans)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(x-y)*cnt[x]
 print(ans)
 cnt[x]+=cnt[y]

n=int(input())
s=[]
s=input().split()
q=int(input())
for i in range(q):
 x,y=map(int,input().split())
 s=re.sub(x,y,s)
 
for j in range(q):
 ans+=int(s[j])
 
print(ans)

n=int(input())
s=str(input())
q=int(input())
 
for i in range(q):
 x,y=map(str, input().split())
 s.replace(x,y)
ans=0 
s_list=list(s.split())
for j in range(q):
 ans+=int(s_list[j])
 
print(ans)

import re
n=int(input())
s=[]
s=input().split()
q=int(input())

for i in range(q):
 x,y=map(str, input().split())
 s=re.sub(str(x),str(y),str(s))
 
for j in range(q):
 ans+=int(s[j])
 
print(ans)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[y]+=cnt[x]
 cnt[y]=0
 print(sum)

n=int(input())
s=str(input())
q=int(input())
 
for i in range(q):
 x,y=map(str, input().split())
 s.replace(x,y)
ans=0 
s_list=list(s.split())
for j in range(q+1):
 ans+=int(s_list[j])
 
print(ans)

n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[y]+=cnt[x]
 cnt[x]=0
 print(sum)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted