#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */
#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key> >
using ostree = pbds::tree<key, val, comp, pbds::rb_tree_tag,
                          pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define allOf(x) std::begin(x), std::end(x)
template <typename...Args>
ostream&operator<<(ostream&os, pair<Args...> const &p)
{return os<<'('<<p.first<<", "<<p.second<<')';}
template <typename...Args>
ostream&operator<<(ostream&os, vector<Args...> const &v)
{os<<'[';for(const auto&el:v)os<<' '<<el;return(os<<" ]");}
template <typename...Args> ostream&operator<<(ostream&os, map<Args...>const&v)
{os<<'[';for(auto const&el:v)os<<' '<<el;return(os<<" ]");}
template <typename...Args> ostream&operator<<(ostream&os, set<Args...>const&v)
{os<<'[';for(auto const&el:v)os<<' '<<el;return(os<<" ]");}
template <typename...Args>
ostream&operator<<(ostream&os, unordered_map<Args...>const&v)
{os<<'[';for(auto const&el:v)os<<' '<<el;return(os<<" ]");}
template<typename T> void trace_rec(stringstream&sst, const T&t)
{ string arg; getline(sst, arg, ','); cerr << arg << " : " << t << " }"; }
template<typename T, typename... Args>
void trace_rec(stringstream&sst, const T&t, const Args... args)
{ string arg; getline(sst, arg, ','); cerr << arg << " : " << t << ", ";
  trace_rec(sst, args...); }
template<typename... Args> void trace(const string&s, Args... args)
{stringstream sst(s); cerr << "{ "; trace_rec(sst, args...); cerr << endl;}
#define dbg(...) // trace(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void dbr(const T lb, const T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<(*it);cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T> >
bool setMin(T &mem, const T&v, Comp comp = Comp())
{ return comp(v, mem) ? mem = v, true : false; }
template<typename T, typename Comp=less<T> >
bool setMax(T &mem, const T&v, Comp comp = Comp())
{ return comp(mem, v) ? mem = v, true : false; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */




int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n; cin >> n;
  vll x(1+n,0), a(1+n, 0);
  for(int i=1; i<=n; i++) cin >> x[i];
  sort(allOf(x));

  ll ans = 0;
  {  
    for(int z=0, l=1, r=n, i=1; l<=r; z^=1) {
      if(z==0) a[i++] = x[l++];
      else a[i++] = x[r--];
    }

    vll b(1+n+n, 0), c(1+n+n, 0);
    for(int i=1; i<=n; i++) b[i] = b[i+n] = a[i];

    for(int i=2; i<=n+n; i++) c[i] = abs(b[i]-b[i-1]);

    dbg(a);
    dbg(b);
    dbg(c);

    for(int i=2; i<=n+n; i++) c[i] += c[i-1];
    dbg(c);

    for(int lx = 1, rx = n;  rx<=n+n; lx++, rx++) {
      dbg(ans, c[rx]-c[lx], lx, rx);
      setMax(ans, c[rx]-c[lx]);
    }
  }

  reverse(x.begin()+1, x.end());
  {  
    for(int z=0, l=1, r=n, i=1; l<=r; z^=1) {
      if(z==0) a[i++] = x[l++];
      else a[i++] = x[r--];
    }

    vll b(1+n+n, 0), c(1+n+n, 0);
    for(int i=1; i<=n; i++) b[i] = b[i+n] = a[i];

    for(int i=2; i<=n+n; i++) c[i] = abs(b[i]-b[i-1]);

    dbg(a);
    dbg(b);
    dbg(c);

    for(int i=2; i<=n+n; i++) c[i] += c[i-1];
    dbg(c);

    for(int lx = 1, rx = n;  rx<=n+n; lx++, rx++) {
      dbg(ans, c[rx]-c[lx], lx, rx);
      setMax(ans, c[rx]-c[lx]);
    }
  }

  cout << ans << endl;


  return 0;
}

/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 4992