TnT/Multi_CodeNet4Repair huggingface dataset:
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().rstrip())
As = {}
answer = 0
for a in [int(x) for x in input().rstrip().split()]:
    answer += a
    if a in As.keys():
        As[a] += 1
    else:
        As[a] = 1
# print(As)
Q = int(input().rstrip())
d = {}
for i in range(Q):
    b, c = map(int, input().rstrip().split())
    d[i] = {'b': b, 'c': c}
# print(d)
for i in sorted(d.keys()):
    if d[i]['b'] in As.keys():
        diff = d[i]['c'] - d[i]['b']
        diff_num = As.pop(d[i]['b'])
        if d[i]['c'] in As.keys():
            As[d[i]['c']] += diff_num
        else:
            As[d[i]['c']] = diff_num
        answer += (diff * diff_num)
    print(answer)
print('---')




N = int(input().rstrip())
As = {}
answer = 0
for a in [int(x) for x in input().rstrip().split()]:
    answer += a
    if a in As.keys():
        As[a] += 1
    else:
        As[a] = 1
# print(As)
Q = int(input().rstrip())
d = {}
for i in range(Q):
    b, c = map(int, input().rstrip().split())
    d[i] = {'b': b, 'c': c}
# print(d)
for i in sorted(d.keys()):
    if d[i]['b'] in As.keys():
        diff = d[i]['c'] - d[i]['b']
        diff_num = As.pop(d[i]['b'])
        if d[i]['c'] in As.keys():
            As[d[i]['c']] += diff_num
        else:
            As[d[i]['c']] = diff_num
        answer += (diff * diff_num)
    print(answer)


Verdicts: Wrong Answer

Accepted
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 = input()
arr = [int(x) for x in input().split()]

q = int(input())
ans = sum(arr)

hashmap = {}
for val in arr:
    if val in hashmap:
        hashmap[val] += 1
    else:
        hashmap[val] = 1


while q > 0:
    print(hashmap)
    [x, y] =  [int(x) for x in input().split()]
    if x in hashmap:
        if y in hashmap:
            hashmap[y] += hashmap[x]
            ans -= hashmap[x]*x
            ans += y*hashmap[x]
        else:
            diff = hashmap[x] * x
            ans -= diff
            hashmap[y] = hashmap[x]
            del hashmap[x]
            add = hashmap[y] * y
            ans += add
        
    print(ans)
    q -=1

N = input()
arr = [int(x) for x in input().split()]

q = int(input())
ans = sum(arr)

hashmap = {}
for val in arr:
    if val in hashmap:
        hashmap[val] += 1
    else:
        hashmap[val] = 1


while q > 0:
    print(hashmap)
    [x, y] =  [int(x) for x in input().split()]
    if x in hashmap:
        if y in hashmap:
            hashmap[y] += hashmap[x]
            ans -= hashmap[x]*x
            ans += y*hashmap[x]
        else:
            diff = hashmap[x] * x
            ans -= diff
            hashmap[y] = hashmap[x]
            del hashmap[x]
            add = hashmap[y] * y
            ans += add
        
    print('ans', ans)
    q -=1

N = input()
arr = [int(x) for x in input().split()]

q = int(input())
ans = sum(arr)

hashmap = {}
for val in arr:
    if val in hashmap:
        hashmap[val] += 1
    else:
        hashmap[val] = 1


while q > 0:

    [x, y] =  [int(x) for x in input().split()]
    if x in hashmap:
        if y in hashmap:
            hashmap[y] += hashmap[x]
            ans -= hashmap[x]*x
            ans += y*hashmap[x]
            del hashmap[x]
        else:
            diff = hashmap[x] * x
            ans -= diff
            hashmap[y] = hashmap[x]
            del hashmap[x]
            add = hashmap[y] * y
            ans += add
        
    print(ans)
    q -=1

Verdicts: Runtime Error

Wrong Answer

Accepted
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):
from collections import defaultdict

N = int(input())
_A = [*map(int, input().split())]
Q = int(input())
val = [[*map(int, line.split())] for line in open(0)]

A = defaultdict(int)
for _a in _A:
    A[_a] += 1

ans = sum(_A)
for v in val:
    if v[0] in A.keys():
        num = A[v[0]]
        A[v[0]] = 0
        A[v[1]] += num
        ans += (v[1] - v[0]) * num
    print(ans)


from collections import defaultdict

