import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); long[] sums = new long[n]; sums[0] = arr[0]; for (int i = 1; i < n; i++) { sums[i] = sums[i - 1] + arr[i]; } long max = Long.MIN_VALUE; for (int i = 1; i <= (n - 1) / 2; i++) { long value = sums[i - 1] + sums[n - 1] - sums[n - i - 1] - (long)arr[i] * i * 2; max = Math.max(max, value); } System.out.println(max); } }