#K34587. Minimum Final Value of an Array

    ID: 25342 Type: Default 1000ms 256MiB

Minimum Final Value of an Array

Minimum Final Value of an Array

Given an array of integers a1,a2,,ana_1, a_2, \ldots, a_n, you are allowed to perform a series of operations where in each operation you choose two elements and replace them with their sum. After performing these operations repeatedly, only one element will remain. It can be shown that the minimum possible final value is obtained by summing the two smallest elements in the array, i.e., if a(1)a_{(1)} and a(2)a_{(2)} are the smallest and second smallest elements respectively, then the answer is a(1)+a(2)a_{(1)} + a_{(2)}.

This problem requires you to compute this value given the initial array.

inputFormat

The first line contains an integer nn (2n1052 \le n \le 10^5), representing the number of elements in the array. The second line contains nn space-separated integers aia_i (1ai1091 \le a_i \le 10^9), the elements of the array.

outputFormat

Output a single integer: the minimum possible final value, which is the sum of the two smallest numbers in the array.## sample

4
4 3 5 6
7

</p>