#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, ans = 0; for (int64_t i = 0; i < (n - 1) / 2; i++) { s += a[i] + a[n - 1 - i]; ans = max(ans, s - 2 * (i + 1) * a[i + 1]); } cout << ans << endl; }