human
Array sum after replacing all occurrences of X by Y for Q queries | Function that print the sum of the array for Q queries.
Stores the frequencies of array elements.
Calculate the sum of the initial array and store the frequency of each element in map.
Iterate for all the queries.
Store query values.
Decrement the sum accordingly.
Increment the sum accordingly.
Set count of Y [ i ].
Reset count of X [ i ].
Print the sum.
Driver Code.
Function call"
Solution in Python:

Can you provide a code to array sum after replacing all occurrences of X by Y for Q queries and the other steps required?
assistant
#Here is code to array sum after replacing all occurrences of X by Y for Q queries and the other steps required.
 def sumOfTheArrayForQuery ( A , N , X , Y , Q ) :
	sum = 0
	count = { }
	for i in range ( N ) :
		sum += A [ i ]
		if A [ i ] in count :
			count [ A [ i ] ] += 1
		else :
			count [ A [ i ] ] = 1
	for i in range ( Q ) :
		x = X [ i ]
		y = Y [ i ]
		if X [ i ] not in count :
			count [ X [ i ] ] = 0
		if Y [ i ] not in count :
			count [ Y [ i ] ] = 0
		sum -= ( count [ X [ i ] ] * X [ i ] )
		sum += count [ X [ i ] ] * Y [ i ]
		count [ Y [ i ] ] += count [ X [ i ] ]
		count [ X [ i ] ] = 0
		print ( sum , end = " ▁ " )
arr = [ 1 , 2 , 1 , 3 , 2 , ]
X = [ 2 , 3 , 5 ]
Y = [ 3 , 1 , 2 ]
N = len ( arr )
Q = len ( X )
sumOfTheArrayForQuery ( arr , N , X , Y , Q )