#include using namespace std; int main() { int n; cin >> n; vector y(n); for (int i = 0; i < n; i++) cin >> y.at(i); sort(y.begin(), y.end()); int dmax = 0, dmaxi = 0; for (int i = 0; i < n - 1; i++) { int d = y.at(i + 1) - y.at(i); if (d > dmax) { dmax = d; dmaxi = i; } } if (dmax == 0) { cout << 1 << endl; return 0; } long dsum = 0, yformer = y.at(dmaxi / 2), ylatter = y.at((n + dmaxi) / 2); for (int i = 0; i <= dmaxi; i++) dsum += abs(y.at(i) - yformer); for (int i = dmaxi + 1; i < n; i++) dsum += abs(y.at(i) - ylatter); cout << dsum << endl; }