#K54747. Minimum Remaining Element
Minimum Remaining Element
Minimum Remaining Element
You are given an array of n integers. In each operation, you can choose any two elements and replace them with their sum. After performing exactly n-1 operations, only one element remains.
Mathematically, if the array is \(a_1, a_2, \dots, a_n\), the final remaining element is:
\[ S = \sum_{i=1}^{n} a_i \]Your task is to compute \(S\). Although the operations may be performed in different orders, the result is always the sum of the elements.
inputFormat
The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in the array.
The second line contains n space-separated integers \(a_1, a_2, \dots, a_n\) where each \(a_i\) is between 0 and 109.
outputFormat
Output a single integer, the sum of all the elements in the array, which is the final remaining element after performing the operations.
## sample4
1 2 3 4
10