#include using namespace std; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int64_t s = 0, k = 0, del = 0, ans = 0; for (int64_t i = 0; i < (n - 1) / 2; i++) { int64_t p = a[i + 1]; s += a[i] + a[n - 1 - k]; k++; while (a[n - 1 - k] - p < p - a[del]) { s -= a[del] + a[n - 1 - k]; del++; k--; } ans = max(ans, s - 2 * (i + 1) * p); } cout << ans << endl; }