


The first line of input contains an integer value 'N'. It denotes the total number of ropes.
The second line of input contains 'N' single space separated integers representing length of each rope i.e. a1, a2, a3, ... an.
The only line of output will contain an integer, the minimum cost for connecting all the ropes.
You need not to print anything, it has been already taken care of. Just implement the given function.
1 <= N <= 10^5
1 <= ai <= 10^9
Time Limit : 1 sec
Clearly, the rope which is picked up first will be having its length included more than once in the final cost. If we pick a rope of larger length earlier, then we will be adding some extra cost to our final result.
So, the idea is to pick ropes of smaller lengths initially to minimize the impact on our final cost.
So, each time we will be finding two smallest ropes, connecting them and
adding the resulting rope back to the pile.
The idea is to use a Heap Data Structure which extracts minimum value in Log(N) time.
Here is the complete algorithm: