#include <bits/stdc++.h>
#define fi first
#define sd second
using namespace std;
priority_queue<pair<int,int> > q;
int t,x,y,f=0;
long long ret[3];
int main() {
freopen("nit.in","r",stdin);
freopen("nit.out","w",stdout);
cin>>t;
while (t--)
{
scanf("%d%d",&x,&y);
q.push({x-y,y});
}
while (!q.empty())
{
pair<int,int> t=q.top();q.pop();
if (t.sd==0) ret[f]+=t.fi;
else ret[f]+=t.fi+t.sd,q.push({t.sd,0});
f^=1;
}
cout<<ret[0]-ret[1];
}