#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, n;
} a[200];
int n;
bool cmp(node a, node b) { return a.x < b.x; }
int main() {
  while (~scanf("%d", &n)) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &a[i].x, &a[i].n);
      if (a[i].x < 0) cnt++;
    }
    sort(a, a + n, cmp);
    int yy = cnt;
    if (n - cnt < yy) yy = n - cnt;
    int ans = 0;
    for (int i = cnt - 1; i >= cnt - yy; i--) {
      ans += a[i].n;
    }
    for (int i = cnt; i < cnt + yy; i++) {
      ans += a[i].n;
    }
    int bb = 0;
    if (cnt - yy - 1 >= 0) bb = a[cnt - yy - 1].n;
    if (cnt + yy < n && a[cnt + yy].n > bb) bb = a[cnt + yy].n;
    ans += bb;
    cout << ans << endl;
  }
  return 0;
}
