P27031 [AtCoder] Align
普及
题目描述

Problem Description

Given $N$ integers, the $i$-th integer is $A_i$. Arrange these integers in any order in a row, and find the maximum sum of the absolute differences between adjacent elements.

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_1 $ $ : $ $ A_N $

Output Format

Output the maximum sum of the absolute differences between adjacent elements when the given integers are arranged in any order in a row.

Sample Input and Output

Sample Input #1

5
6
8
1
2
3

Sample Output #1

21

Sample Input #2

6
3
1
4
1
5
9

Sample Output #2

25

Sample Input #3

3
5
5
1

Sample Output #3

8

Notes/Hints

Constraints

  • $2 \leq N \leq 10^5$
  • $1 \leq A_i \leq 10^9$
  • All inputs are integers

Sample Explanation 1

When arranged in the order $3, 8, 1, 6, 2$, the sum of the absolute differences between adjacent elements is $21$, which is the maximum achievable value.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 6 8 1 2 3
样例输出
21