#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include<math.h>
#include <string.h>
#include <fstream>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define allR(x) (x).rbegin() , (x).rend()
#define pb push_back
const int N = 3e5+5, MX=1e9;
int a[N], change[N];
pair<int,int> p[N];
int main(){
freopen("input.txt", "r", stdin);
int n;
ll ans=0, ans2=0, sum=0, sum2=0;
cin >> n;
for(int i=0 ; i<n ; i++ ){
cin >> p[i].first >> p[i].second;
sum += p[i].first;
sum2 += p[i].second;
}
sort(p, p+n);
for(int i=0 ; i<n/2 ; i++ ){
ans += p[i].first;
ans2 += p[i].second;
}
cout << max( ans + sum2 - ans2, ans2 + sum-ans) ;
}
Copy