#K93887. Sea Defense Height Adjustment

    ID: 38519 Type: Default 1000ms 256MiB

Sea Defense Height Adjustment

Sea Defense Height Adjustment

You are given n sea defenses with various heights. Your task is to calculate the minimum total height increase required so that every sea defense reaches the height of the tallest defense.

Formally, let \( h_1, h_2, \dots, h_n \) be the heights of the sea defenses. If \( M = \max\{h_1, h_2, \dots, h_n\} \), then the total increase required is:

\( \sum_{i=1}^{n} (M - h_i) \)

If n is 0, then output 0.

inputFormat

The first line contains an integer n denoting the number of sea defenses.

The second line contains n space-separated integers representing the heights of the sea defenses.

outputFormat

Output a single integer which is the minimum total height increase needed so that all sea defenses reach the height of the tallest defense.

## sample
5
3 1 2 4 2
8

</p>