#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
long long ans = 0;
vector<ll> v(n);
for(int i = 0; i < n; ++i){
ll 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;
return 0;
}