N, _A, Q, *val = [[*map(int, line.split())] for line in open(0)]
N = N[0]
Q = Q[0]

A = defaultdict(int)
for _a in _A:
    A[_a] += 1

ans = sum(_A)
for v in val:
    if v[0] in A.keys():
        num = A[v[0]]
        A[v[0]] = 0
        A[v[1]] += num
        ans += (v[1] - v[0]) * num
    print(ans)


Verdicts: Runtime Error

Accepted
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(map(int, input().split()))
q = int(input())
bc =[list(map(int, input().split())) for _ in range(q)]
temp = [0] * (10**5 + 1)

for i in a:
    temp[i] += 1
ans = sum(a)
for i in range(q):
    b,c = bc[i][0],bc[i][1]
    ans = ans - temp[b] * b + temp[b] * c 
    print(sum(temp))
    temp[c] += tremp[b]


  
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc =[list(map(int, input().split())) for _ in range(q)]
    temp = [0] * (10**5 + 1)
    
    for i in a:
        temp[i] += 1
    ans = sum(a)
    for i in range(q):
        b,c = bc[i][0],bc[i][1]
        ans = ans - temp[b] * b + temp[b] * c 
        print(ans)
        temp[c] += temp[b]
        temp[b] = 0
if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Accepted
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(map(int,input().split()))
q=int(input())

b=[]
c=[]
for i in range(q):
    d,e=input().split()
    b.append(int(d))
    c.append(int(e))

for i in range(q):
    for j in range(len(b)):
        if a[i] == b[j]:
            a[i]=c[j]
            # if a[-1] ==b[j]:
            #     a[-1]=c[i]
print(sum(a))
    # print(a)
# print(a)
# print(b)
# print(c)

n=int(input())
a=list(map(int,input().split()))

L=[0]*(100001)
s=sum(a)

for i in a:
    L[i] +=1

q= int(input())
for _ in range(q):
    b, c = map(int,input().split())
    L[c] += L[b]
    s+= L[b]*(c-b)
    L[b]=0
    print(s)
# b=[]
# c=[]

#     d,e=input().split()
#     b.append(int(d))
#     c.append(int(e))



#     for j in range(q):


#                 if a[j]==b[i]:
#                     a[j]=c[i]
# else:

#         for j in range(q):
#             if a[i] == b[j]:
#                 a[i]=c[j]

#         #     if a[i] == b[i]:
#         #         a[i]=c[j]
#         #         if a[-1] ==b[j]:
#         #             a[-1]=c[i]
#         print(sum(a))



# # print(a)
# # print(a)
# # print(b)
# # print(c)

Verdicts: Runtime Error

Accepted
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):
import numpy as np
import sys
import bisect

readline = sys.stdin.readline


N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]


for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    
    # b = np.copy(A)

    # print(sum(A))
    print(A)



import numpy as np
import sys
import bisect

readline = sys.stdin.readline


N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]


for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    
    # b = np.copy(A)

    print(sum(A))



import numpy as np
import sys

readline = sys.stdin.readline

N = int(input())
A = np.array(readline().split(), np.int64)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

print(N)

"""
for q in range(Q):
    A = [BC[q][1] if x==BC[q][0] else x for x in A]
    print(sum(A))
    """

import numpy as np
import sys
import bisect

readline = sys.stdin.readline


N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]


for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    
    # b = np.copy(A)

    # print(sum(A))
    print(N)



import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline


N = int(input())
A = np.array(readline().split(), np.int64)
num_array = np.zeros(10**5, np.int64)
for n in A:
    num_array[n-1] += 1

# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]


for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    
    

    

    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = num_array[BC[q][0] - 1]
    
    num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]
    num_array[BC[q][0] - 1] = 0

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)



Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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())
l = list(map(int, input()))
q = int(input())
count = 0

for i in range(q):
	count = 0
	b, c = map(int, input().split())
	for a in l:
		if a == b:
			l[count] = c
		print(sum(l))
		count++


import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

num = collections.Counter(A)

S = sum(A)
slist = []

for i in range(Q):
	B, C = map(int, input().split())
	numb = num[B]
	S += (C - B) * numb
	num[C] += numb
	num[B] = 0
	slist.append(S)

[print(i) for i in slist]

Verdicts: Runtime Error

Accepted
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):
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())
#print(A)
D=[0]*10**5;W=[0]*10**5
for i in range(10**5):
  D[i]=A.count(i+1)
  W[i]=i+1

