void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto a = new long[](n);
  foreach (i; 0 .. n)
    rd(a[i]);

  sort(a);
  long sum = 0;
  if (n & 1) {
    long s = 0;
    s -= a[0] * 2;
    for (int i = n - 1, t = 1; i > 0; i -= 2, t ^= 1) {
      long ad = (a[i] + a[i - 1]);
      if (t == 0)
        ad *= -1;
      if (i - 2 > 0)
        ad *= 2;
      s += ad;
    }
    long s2 = 0;
    s2 += a[$ - 1] * 2;
    for (int i = 0, t = 1; i + 1 < n; i += 2, t ^= 1) {
      long ad = (a[i] + a[i + 1]);
      if (t)
        ad *= -1;
      if (i + 2 < n - 1)
        ad *= 2;
      s2 += ad;
    }
    sum = max(s, s2);
  } else {
    long s = 0;
    s -= a[0] * 2;
    s += a[$ - 1] * 2;
    for (int i = 1; i < n / 2; i++) {
      long ad = a[n - i - 1] - a[i];
      if (i + 1 < n / 2)
        ad *= 2;
      s += ad;
    }
    sum = s;
  }
  writeln(sum);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}
