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]; long total = 0; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); total += arr[i]; } Arrays.sort(arr); if (n == 1) { System.out.println(0); return; } else if (n == 2) { System.out.println(arr[1] - arr[0]); return; } else if (n == 3) { System.out.println(total - arr[1] * 3L); return; } long max = 0; int left = 0; int right = n - 1; long value = 0; while (left < right) { value += arr[left] + arr[right]; long count = (left + 1) * 2; max = Math.max(max, value - arr[left + 1] * count); left++; right--; } left = 0; right = n - 1; value = 0; while (left + 1 < right) { value += arr[left] + arr[right]; long count = left + 1; max = Math.max(max, value - (arr[left + 1] + arr[left + 2]) * count); left++; right--; } System.out.println(max); } }