# B. Power Sequence SOLUTIONS

## Power Sequence SOLUTION Codeforces

We should call a rundown of positive numbers a0,a1,…,an−1 a force succession on the off chance that there is a positive number c, so that for each 0≤i≤n−1 then ai=ci.

Given elite of n positive numbers a0,a1,…,an−1, you are permitted to:

Reorder the rundown (for example pick a stage p of {0,1,…,n−1} and change ai to programming interface), at that point

Do the accompanying activity quite a few times: pick a record I and change ai to ai−1 or ai+1 (for example augmentation or decrement ai by 1) with an expense of 1.

Locate the base expense to change a0,a1,…,an−1 into a force grouping.

Information

The principal line contains a whole number n (3≤n≤105).

The subsequent line contains n numbers a0,a1,…,an−1 (1≤ai≤109).

Yield

Print the base expense to change a0,a1,…,an−1 into a force grouping.

Models

inputCopy

1 3 2

outputCopy

inputCopy

1000000000

outputCopy

1999982505

Note

In the main model, we first reorder {1,3,2} into {1,2,3}, at that point increase a2 to 4 with cost 1 to get a force grouping {1,2,4}.