#P7823. Alarm Clock Adjustment

    ID: 21008 Type: Default 1000ms 256MiB

Alarm Clock Adjustment

Alarm Clock Adjustment

You are given an alarm clock that is controlled by two variables (a_1) and (a_2). Initially, both (a_1 = 0) and (a_2 = 0). Changing the value of a variable from (x) to (y) incurs a cost of (|x-y|).

You are then given (n) integers: (k_1, k_2, \dots, k_n). For the (i)-th day, you must adjust the values of the variables so that at least one of them equals (k_i). Your task is to compute the minimum total cost required to satisfy the condition for all (n) days.

inputFormat

The first line contains an integer (n) denoting the number of days. The second line contains (n) space-separated integers (k_1, k_2, \dots, k_n).

outputFormat

Output a single integer, the minimum total cost required to adjust the alarm clock variables over the (n) days.

sample

3
1 2 3
3