#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<stack> #include<queue> #include<map> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<cstdio> #include<list> #include<sstream> //#include<regex> using namespace std; typedef long long ll; int INF=2147483647; int inf=-2147483648; #define read(x) scanf("%d",&x); #define fo(i,n) for(int i=0;i<(n);i++) #define me(a) memset(a,0,sizeof(a)); #define one(x) cout<<(x)<<endl; #define two(a,b) cout<<(a)<<" "<<(b)<<endl; #define three(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl; #define four(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl; //int dir[4][2]={-1,0,1,0,0,-1,0,1}; //int dir[8][2]={-1,0,1,0,0,-1,0,1,-1,-1,1,1,1,-1,-1,1}; //int dir[4][2]={-2,0,2,0,0,-2,0,2}; int main() { //ios::sync_with_stdio(false); int n,i,l=0,r=0,ans=0,a,b; cin>>n; pair<int,int>p[1000]; for(i=0;i<n;i++){ cin>>p[i].first>>p[i].second; //p[i]=make_pair(a,b); if(p[i].first<0) l++; else r++;} sort(p,p+n); for(i=max(0,l-r-1);i<=min(n,l*2);i++) ans+=p[i].second; cout<<ans; return 0; }