Computer Science, asked by kkishor7967, 1 year ago

Kevin has a sequence of integers a1, a2, ..., an. Define the strength of the sequence to be

|a1 - a2| + |a2 - a3| + ... + |an-1 - an| + |an - a1|.

Kevin wants to make his sequence stronger, so he reorders his sequence into a new sequence b1, b2, ..., bn. He wants this new sequence to be as strong as possible. What is the largest possible strength of the resulting sequence?

Input

The input consists of 2 lines. The first line has a positive integer n. The second line contains the n integers a1, a2, ..., an.

Output

Output a single integer: the maximum possible strength.

Constraints

1 <= n <= 10^5.
|ai| <= 10^9.

Note that ai can be negative.

Answers

Answered by dheeraj86
0
For the sequence a1,a2,a3,…, an,an=an−1+an−2 for all values n>2. If a1=1 and a3=4, what are the values of a2 and a8?

a2 a8
2
3
29
47
76

Hi, I used the same method as OE. Can anyone know other faster way to solve this question, please.
Similar questions