for i in range(Q):
    D[C[i]-1]+=D[B[i]-1]
    D[B[i]-1]=0
    print(int(np.average(D, weights=W)*10**5*(10**5+1)//2))

import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

D = collections.Counter(A)
s=sum(A)
for i in range(Q):
  s=s-B[i]*D[B[i]]
  D[C[i]]+=D[B[i]]
  s=s+C[i]*D[B[i]]
  D[B[i]]=0
  print(s)

Verdicts: Wrong Answer

Accepted
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):
import numpy as np

N=int(input())
A=list(map(int, input().split()))
Q=int(input())
B,C=map(int, input().split())
rep=[i for i, x in enumerate(A) if x == B]
for i in range(len(rep)):
    A[rep[i]]=C
ans=np.cumsum(A)
print(ans[1])

for _ in range(Q-1):
    B,C=map(int, input().split())
    rep=[i for i, x in enumerate(A) if x == B]
    for i in range(len(rep)):
        A[rep[i]]=C
    ans+=(C-B)*len(rep)
    print(ans[1])

mod=pow(10,5)+2
N=int(input())
num=[0]*mod
ans=0
A=list(map(int, input().split()))
for i in range(N):
    num[A[i]]+=1
    ans+=A[i]
Q=int(input())
for i in range(Q):
    B,C=map(int, input().split())
    cnt=num[B]
    num[C]+=num[B]
    num[B]=0
    ans+=(C-B)*cnt
    print(ans)

Verdicts: Runtime Error

Accepted
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):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    C = Counter(A)
    ANS = 0
    for i in C:
        ANS += i * C[i]

    for _ in range(Q):
        B, X = map(int, input().split())
        ANS += X * C[B]
        C[X] += C[B]

        ANS -= B * C[B]
        del(C[B])
        print(ANS)

resolve()

from collections import Counter


def resolve():
    N = int(input())
    A = list(input().split())
    Q = int(input())

    C = Counter(A)
    ANS = 0
    for i in C:
        ANS += i * C[i]

    for _ in range(Q):
        B, X = map(int, input().split())
        ANS += X * C[B]
        C[X] += C[B]

        ANS -= B * C[B]
        del(C[B])
        print(ANS)

resolve()

from collections import Counter


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    C = Counter(A)
    ANS = 0
    for i in C:
        ANS += i * C[i]

    for _ in range(Q):
        B, X = map(int, input().split())
        ANS += X * C[B]
        C[X] += C[B]

        ANS -= B * C[B]
        del(C[B])
        print(ANS)

resolve()

Verdicts: Runtime Error

Runtime Error

Accepted
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 = input()
#print(a)
q = int(input())

b = []
for _ in range(q):
    b.append(input().split())
#print(b)
for i in range(q):
    a.replace(b[i][0],b[i][1],100000)
    c = 0
    d = a.split(" ")
    #print(d)
    for j in range(len(d)):
        c += int(d[j])
    print(c)


n = int(input())

a = list(map(int,input().split()))
#print(a)
q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1
x = sum(a)
b = []
for _ in range(q):
    b.append(list(map(int,input().split())))
#print(b)


for i in range(q):
    x += (b[i][1] - b[i][0]) * z[b[i][0]]
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    print(x)

Verdicts: Wrong Answer

Accepted
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 = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10 ** 5)+1)]

for i in a_list:
    ary[i] += i


for _ in range(q):
    b, c = map(int, input().split())
    print('BC', b, c)
    ary[c] += (ary[b]/b)*c
    ary[b] = 0
    ans = int(sum(ary))
    print(ans)


n = int(input())

a_list = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10**5) + 1)]

for i in a_list:
    ary[i] += 1

ans = []

f_ans = sum(a_list)
for _ in range(q):
    b, c = map(int, input().split())
    f_ans += (c-b)*ary[b]
    ary[c] += ary[b]
    ary[b] = 0

    ans.append(f_ans)

for a in ans:
    print(a)


Verdicts: Wrong Answer

Accepted
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):
K = int(input())
S = len(input())

M = 10**9 + 7

F = [1]
IF = [1]
for i in range(1, K + S + 1):
    F.append((F[-1] * i) % M)
    IF.append((IF[-1] * pow(i, M - 2, M)) % M)

def nCr(n, r):
    return (F[n] * IF[r] * IF[n-r]) % M

ans = 0
for i in range(K + 1):
    ans = (ans + nCr(i + S - 1, S - 1) * pow(25, i, M) * pow(26, K - i, M)) % M
