#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(n / 4), ylatter = y.at(3 * n / 4); for (int i = 0; i < n / 2; i++) dsum += abs(y.at(i) - yformer); for (int i = n / 2; i < n; i++) dsum += abs(y.at(i) - ylatter); cout << dsum << endl; }