/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.20 16:32:07 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n;cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); ll ans = 0; ll x = 0; ll y = 0; ll m = a[0]; for (int i = 1; i < n-i; i++) { y += (a[i] - m) * i; x -= (a[i] - m) * (i - 1); x += a[n-i] - a[i]; ans = max(ans,x - y); m = a[i]; } cout << ans << endl; return 0; }