#include <bits/stdc++.h>
using namespace std;
template <class T>
struct BIT {
  int treesize;
  vector<T> lst;
  BIT(int newn = 0) : treesize(newn), lst(newn + 1, 0) {}
  void add(int place, T num) {
    ++place;
    while (place <= treesize) {
      lst[place] += num;
      place += place & -place;
    }
  }
  T sum(int place) {
    T res = 0;
    while (place > 0) {
      res += lst[place];
      place -= place & -place;
    }
    return res;
  }
  T sum(int left, int right) { return sum(right) - sum(left); }
};
int n, all = 0, lcnt = 0, minum = -1, len = 0;
vector<pair<int, int> > queries;
map<int, int> id, light;
BIT<long long> bcnt, bsum;
vector<int> v;
long long calc();
int main(void) {
  cin >> n;
  queries.resize(n);
  for (auto &p : queries) {
    cin >> p.first >> p.second;
    v.push_back(abs(p.second));
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  reverse(v.begin(), v.end());
  len = v.size();
  bcnt = BIT<long long>(len);
  bsum = BIT<long long>(len);
  for (int i = 0; i < len; ++i) id[v[i]] = i;
  long long sum = 0;
  for (auto [s, p] : queries) {
    int nid = id[abs(p)];
    sum += p;
    if (s) {
      if (p > 0) {
        ++all, ++lcnt, ++light[p];
        if (lcnt == 1) {
          minum = p;
        } else {
          if (p <= minum) {
            nid = id[minum];
            bcnt.add(nid, 1);
            bsum.add(nid, minum);
            minum = p;
          } else {
            bcnt.add(nid, 1);
            bsum.add(nid, p);
          }
        }
      } else {
        --all, --lcnt;
        if (minum != -p || light[-p] > 1) {
          bcnt.add(nid, -1);
          bsum.add(nid, p);
        }
        if (--light[-p] == 0) {
          light.erase(-p);
          if (minum == -p) {
            if (lcnt) {
              minum = (*light.begin()).first;
              nid = id[minum];
              bcnt.add(nid, -1);
              bsum.add(nid, -minum);
            } else {
              minum = -1;
            }
          }
        }
      }
    } else {
      if (p > 0) {
        ++all;
        bcnt.add(nid, 1);
        bsum.add(nid, p);
      } else {
        --all;
        bcnt.add(nid, -1);
        bsum.add(nid, p);
      }
    }
    cout << calc() + sum << endl;
  }
  return 0;
}
long long calc() {
  int num = lcnt - (lcnt == all), l = 0, r = len;
  if (num <= 0) return 0;
  auto check = [&](int x) { return bcnt.sum(x) >= num; };
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  long long res = bsum.sum(r);
  return res;
}
