human
Sum of maximum of all subarrays by adding even frequent maximum twice | Function to calculate sum of maximum of all subarrays.
Stores the sum of maximums.
Traverse the array.
Store the frequency of the maximum element in subarray.
Finding maximum.
Increment frequency by 1.
If new maximum is obtained.
If frequency of maximum is even , then add 2 * maxNumber . Otherwise , add maxNumber.
Print the sum obtained.
Driver Code.
Function Call"
How can the above be solved in Python?
 ... Give me a code to sum of maximum of all subarrays by adding even frequent maximum twice and the other steps required?
assistant
#Here is code to sum of maximum of all subarrays by adding even frequent maximum twice and the other steps required.
 def findSum ( a ) :
	ans = 0
	for low in range ( 0 , len ( a ) ) :
		for high in range ( low , len ( a ) ) :
		count = 0
		maxNumber = 0
		for i in range ( low , high + 1 ) :
			if ( a [ i ] == maxNumber ) :
			count += 1
			elif ( a [ i ] > maxNumber ) :
			maxNumber = a [ i ]
			count = 1
		if count % 2 :
			ans += maxNumber
		else :
			ans += maxNumber * 2
	print ( ans )
arr = [ 2 , 1 , 4 , 4 , 2 ]
findSum ( arr )