#include // #include #include using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (n); i++) int scan() { auto minus = false; int result = 0; while (true) { auto k = getchar_unlocked(); if (k == '-') minus = true; else if (k < '0' || k > '9') break; else result = 10 * result + k - '0'; } return result * (minus ? -1 : 1); } int Y[1000010]; signed main() { int n = scan(); REP(i, n) Y[i] = scan(); sort(Y, Y + n); int mid = Y[n / 2]; int ans = 0; REP(i, n) ans += abs(Y[i] - mid); printf("%lld\n", ans); }