时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
Special Judge, 64bit IO Format: %lld

题目描述

Alice and Bob are playing a number guessing game.

Alice has secretly chosen an integer x. Bob can ask Alice any integer y, and Alice will respond with either Yes or No, indicating whether x \geq y. Additionally, Alice keeps track of the cost of each query, which is |x - y|. Note that Bob is unaware of the specific cost associated with each query.

Bob knows that x must be one of the integers a_1, a_2, \cdots, a_n that are given in ascending order. To determine x, Bob wants to minimize the worst-case scenario of the sum of query costs.

Please determine the minimum possible sum of query costs in the worst-case scenario.

输入描述:

The first line contains a positive integer n.
The second line contains n positive integers a_i, guaranteed to be sorted in ascending order.

输出描述:

Output one integer, which is the minimum sum of query costs in the worst-case scenario.
示例1

输入

复制
4
1 5 6 7

输出

复制
4
示例2

输入

复制
10
8 18 20 24 50 53 77 92 100 121

输出

复制
64

备注:

1 \leq n \leq 1000, 1 \leq a_i \leq 10^9.