import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = new int[](n);
  foreach (i; 0..n) {
    a[i] = readln.chomp.to!int;
  }
  a.sort();
  auto res1 = new int[](n-1);
  auto res2 = new int[](n-1);
  
  foreach (i; 0..n-1) {
    if (i % 2) {
      res1[i] = a[$-i/2-1];
      res2[i] = a[i/2];
    } else {
      res1[i] = a[i/2];
      res2[i] = a[$-i/2-1];
    }
  }
  int sum1, sum2;
  foreach (i; 0..n-2) {
    sum1 += abs(res1[i] - res1[i+1]);
    sum2 += abs(res2[i] - res2[i+1]);
  }
  sum1 += max(abs(a[n/2] - res1[0]), abs(a[n/2] - res1[$-1]));
  sum2 += max(abs(a[n/2] - res2[0]), abs(a[n/2] - res2[$-1]));

  max(sum1, sum2).writeln;
}
