#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int main(void) {
  int n;
  cin >> n;
  set<pair<int, int> > left, right;
  int esq = 0, dir = 0;
  int c0 = 0, c1 = 0;
  for (int i = 0; i < n; i++) {
    int x, a;
    cin >> x >> a;
    if (x < 0)
      esq += a, c0++;
    else
      dir += a, c1++;
    if (x < 0)
      left.emplace(-x, a);
    else
      right.emplace(x, a);
  }
  bool flag = 1;
  if (c0 > c1) flag = 0;
  set<pair<int, int> >::iterator it;
  long long ans = 0;
  while (true) {
    if (flag and right.empty()) break;
    if (!flag and left.empty()) break;
    if (flag)
      it = right.begin();
    else
      it = left.begin();
    ans += it->second;
    if (flag)
      right.erase(it);
    else
      left.erase(it);
    flag = 1 - flag;
  }
  cout << ans << endl;
  return 0;
}
