#include <stdio.h>
#include <vector>
#include <algorithm>
int main() {
int n;
scanf("%d", &n);
std::vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &a[i], &b[i]);
}
std::vector<int> queue1(n), queue2(n);
for (int i = 0; i < n; ++i) {
queue1[i] = i;
queue2[i] = i;
}
std::sort(queue1.begin(), queue1.end(), [&](const int i, const int j) {
return a[i] > a[j] || (a[i] == a[j] && b[i] > b[j]);
});
std::sort(queue2.begin(), queue2.end(), [&](const int i, const int j) {
return b[i] > b[j] || (b[i] == b[j] && a[i] > a[j]);
});
std::vector<bool> actual(n, true);
int sum1 = 0, sum2 = 0, pos1 = 0, pos2 = 0;
while (true) {
while (pos1 < n && actual[pos1] == false) ++pos1;
if (pos1 == n) break;
sum1 += a[pos1];
actual[pos1] = false;
while (pos2 < n && actual[pos2] == false) ++pos2;
if (pos2 == n) break;
sum2 += b[pos2];
actual[pos2] = false;
}
printf("%d", sum1-sum2);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiAKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKICAgIHNjYW5mKCIlZCIsICZuKTsKICAgICAKICAgIHN0ZDo6dmVjdG9yPGludD4gYShuKSwgYihuKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgc2NhbmYoIiVkICVkIiwgJmFbaV0sICZiW2ldKTsKICAgIH0KICAgICAKICAgIHN0ZDo6dmVjdG9yPGludD4gcXVldWUxKG4pLCBxdWV1ZTIobik7CiAgICAgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIHF1ZXVlMVtpXSA9IGk7CiAgICAgICAgcXVldWUyW2ldID0gaTsKICAgIH0KICAgICAKICAgIHN0ZDo6c29ydChxdWV1ZTEuYmVnaW4oKSwgcXVldWUxLmVuZCgpLCBbJl0oY29uc3QgaW50IGksIGNvbnN0IGludCBqKSB7CiAgICAgICAgcmV0dXJuIGFbaV0gPiBhW2pdIHx8IChhW2ldID09IGFbal0gJiYgYltpXSA+IGJbal0pOwogICAgfSk7CiAgICAgCiAgICBzdGQ6OnNvcnQocXVldWUyLmJlZ2luKCksIHF1ZXVlMi5lbmQoKSwgWyZdKGNvbnN0IGludCBpLCBjb25zdCBpbnQgaikgewogICAgICAgIHJldHVybiBiW2ldID4gYltqXSB8fCAoYltpXSA9PSBiW2pdICYmIGFbaV0gPiBhW2pdKTsKICAgIH0pOwogICAgIAogICAgc3RkOjp2ZWN0b3I8Ym9vbD4gYWN0dWFsKG4sIHRydWUpOwogICAgIAogICAgaW50IHN1bTEgPSAwLCBzdW0yID0gMCwgcG9zMSA9IDAsIHBvczIgPSAwOwogICAgd2hpbGUgKHRydWUpIHsKICAgICAgICB3aGlsZSAocG9zMSA8IG4gJiYgYWN0dWFsW3BvczFdID09IGZhbHNlKSArK3BvczE7CiAgICAgICAgaWYgKHBvczEgPT0gbikgYnJlYWs7CiAgICAgICAgc3VtMSArPSBhW3BvczFdOwogICAgICAgIGFjdHVhbFtwb3MxXSA9IGZhbHNlOwogICAgICAgIHdoaWxlIChwb3MyIDwgbiAmJiBhY3R1YWxbcG9zMl0gPT0gZmFsc2UpICsrcG9zMjsKICAgICAgICBpZiAocG9zMiA9PSBuKSBicmVhazsKICAgICAgICBzdW0yICs9IGJbcG9zMl07CiAgICAgICAgYWN0dWFsW3BvczJdID0gZmFsc2U7CiAgICB9CiAgICBwcmludGYoIiVkIiwgc3VtMS1zdW0yKTsKICAgIHJldHVybiAwOwp9