human
Sum of ( maximum element | Function to return a ^ n % mod.
Compute sum of max ( A ) - min ( A ) for all subsets.
Sort the array ..
Maxs = 2 ^ i - 1.
Mins = 2 ^ ( n - 1 - i ) - 1.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to sum of ( maximum element and the other steps required.
 def power ( a , n ) :
	if n == 0 :
		return 1
	p = power ( a , n // 2 ) % mod
	p = ( p * p ) % mod
	if n & 1 == 1 :
		p = ( p * a ) % mod
	return p
def computeSum ( arr , n ) :
	arr . sort ( )
	Sum = 0
	for i in range ( 0 , n ) :
		maxs = ( power ( 2 , i ) - 1 + mod ) % mod
		maxs = ( maxs * arr [ i ] ) % mod
		mins = ( power ( 2 , n - 1 - i ) - 1 + mod ) % mod
		mins = ( mins * arr [ i ] ) % mod
		V = ( maxs - mins + mod ) % mod
		Sum = ( Sum + V ) % mod
	return Sum
if __name__ == " _ _ main _ _ " :
	mod = 1000000007
	arr = [ 4 , 3 , 1 ]
	n = len ( arr )
	print ( computeSum ( arr , n ) )