import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] li = new int[n]; long[] rsw = new long[n]; long ans = 0; for(int i = 0; i < n; i++){ li[i] = sc.nextInt(); } Arrays.sort(li); rsw[0] = li[0]; for(int i = 1; i < n; i++){ rsw[i] += li[i]+rsw[i-1]; } int n2 = n/2; for(int i = 1; i < n2+1; i++){ long tmp = rsw[i] + (rsw[n-1]-rsw[n-1-i])-(li[i]*(i*2+1)); ans = Math.max(ans,tmp); } for(int i = 0; i < n2+1; i++){ long tmp = rsw[i] + (rsw[n-1]-rsw[n-1-i]); tmp -= (li[i]*((i+1)*2)); ans = Math.max(ans,tmp); } System.out.println(ans); } }