print(ans)


N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (100001)
ans = sum(A)
for a in A:
    cnt[a] += 1
Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    ans += (c - b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(ans)


Verdicts: Wrong Answer

Accepted
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):
A=[0]*(10**5+1)
for i in a:
	A[i]+=1

for bc in BC:
	diff= bc[1]-bc[0]
	SUM+=diff*A[bc[0]]
	A[bc[1]]+=A[bc[0]]
	A[bc[0]]-=A[bc[0]]
	print(SUM)


def input_array():
	return list(map(int,input().split()))

n=int(input())
a=input_array()
q=int(input())
BC=[input_array() for _ in range(q)]
SUM=sum(a)

A=[0]*(10**5+1)
for i in a:
	A[i]+=1

for bc in BC:
	diff= bc[1]-bc[0]
	SUM+=diff*A[bc[0]]
	A[bc[1]]+=A[bc[0]]
	A[bc[0]]-=A[bc[0]]
	print(SUM)

Verdicts: Runtime Error

Accepted
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(map(int, input().split()))
Q = int(input())

a = [0] * (10 ** 5 + 1)
ans = sum(A)

for i in range(N):
    a[A[i]] += 1

for i in range(Q):
    B, C = map(int, input().split())
    a[C] += a[B]
    a[B] = 0
    ans += a[B] * (C - B)
    print(ans)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())

a = [0] * (10 ** 5 + 1)
ans = sum(A)

for i in range(N):
    a[A[i]] += 1

for i in range(Q):
    B, C = map(int, input().split())
    ans += a[B] * (C - B)
    a[C] += a[B]
    a[B] = 0
    print(ans)


Verdicts: Wrong Answer

Accepted
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):
import numpy as np

N=int(input())
A=list(map(int,input().split()))
Adic={}
for i in A:
  if Adic.get(i)==None:
    Adic[i]=1
  else:
    Adic[i]+=1
Q=int(input())
ope=[]

for i in range(Q):
  ope.append(list(map(int,input().split())))

A=np.array(A)

sum=0
for key,value in Adic.items():
  sum+=key*value
for b,c in ope:
  if Adic.get(b)!=None:
    if Adic.get(c)==None:Adic[c]=0
    sum-=b*Adic[b]
    Adic[c]+=Adic.pop(b)
    sum+=c*Adic[c]
    print(sum)
  else:
    print(sum)

import numpy as np

N=int(input())
A=list(map(int,input().split()))
Adic={}
for i in A:
  if Adic.get(i)==None:
    Adic[i]=1
  else:
    Adic[i]+=1
Q=int(input())
ope=[]

for i in range(Q):
  ope.append(list(map(int,input().split())))

A=np.array(A)

sum=0
for key,value in Adic.items():
  sum+=key*value
for b,c in ope:
  if Adic.get(b)!=None:
    if Adic.get(c)==None:Adic[c]=0
    sum=sum-b*Adic[b]+c*Adic[b]
    Adic[c]+=Adic.pop(b)
    print(sum)
  else:
    print(sum)

Verdicts: Wrong Answer

Accepted
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):
#D                 more faster method than above               see it ..........
l = lambda : list(map(int,input().split().strip()))
n = int(input())
a = l
t = [0]*(10**5+1)
s = 0
for i in a:
    s += i
    t[i] += 1
q = int(input())
for _ in range(q):
    b,c = l
    s += (c-b)*t[b]
    t[c] += t[b]
    t[b] = 0
    print(s)


#D
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
mp = defaultdict(int)
for i in a:
    mp[i] += 1
q = int(input())
for _ in range(q):
    print(mp)
    s = 0   
    b,c=map(int,input().split())
    if c in mp:
        mp[c] = mp[c]+mp[b]
        mp.pop(b)
    elif b in mp:
        mp[c] = mp.pop(b)
        
    for i in mp:
        s += (mp[i])*i
    print(s)
    

#D                 more faster method than above               see it ..........
l = lambda : list(map(int,input().strip().split()))
n = int(input())
a = l()
t = [0]*(10**5+1)
s = 0
for i in a:
    s += i
    t[i] += 1
q = int(input())
for _ in range(q):
    b,c = l()
    s += (c-b)*t[b]
    t[c] += t[b]
    t[b] = 0
    print(s)


Verdicts: Runtime Error

Wrong Answer

