#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=5e5+1;
struct Node{
int l,r,m;
}st[N];
bool cmp(Node a,Node b){return a.m>b.m;}
int main()
{
int n,m,i,j,s=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&st[i].l,&st[i].r);
if(st[i].l>st[i].r)
swap(st[i].l,st[i].r);
s+=st[i].l;
st[i].m=st[i].l+st[i].r;
}
sort(st+1,st+i,cmp);
for(i=1;i*2<=n;i++)
// printf("i=%d:%d %d\n",i,st[i].l,st[i].r);
s-=st[i].m;
printf("%d",s);
return 0;
}