include [HTML_REMOVED]
using namespace std;
typedef long long ll;
ll n,ans;
const ll N=1e5+1e4;
ll a[N];
signed main()
{
cin>>n;
for(ll i=1;i<=n;i)cin>>a[i];
sort(a+1,a+n+1);
for(ll i=1;i<=n/2;i)ans+=(a[n-i+1]-a[i]);
cout<<ans;
return 0;
}