Accepted
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(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    for i in range(N):
        if A[i] == B:
            A[i] = C
            print(sum(A))


from collections import Counter
 
n = int(input())
a = list(map(int, input().split()))
q = int(input())
 
cnt = Counter(a)
 
s = sum(a)
 
for i in range(q):
	b, c = map(int, input().split())
	s = s - b*cnt[b]
	s = s + c*cnt[b]
	cnt[c] += cnt[b]
	cnt[b] = 0
	print(s)

Verdicts: Wrong Answer

Accepted
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(map(int,input().split()))
Q = int(input())
B=[]
C=[]

for _ in range(q):
    bi, ci = list(map(int, input().split()))
    B.append(bi)
    C.append(ci)

dic = {}
for i in A:
    dic[i] = dic.get(i,0) + 1

sum = sum(A)

for i in range(Q):
    sum += dic[B[i]] * (C[i] -B[i])
    dic[C[i]] += dic[B[i]]
    dic[B[i]] = 0
    print(sum)

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B=[]
C=[]

for _ in range(Q):
    bi, ci = list(map(int, input().split()))
    B.append(bi)
    C.append(ci)

dic = {}
for i in A:
    dic[i] = dic.get(i,0) + 1

sum = sum(A)

for i in range(Q):
    sum += dic.get(B[i], 0) * (C[i] -B[i])
    dic[C[i]] = dic.get(C[i], 0) + dic.get(B[i], 0)
    dic[B[i]] = dic.get(B[i], 0)
    dic[B[i]] = 0
    print(sum)

Verdicts: Runtime Error

Accepted
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(map(int,input().split()))
q=int(input())
temp=sum(a)
import collections
ca=collections.Counter(a)
print(ca)
for i in range(q):
  b,c=map(int,input().split())
  ba=ca[b]
  temp=temp-b*ba+c*ba
  ca[b]=ca[b]-ba
  ca[c]=ca[c]+ba


n=int(input())
a=list(map(int,input().split()))
q=int(input())
temp=sum(a)
import collections
ca=collections.Counter(a)
for i in range(q):
  b,c=map(int,input().split())
  ba=ca[b]
  temp=temp-b*ba+c*ba
  print(temp)
  ca[b]=ca[b]-ba
  ca[c]=ca[c]+ba


Verdicts: Wrong Answer

Accepted
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):
import collections

def calc_sum(c):
    sum_val = 0
    for key, val in c.items():
        sum_val += key * val
    return sum_val

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())

actions = []

for i in range(Q):
    B, C = map(int, input().split())
    actions.append({'B':B, 'C':C})

c = collections.Counter(arr)
sum_val = calc_sum(c)

for i in range(Q):
    B = actions[i]['B']
    C = actions[i]['C']
    if B in c:
        c[C] += c[B]
        sum_val += c[C] * C - c[B] * B
        c.pop(B)

    print(sum_val)

import collections

def calc_sum(c):
    sum_val = 0
    for key, val in c.items():
        sum_val += key * val
    return sum_val

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())

actions = []

for i in range(Q):
    B, C = map(int, input().split())
    actions.append({'B':B, 'C':C})

c = collections.Counter(arr)
sum_val = calc_sum(c)

for i in range(Q):
    B = actions[i]['B']
    C = actions[i]['C']
    if B in c:
        c[C] += c[B]
        sum_val += c[B] * C - c[B] * B
        c.pop(B)

    print(sum_val)

Verdicts: Wrong Answer

Accepted
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):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]

    d = dict()
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1

    total = sum(A)
    ans = []
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        if b in d:
            if c in d:
                d[c] += d[b]
            else:
                d[c] = d[b]

            total += (c - b) * d[b]
            ans.append(total)
            d.pop(b)

        else:
            ans.append(total)

        print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]

    d = dict()
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1

    total = sum(A)
    ans = []
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        if b in d:
            if c in d:
                d[c] += d[b]
            else:
                d[c] = d[b]

            total += (c - b) * d[b]
            ans.append(total)
            d.pop(b)

        else:
            ans.append(total)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
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(map(int, input().split()))
q = int(input())

l = {}
ans = []
for e in a:
    l[e] = l[e] + 1 if l.get(e) else 1

sum = 0
for k, v in l.items():
    sum += k * v

for _ in range(q):
    b, c = map(int, input().split())
    if b in l:
        sum += (c - b) * l[b]
    ans.append(sum)

for sum in ans:
    print(sum)

n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)


