#include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,a) for(int i=0;i<(a);i++) #define MOD 1000000007 int N; const ll MA=1000000000; ll a[100000]; ll solve(ll x){ ll res=0; rep(i,N) res+=abs(a[i]-x); return res; } int main(){ cin>>N; rep(i,N) cin>>a[i]; sort(a,a+N); int lb=-MA-1,ub=MA+1; while(ub-lb>5){ ll mid1=(lb*2+ub)/3; ll mid2=(lb+ub*2)/3; if(solve(mid1)>solve(mid2)) lb=mid1; else ub=mid2; } ll ans=LLONG_MAX/2; for(ll i=lb;i<=ub;i++){ ans=min(ans,solve(i)); } cout<