#include <bits/stdc++.h>
using namespace std;
int n, ft, st;
pair<int, int> xa[112];
bool f[112], s[112];
int bs(int x) {
  int l = -1, r = n;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (xa[m].first < x)
      l = m;
    else
      r = m;
  }
  return l;
}
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  xa[0] = {0, 0};
  for (int i = 1; i <= n; i++) scanf("%d %d", &xa[i].first, &xa[i].second);
  std::sort(xa, xa + n + 1);
  int p = bs(0) + 1, b = 1;
  f[p] = s[p] = 1;
  while (1) {
    while (p >= 0 && p <= n && f[p] == 1) p += b;
    if (p < 0 || p > n || f[p] == 1) {
      break;
    } else
      ft += xa[p].second, b *= -1, f[p] = 1;
  }
  p = bs(0) + 1, b = -1;
  while (1) {
    while (p >= 0 && p <= n && s[p] == 1) p += b;
    if (p < 0 || p > n || s[p] == 1) {
      break;
    } else
      st += xa[p].second, b *= -1, s[p] = 1;
  }
  printf("%d\n", max(st, ft));
  return 0;
}
