#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n; cin >> n;
int ans = 0;
vector<int> v(n);
for(int i = 0; i < n; ++i){
int a, b;
cin >> a >> b;
ans += a;
v[i] = b - a;
}
sort(v.begin(), v.end());
for(int i = n/2; i < n; ++i)
ans += v[i];
cout << ans << endl;
return 0;
}