#include #include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n); for(auto &&v : a) cin >> v; sort(a.begin(), a.end()); int l = 0, r = n - 1; ll ans = 0; for(int i = 0; i < n; i++){ if(i % 2 == 0){ ans += a[r--]; }else{ ans -= -a[l++]; } } cout << ans << '\n'; }