https://www.acwing.com/problem/content/106/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[100010],ans=0;
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)ans+=a[i]-a[i/2];
cout<<ans;
return 0;
}