#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n;
  cin >> n;
  vector<pair<int, int> > a, b;
  int c1 = 0, c2 = 0;
  int p, q;
  for (i = 0; i < n; i++) {
    cin >> p >> q;
    if (p < 0) {
      a.push_back(make_pair(p, q));
    } else
      b.push_back(make_pair(p, q));
  }
  sort(b.begin(), b.end());
  sort(a.rbegin(), a.rend());
  long long int ans1 = 0, ans2 = 0;
  for (i = 0; i < n; ++i) {
    if (i % 2) {
      if (c1 == b.size())
        break;
      else
        ans1 += b[c1++].second;
    } else {
      if (c2 == a.size())
        break;
      else
        ans1 += a[c2++].second;
    }
  }
  c1 = 0, c2 = 0;
  for (i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      if (c1 == b.size())
        break;
      else
        ans2 += b[c1++].second;
    } else {
      if (c2 == a.size())
        break;
      else
        ans2 += a[c2++].second;
    }
  }
  cout << max(ans1, ans2);
  return 0;
}
