#include <bits/stdc++.h>
using namespace std;
long long int vis[1000], vis1[1000000];
long long int ara1[100005], ara2[100005];
map<long long int, long long int> str1;
map<long long int, long long int> str2;
int main() {
  long long int t;
  scanf("%lld", &t);
  long long int c = 0, d = 0, sum = 0;
  ;
  for (long long int ii = 1; ii <= t; ii++) {
    long long int a, b;
    scanf("%lld%lld", &a, &b);
    if (a < 0) {
      ara1[c++] = -1 * a;
      str1[-1 * a] = b;
    } else {
      ara2[d++] = a;
      str2[a] = b;
    }
  }
  sort(ara1, ara1 + c);
  sort(ara2, ara2 + d);
  long long int mn = min(c, d);
  for (long long int i = 0; i < mn; i++) sum += str1[ara1[i]] + str2[ara2[i]];
  if (mn == c && mn != d)
    sum += str2[ara2[mn]];
  else if (mn == d && mn != c)
    sum += str1[ara1[mn]];
  cout << sum << endl;
  return 0;
}