Verdicts: Wrong Answer

Accepted
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(map(int, input().split()))
Q = int(input())
B = []
C = []
 
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
 
S = sum(A)
memory = [0] * 100001
for num in A:
    memory[num] += 1
for i in range(Q):
  S = S + memory[B[i]] * (C[i]- B[i])
  memory[C[i]] = memory[B[i]]
  memory[B[i]] = 0
  print(S)
 

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
 
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
 
S = sum(A)
memory = [0] * 100001
for num in A:
    memory[num] += 1
for i in range(Q):
  S = S + memory[B[i]] * (C[i]- B[i])
  print(S)
  memory[C[i]] += memory[B[i]]
  memory[B[i]] = 0
  
 

Verdicts: Wrong Answer

Accepted
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(map(int,input()))
q = int(input())
for i in range(q):
  summ = 0
  b,c = map(int,input().split())
  for i in range(N):
    if(a[i]==b):
      a[i] = c
    summ += a[i]
  print(summ)


N = int(input())
a = list(map(int,input().split()))
q = int(input())
num = []
summ = 0
for i in range(10**5):
  num.append(0)
for i in range(N):
  num[a[i]-1] += 1
  summ += 1
for i in range(q):
  b,c = map(int,input().split())
  summ += (c-b)*a[b-1]
  a[c-1] += a[b-1]
  a[b-1] = 0
  print(summ)


N = int(input())
a = list(map(int,input().split()))
q = int(input())
num = []
summ = 0
for i in range(10**5):
  num.append(0)
for i in range(N):
  num[a[i]-1] += 1
  summ += a[i]
for i in range(q):
  b,c = map(int,input().split())
  summ += (c-b)*a[b-1]
  a[c-1] += a[b-1]
  a[b-1] = 0
  print(summ)


N = int(input())
a = list(map(int,input().split()))
q = int(input())
num = []
summ = 0
for i in range(10**5):
  num.append(0)
for i in range(N):
  num[a[i]-1] += 1
  summ += a[i]
for i in range(q):
  b,c = map(int,input().split())
  summ += (c-b)*num[b-1]
  num[c-1] += num[b-1]
  num[b-1] = 0
  print(summ)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
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):
import sys
import numpy as np
import math  
import collections
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate 
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache 

def main():
    n = int(sys.stdin.readline())
    a = list(map(int,sys.stdin.readline().split()))
    q = int(sys.stdin.readline())
    queue = [list(map(int,sys.stdin.readline().split())) for _ in range(q)]
    count = collections.Counter(a)
    print(count)
    print(list(count))
    for b, c in queue:
        if  b in count:
            if c in count:
                count[c] += count[b]
                del count[b]
            else:
                count[c] = count[b]
                del count[b]
        ans = 0
        for k in count:
            ans += k * count[k]
        print(ans) 
    
    
    return 0

if __name__ == "__main__":
    main()

import sys
import numpy as np
import math  
import collections
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate 
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache 

def main():
    n = int(sys.stdin.readline())
    a = list(map(int,sys.stdin.readline().split()))
    q = int(sys.stdin.readline())
    queue = [list(map(int,sys.stdin.readline().split())) for _ in range(q)]
    count = collections.Counter(a)
    #print(count)
    #print(list(count))
    ans = 0
    for k in count:
        ans += k * count[k]
    for b, c in queue:
        if  b in count:
            if c in count:
                count[c] += count[b]
                ans += (c - b) * count[b]
                del count[b]
            else:
                count[c] = count[b]
                ans += (c - b) * count[b]

                del count[b]
        print(ans)
    
    
    return 0

if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
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(map(int,input().split()))
Q=int(input())

base=sum(A)

from collections import Counter

ad=Counter(A)

for _ in range(Q):
    b,c=map(int.input().split())
    if ad[b]!=0:
        base+=(c-b)*ad[b]
        ad[c]+=ad[b]
        ad[b]=0
    print(base)

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = sum(A)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    if c not in C.keys():
        C[c] = 0
    if b in C.keys():
        ans += (c-b)*C[b]
        C[c] += C[b]
        C[b] = 0
    print(ans)
    

Verdicts: Runtime Error

Accepted
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):
def main():
  n = int(input())
  a = list(map(int,input().split()))
  q = int(input())
  for _ in range(q):
    b, c = map(int, input().split())
    sum=0
    for i in range(0,n):
      if(a[i]==b):
        a[i]=c
        sum+=a[i]
    print(sum)
