#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector y(n); for (int i = 0; i < n; ++i) cin >> y[i]; sort(y.begin(), y.end()); ll c = n & 1 ? y[n / 2] : (y[n / 2 - 1] + y[n / 2]) / 2; ll res{ 0 }; for (const auto& it : y) res += abs(it - c); cout << res << "\n"; return 0; }