#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > a[2];
int main() {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x < 0)
      a[0].push_back(make_pair(-x, y));
    else
      a[1].push_back(make_pair(x, y));
  }
  sort(a[0].begin(), a[0].end());
  sort(a[1].begin(), a[1].end());
  int x = min(a[0].size(), a[1].size());
  int res = 0;
  for (int i = (0), _b = (x - 1); i <= _b; i++)
    res += a[0][i].second + a[1][i].second;
  if (a[0].size() != x) res += a[0][x].second;
  if (a[1].size() != x) res += a[1][x].second;
  cout << res << endl;
}