main()

import collections
def main():
  n = int(input())
  a = list(map(int,input().split()))
  ans=sum(a)
  counter = collections.Counter(a)
  q = int(input())
  for _ in range(q):
    b, c = map(int, input().split())
    num=counter[b]
    counter[b]=0
    counter[c]+=num
    ans+=(c-b)*num
    print(ans)
main()

Verdicts: Wrong Answer

Accepted
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(map(int, input().split()))
q = int(input())
d = dict()
s = 0
for num in a:
  if num in d:
    d[num] += 1
  else:
    d[num] = 1
  s += num
for i in range(q):
  B, C = list(map(int, input().split()))
  if B in d:
    if C in d:
      d[C] += d[B]
    else:
      d[C] = d[B]
    s += (C-B)*d[B]
    s[B] = 0
  print(s)

n = int(input())
a = input().split()
q = int(input())
d = dict()
s = 0
for num in a:
  if num in d:
    d[num] += 1
  else:
    d[num] = 1
  s += int(num)
for i in range(q):
  B, C = input().split()
  if B in d:
    if C in d:
      d[C] += d[B]
    else:
      d[C] = d[B]
    s += (int(C)-int(B))*d[B]
    d[B] = 0
  print(s)


Verdicts: Runtime Error

Accepted
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):
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
c=Counter(A)
commons=c.most_common()

ans=0

dic={}
for common in commons:
    dic[common[0]]=common[1]
    ans+=common[0]*common[1]
# print(dic)
# print(ans)

Q=int(input())
for i in range(Q):
    b,c=map(int,input().split())
    ans+=(c-b)*dic[b]
    dic[b]=0
    dic[c]+=dic[b]
    # print(dic)
    print(ans)


from collections import Counter

N=int(input())
A=list(map(int,input().split()))
c=Counter(A)
commons=c.most_common()

ans=0

dic={}
for common in commons:
    dic[common[0]]=common[1]
    ans+=common[0]*common[1]
# print(dic)
# print(ans)

Q=int(input())
for i in range(Q):
    b,c=map(int,input().split())
    if b not in dic:
        print(ans)
        continue
    else:
        pass
    if c not in dic:
        ans+=(c-b)*dic[b]
        print(ans)
        dic[c]=dic[b]
        dic[b]=0
        continue
    else:
        pass
    ans+=(c-b)*dic[b]
    dic[c]+=dic[b]
    dic[b]=0
    print(ans)


Verdicts: Runtime Error

Accepted
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):
from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
S = sum(A)

Q = int(input())
for _ in range(Q):
    x, y = map(int, input().split())
    S += (c[x]*(y-x))
    print(S)
    c[y] = c[x]
    c[x] = 0

from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
S = sum(A)

Q = int(input())
for _ in range(Q):
    x, y = map(int, input().split())
    S += (c[x]*(y-x))
    print(S)

from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
S = sum(A)

Q = int(input())
for _ in range(Q):
    x, y = map(int, input().split())
    S += (c[x]*(y-x))
    print(S)
    c[y] += c[x]
    c[x] = 0

Verdicts: Wrong Answer

Wrong Answer

Accepted
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())
arr=[int(i) for i in input().strip().split(" ")]
t=int(input())
dic={}
sum_array=0
for i in arr:
    dic[i]=dic.get(i,0)+1
    sum_array+=i
    

for _ in range(t):
    a,b=[int(i) for i in input().split(" ")]
    if b in dic:
        dic[b]+=dic[a]
    else:
        dic[b]=dic[a]
    
    sum_array+=dic[a]*(b-a)
    print(dic,sum_array)
    dic[a]=0

n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
t=int(input())
dic={}
sum_array=0
for i in arr:
    dic[i]=dic.get(i,0)+1
    sum_array+=i
    

for _ in range(t):
    a,b=[int(i) for i in input().split(" ")]
    if a not in dic:
        print(sum_array)
        continue
    if b in dic:
        dic[b]+=dic[a]
    else:
        dic[b]=dic[a]
    
    sum_array+=dic[a]*(b-a)
    print(sum_array)
    dic[a]=0

Verdicts: Runtime Error

Accepted
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):
import sys

