human
Largest number in given Array formed by repeatedly combining two same elements | Function to return the largest sum.
Variable to store the largest sum.
Map to store the frequencies of each element.
Store the Frequencies.
Loop to combine duplicate elements and update the sum in the map.
If j is a duplicate element.
Update the frequency of 2 * j.
If the new sum is greater than maximum value , Update the maximum.
Returns the largest sum.
Driver Code.
Function Calling"
Solution in Python:

=====
Can you provide a code to largest number in given Array formed by repeatedly combining two same elements and the other steps required?
assistant
#Here is code to largest number in given Array formed by repeatedly combining two same elements and the other steps required.
 def largest_sum ( arr , n ) :
	maximum = - 1
	m = dict ( )
	for i in arr :
		m [ i ] = m . get ( i , 0 ) + 1
	for j in list ( m ) :
		if ( ( j in m ) and m [ j ] > 1 ) :
			x , y = 0 , 0
			if 2 * j in m :
				m [ 2 * j ] = m [ 2 * j ] + m [ j ] // 2
			else :
				m [ 2 * j ] = m [ j ] // 2
			if ( 2 * j > maximum ) :
				maximum = 2 * j
	return maximum
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 1 , 2 , 4 , 7 , 8 ]
	n = len ( arr )
	print ( largest_sum ( arr , n ) )