#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[110], b[110];
int main() {
  int n, x, y, z = 0, t = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x < 0)
      b[z].first = -1 * x, b[z].second = y, z++;
    else
      a[t].first = x, a[t].second = y, t++;
  }
  sort(a, a + t);
  sort(b, b + z);
  y = 0;
  x = min(t, z);
  for (int i = 0; i <= x; i++) y += a[i].second + b[i].second;
  if (x == t) y -= a[x].second;
  if (x == z) y -= b[x].second;
  cout << y;
}
