#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    v.push_back(make_pair(x, y));
  }
  v.push_back(make_pair(0, 0));
  v.push_back(make_pair(-100005, 0)), v.push_back(make_pair(100005, 0));
  sort(v.begin(), v.end());
  int pos, sz = v.size();
  for (int i = 0; i < sz; ++i)
    if (v[i].first == 0) {
      pos = i;
      break;
    }
  int l = pos - 1, r = pos + 1;
  long long ans = 0;
  while (v[l].second != 0 && v[r].second != 0) {
    ans += v[l].second, ans += v[r].second;
    --l, ++r;
  }
  ans += max(v[l].second, v[r].second);
  printf("%lld\n", ans);
  return 0;
}
