human
Sum of even values and update queries on an array | Function to print the result for every query.
If current element is even.
If element is even then remove it from sum.
If the value becomes even after updating.
Store sum for each query.
Print the result for every query.
Driver code"
Solution in Python:
 ... Write me a code to sum of even values and update queries on an array and the other steps required?
assistant
#Here is code to sum of even values and update queries on an array and the other steps required.
 def BalanceArray ( A , Q ) :
	ANS = [ ]
	sum = 0
	for i in range ( len ( A ) ) :
		if ( A [ i ] % 2 == 0 ) :
			sum += A [ i ] ;
	for i in range ( len ( Q ) ) :
		index = Q [ i ] [ 0 ] ;
		value = Q [ i ] [ 1 ] ;
		if ( A [ index ] % 2 == 0 ) :
			sum -= A [ index ] ;
		A [ index ] += value ;
		if ( A [ index ] % 2 == 0 ) :
			sum += A [ index ] ;
		ANS . append ( sum ) ;
	for i in range ( len ( ANS ) ) :
		print ( ANS [ i ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
	A = [ 1 , 2 , 3 , 4 ] ;
	Q = [ [ 0 , 1 ] , [ 1 , - 3 ] , [ 0 , - 4 ] , [ 3 , 2 ] ] ;
	BalanceArray ( A , Q ) ;