#include #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; ll LINF = (1LL << 61) - 1; int INF = (1LL << 30) - 1; int MOD = 1e9+7; vector V; ll getAbs(ll mid){ ll sum = 0; for(auto i:V){ sum += abs(i - mid); } return sum; } main(){ int N; cin >> N; V.resize(N); rep(i,N){ cin >> V[i]; } sort(V.begin(), V.end()); cout << getAbs(V[N/2]) << endl; }