if __name__ == '__main__':
    n = int(sys.stdin.readline().rstrip())
    A = list(map(lambda x: int(x), sys.stdin.readline().split()))
    q = int(sys.stdin.readline().rstrip())
    B, C = [], []
    for i in range(q):
        b, c = list(map(lambda x: int(x), sys.stdin.readline().split()))
        B.append(b)
        C.append(c)

    for i in range(q):
        summ = 0
        for a in A:
            if a == B[i]:
                summ += C[i]
            else:
                summ += a
        print(summ)



import sys
import numpy as np

if __name__ == '__main__':
    n = int(sys.stdin.readline().rstrip())
    A = list(map(lambda x: int(x), sys.stdin.readline().split()))
    q = int(sys.stdin.readline().rstrip())
    dic = {}
    for a in A:
        dic[a] = dic.get(a, 0) + 1

    # keys = list(dic.keys())
    # values = list(dic.values())
    
    summ = sum([k*v for k, v in dic.items()])
    for i in range(q):
        b, c = list(map(lambda x: int(x), sys.stdin.readline().split()))

        diff = c*dic.get(b,0) - b*dic.get(b,0)
        dic[c] = dic.get(c, 0) + dic.get(b, 0)
        dic[b] = 0
        summ += diff
        print(summ)

Verdicts: Wrong Answer

Accepted
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):
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())

d = Counter(A)
total = sum(A)

for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    if d[b]:
        total += (c - b) * d[b]
        d[c] = d[b]
        d[b] = 0
    print(total)



from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())

d = Counter(A)
total = sum(A)

for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    if d[b]:
        total += (c - b) * d[b]
        d[c] = d[b] + (d[c] if d[c] else 0)
        d[b] = 0
    print(total)



Verdicts: Wrong Answer

Accepted
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 = [int(i) for i in input().split()]
q = int(input())

ans = sum(a)
numbers = [0]*(10**5+1)
for _ in range(q):
    b,c = [int(i) for i in input().split()]
    nb = numbers[b]
    ans += (c-b)*nb
    print(ans)
    numbers[b] = 0
    numbers[c] += nb    

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())

ans = sum(a)
numbers = [0]*(10**5+1)
for v in a:
    numbers[v] += 1

for _ in range(q):
    b,c = [int(i) for i in input().split()]
    nb = numbers[b]
    ans += (c-b)*nb
    print(ans)
    numbers[b] = 0
    numbers[c] += nb    

Verdicts: Wrong Answer

Accepted
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())
# w = list(map(int, input().split()))

a = list(map(int, input().split()))

q = int(input())
#p = list(map(int, input().split()))
#a = list(map(int, input().split()))

bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
a_count = collections.Counter(a)
a_list = dict(list(a_count.items()))
#print(a_list)
total = sum(a)
for b, c in bc:
    if b in a_list:
        total += (c-b)*a_list[b]
        num = a_list[b]
        a_list[b] = 0
        if c in a_list:
            a_list[c] += num
        else:
            a_list[c] = num
            
    print(total)


import collections
n = int(input())
# w = list(map(int, input().split()))

a = list(map(int, input().split()))

q = int(input())
#p = list(map(int, input().split()))
#a = list(map(int, input().split()))

bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
a_count = collections.Counter(a)
a_list = dict(list(a_count.items()))
#print(a_list)
total = sum(a)
for b, c in bc:
    if b in a_list:
        total += (c-b)*a_list[b]
        num = a_list[b]
        a_list[b] = 0
        if c in a_list:
            a_list[c] += num
        else:
            a_list[c] = num
            
    print(total)


Verdicts: Runtime Error

Accepted
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):
import math

n = int(input())
a = [0]*10**7
x = math.sqrt(10)
b = math.floor(x)
l = 0
for i in range(1,n+1):
  x = math.sqrt(i)
  b = math.floor(x)
  for j in range(1,b+1):
    if(i%j==0 and i//j == j):
      a[i-1] +=1
    elif(i%j==0):
      a[i-1] +=2
for k in range(n):
  l = l + a[k]*(k+1)
print(l)
 


n = int(input())
a = list(map(int, input().split()))
q = int(input())
r = [0]*(10**5+10)
for i in range(n):
  r[a[i]] +=1
b = [0]*q
c = [0]*q
for i in range(q):
  b[i],c[i] = map(int,input().split())
s = 0
for m in range(n):
  s += a[m] 
for ii in range(q):
  s = s + (c[ii]-b[ii])*r[b[ii]]
  r[c[ii]] +=r[b[ii]]
  r[b[ii]]=0
  print(s)

Verdicts: Wrong Answer

Accepted