#include #include using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) int scan() { auto minus = false; auto 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 main() { auto n = scan(); vector Y(n); REP(i, n) Y[i] = scan(); sort(Y.begin(), Y.end()); auto mid = Y[n / 2]; auto ans = 0; REP(i, n) ans += abs(Y[i] - mid); printf("%d", ans); }