for each point , finding the distance .
res = 0 NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT res += ( arr [ i ] * i - sum ) NEW_LINE sum += arr [ i ] NEW_LINE DEDENT return res NEW_LINE def totaldistancesum ( x , y , n ) : NEW_LINE return distancesum ( x , n ) + distancesum ( y , n ) NEW_LINE