#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> p, pair<long long, long long> p1) {
  if (p.first != p1.first)
    return p.first < p1.first;
  else if (p.second != p1.second)
    return p.second > p1.second;
}
int main() {
  long long n, k, m, x, y, ans;
  pair<long long, long long> a[100], b[100];
  scanf("%lld", &n);
  x = y = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld", &k, &m);
    if (k > 0) {
      x++;
      a[x].first = k;
      a[x].second = m;
    } else {
      y++;
      b[y].first = k * (-1);
      b[y].second = m;
    }
  }
  sort(a + 1, a + 1 + x, cmp);
  sort(b + 1, b + 1 + y, cmp);
  ans = 0;
  if (x > y) {
    for (int i = 1; i <= y; i++) ans += a[i].second + b[i].second;
    ans += a[y + 1].second;
  } else {
    if (y > x) {
      for (int i = 1; i <= x; i++) ans += a[i].second + b[i].second;
      ans += b[x + 1].second;
    } else {
      for (int i = 1; i <= y; i++) ans += a[i].second + b[i].second;
    }
  }
  printf("%lld\n", ans);
}
