#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	vector<long long> a(n), b(n);
	for(int i = 0; i < n; scanf("%lld", &a[i++])){}
	sort(a.begin(), a.end());
	long long total = 0, total2 = 0, total3 = 0, total4 = 0;
	int center = n / 2;
	b[center] = a[0];
	for(int i = 1, mi = 1, mx = n - 1; ; ++i)
	{
		if(mx == mi)
		{
			if(center + i < n)
			{
				b[center + i] = a[mx];
			}
			else
			{
				b[center - i] = a[mi];
			}
			break;
		}
		if(mx < mi)
		{
			break;
		}
		if(i % 2)
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center - i] = a[mx--];
				b[center + i] = a[mx--];
			}
			else
			{
				b[center + i] = a[mx--];
				b[center - i] = a[mx--];
			}
		}
		else
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center + i] = a[mi++];
				b[center - i] = a[mi++];
			}
			else
			{
				b[center - i] = a[mi++];
				b[center + i] = a[mi++];
			}
		}
	}
	for(int i = 1; i < n; ++i)
	{
		total += abs(b[i] - b[i - 1]);
	}
	b[center] = a[n - 1];
	for(int i = 1, mi = 0, mx = n - 2; ; ++i)
	{
		if(mx == mi)
		{
			if(center + i < n)
			{
				b[center + i] = a[mx];
			}
			else
			{
				b[center - i] = a[mi];
			}
			break;
		}
		if(mx < mi)
		{
			break;
		}
		if(!(i % 2))
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center - i] = a[mx--];
				b[center + i] = a[mx--];
			}
			else
			{
				b[center + i] = a[mx--];
				b[center - i] = a[mx--];
			}
		}
		else
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center + i] = a[mi++];
				b[center - i] = a[mi++];
			}
			else
			{
				b[center - i] = a[mi++];
				b[center + i] = a[mi++];
			}
		}
	}
	for(int i = 1; i < n; ++i)
	{
		total2 += abs(b[i] - b[i - 1]);
	}
	center = (n - 1) / 2;
	b[center] = a[0];
	for(int i = 1, mi = 1, mx = n - 1; ; ++i)
	{
		if(mx == mi)
		{
			if(center + i < n)
			{
				b[center + i] = a[mx];
			}
			else
			{
				b[center - i] = a[mi];
			}
			break;
		}
		if(mx < mi)
		{
			break;
		}
		if(i % 2)
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center - i] = a[mx--];
				b[center + i] = a[mx--];
			}
			else
			{
				b[center + i] = a[mx--];
				b[center - i] = a[mx--];
			}
		}
		else
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center + i] = a[mi++];
				b[center - i] = a[mi++];
			}
			else
			{
				b[center - i] = a[mi++];
				b[center + i] = a[mi++];
			}
		}
	}
	for(int i = 1; i < n; ++i)
	{
		total3 += abs(b[i] - b[i - 1]);
	}
	b[center] = a[n - 1];
	for(int i = 1, mi = 0, mx = n - 2; ; ++i)
	{
		if(mx == mi)
		{
			if(center + i < n)
			{
				b[center + i] = a[mx];
			}
			else
			{
				b[center - i] = a[mi];
			}
			break;
		}
		if(mx < mi)
		{
			break;
		}
		if(!(i % 2))
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center - i] = a[mx--];
				b[center + i] = a[mx--];
			}
			else
			{
				b[center + i] = a[mx--];
				b[center - i] = a[mx--];
			}
		}
		else
		{
			if(b[center + i - 1] > b[center - i + 1])
			{
				b[center + i] = a[mi++];
				b[center - i] = a[mi++];
			}
			else
			{
				b[center - i] = a[mi++];
				b[center + i] = a[mi++];
			}
		}
	}
	for(int i = 1; i < n; ++i)
	{
		total4 += abs(b[i] - b[i - 1]);
	}
	printf("%lld\n", max(max(total3, total4), max(total, total2)));
}


Measured memory_bytes: 1920