#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int n;
    cin >> n;

    vector<ll> ab;
    ll cnt = 0;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        ab.push_back(a+b);
        cnt += b;
    }
    sort(ab.begin(), ab.end(), greater<ll>());
    ll ans = 0;
    rep(i, (n+1)/2){
        ans += ab[2 * i];
    }
    ans -= cnt;

    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e18
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b)  for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll n,ans=0,x,mx=0;cin>>n;
         for(ll i=0;i<n;i++){
            cin>>x;
            if(mx>x)ans+=mx-x;
            mx=max(mx,x);
         }
         cout<<ans<<"\n";
    }
}
