///
#include<bits/stdc++.h> ///
using namespace std; ///
const int N=1e5+5; ///
long long a[N]; ///
long long sum; ///
int main(){ ///
long long n,c; ///
cin>>n; ///
for(int i=0;i<n;i++){ ///
cin>>a[i]; ///
} ///
int j=n-1; ///
sort(a,a+n); ///
for(int i=0;i<n;i++){ ///
sum+=abs(a[i]-a[j/2]); ///
} ///
cout<<sum; ///
return 0; ///
} ///
///
AC代码双手奉上