#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long tc;
  while (cin >> tc) {
    long a[101] = {0}, b[101] = {0}, sum = 0, x, y, j = 0, k = 0, p = 0;
    vector<pair<int, int> > vp1, vp2;
    for (__typeof(tc) i = (1); i <= (tc); i++) {
      cin >> x >> y;
      if (x < 0)
        vp1.push_back(make_pair(x, y));
      else
        vp2.push_back(make_pair(x, y));
    }
    sort((vp1).begin(), (vp1).end());
    sort((vp2).begin(), (vp2).end());
    reverse((vp1).begin(), (vp1).end());
    if (vp1.size() > vp2.size()) {
      p = (vp1.size() < vp2.size() ? vp1.size() : vp2.size());
      for (int i = 0; i < p; i++) sum += vp2[i].second + vp1[i].second;
      sum += vp1[p].second;
    } else if (vp1.size() < vp2.size()) {
      p = (vp1.size() < vp2.size() ? vp1.size() : vp2.size());
      for (int i = 0; i < p; i++) sum += vp2[i].second + vp1[i].second;
      sum += vp2[p].second;
    } else {
      for (int i = 0; i < vp1.size(); i++) sum += vp1[i].second + vp2[i].second;
    }
    cout << sum << endl;
  }
  return 0;
}
