#P4597. 序列 sequence

序列 sequence

Description

Given a sequence, in each operation you may add +1+1 or 1-1 to any number. Make the sequence non-decreasing.

Input Format

The first line contains an integer nn (n5×105n \le 5 \times 10^5), the number of elements.
The second line contains nn integers; the absolute value of each integer does not exceed 10910^9.

Output Format

Output a single number: the minimal number of operations.

5
3 2 -1 2 11

4
5
2 1 1 1 1

1

Hint

For 100%100\% of the testdata, 1n5×1051 \le n \le 5 \times 10^5.

Translated by ChatGPT 5