#K46787. Minimum Total Cooking Time

    ID: 28054 Type: Default 1000ms 256MiB

Minimum Total Cooking Time

Minimum Total Cooking Time

You are given an integer n representing the number of dishes and a list of n positive integers which denote the cooking durations of these dishes. To minimize the total cooking time, you can rearrange the order in which the dishes are cooked.

The total cooking time is calculated as the sum of the cumulative cooking times. More formally, if the dishes are sorted in ascending order such that \(d_1 \le d_2 \le \dots \le d_n\), then the total cooking time is:

\[ T = d_1 + (d_1+d_2) + \dots + (d_1+d_2+\dots+d_n)\]

Your task is to compute \(T\) given the list of durations.

inputFormat

The first line contains an integer n (1 \(\le\) n \(\le\) 105), the number of dishes. The second line contains n space-separated positive integers, where each integer represents the cooking duration of a dish.

outputFormat

Output a single integer, the minimum total cooking time calculated as the sum of cumulative sums after sorting the durations in ascending order.

## sample
4
4 2 3 7
32