#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const long long N = 200005;
vector<long long> a(N), seg(4 * N);
long long queryMax(long long cur, long long st, long long end, long long l,
                   long long r) {
  if (l <= st && r >= end) return seg[cur];
  if (r < st || l > end) return 0;
  long long mid = (st + end) >> 1;
  long long ans1 = queryMax(2 * cur, st, mid, l, r);
  long long ans2 = queryMax(2 * cur + 1, mid + 1, end, l, r);
  return max(ans1, ans2);
}
void updateMax(long long cur, long long st, long long end, long long pos,
               long long upd) {
  if (st == end) {
    a[pos] = upd;
    seg[cur] = upd;
    return;
  }
  long long mid = (st + end) >> 1;
  if (st <= pos && pos <= mid)
    updateMax(2 * cur, st, mid, pos, upd);
  else
    updateMax(2 * cur + 1, mid + 1, end, pos, upd);
  seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]);
}
vector<long long> a1(N), seg1(4 * N);
void buildMin(long long cur, long long st, long long end) {
  if (st == end) {
    seg1[cur] = a1[st];
    return;
  }
  long long mid = (st + end) >> 1;
  buildMin(2 * cur, st, mid);
  buildMin(2 * cur + 1, mid + 1, end);
  seg1[cur] = min(seg1[2 * cur], seg1[2 * cur + 1]);
}
long long queryMin(long long cur, long long st, long long end, long long l,
                   long long r) {
  if (l <= st && r >= end) return seg1[cur];
  if (r < st || l > end) return LLONG_MAX;
  long long mid = (st + end) >> 1;
  long long ans1 = queryMin(2 * cur, st, mid, l, r);
  long long ans2 = queryMin(2 * cur + 1, mid + 1, end, l, r);
  return min(ans1, ans2);
}
void updateMin(long long cur, long long st, long long end, long long pos,
               long long upd) {
  if (st == end) {
    a1[pos] = upd;
    seg1[cur] = upd;
    return;
  }
  long long mid = (st + end) >> 1;
  if (st <= pos && pos <= mid)
    updateMin(2 * cur, st, mid, pos, upd);
  else
    updateMin(2 * cur + 1, mid + 1, end, pos, upd);
  seg1[cur] = min(seg1[2 * cur], seg1[2 * cur + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    map<long long, pair<long long, long long> > spell;
    long long L1 = 0, R1 = 0, L2 = 0, R2 = 0;
    long long sum1 = 0, sum2 = 0;
    long long x, y, pos;
    map<long long, long long> side;
    long long tmp, tmp1, tmp2;
    for (long long i = 1; i <= n; i++) a1[i] = 1000000007;
    buildMin(1, 1, n);
    for (long long i = 1; i <= n; i++) {
      cin >> x >> y;
      if (y > 0) {
        updateMax(1, 1, n, i, y);
        sum1 += y;
        spell[y] = {x, i};
        side[y] = 1;
        if (x)
          L1++;
        else
          R1++;
      } else {
        y *= -1;
        pos = spell[y].second;
        updateMin(1, 1, n, pos, 1000000007);
        updateMax(1, 1, n, pos, 0);
        if (side[y] == 1) {
          if (x)
            L1--;
          else
            R1--;
          sum1 -= y;
        } else {
          if (x)
            L2--;
          else
            R2--;
          sum2 -= y;
        }
      }
      while (L2 + R2 < L1 + L2) {
        tmp = queryMax(1, 1, n, 1, n);
        pos = spell[tmp].second;
        updateMax(1, 1, n, pos, 0);
        updateMin(1, 1, n, pos, tmp);
        sum1 -= tmp;
        sum2 += tmp;
        side[tmp] = 2;
        if (spell[tmp].first) {
          L1--;
          L2++;
        } else {
          R1--;
          R2++;
        }
      }
      while (L2 + R2 > L1 + L2) {
        tmp = queryMin(1, 1, n, 1, n);
        pos = spell[tmp].second;
        updateMax(1, 1, n, pos, tmp);
        updateMin(1, 1, n, pos, 1000000007);
        sum1 += tmp;
        sum2 -= tmp;
        side[tmp] = 1;
        if (spell[tmp].first) {
          L2--;
          L1++;
        } else {
          R2--;
          R1++;
        }
      }
      tmp1 = queryMax(1, 1, n, 1, n);
      tmp2 = queryMin(1, 1, n, 1, n);
      while (tmp1 > tmp2) {
        updateMin(1, 1, n, spell[tmp2].second, 1000000007);
        updateMax(1, 1, n, spell[tmp1].second, 0);
        updateMin(1, 1, n, spell[tmp1].second, tmp1);
        updateMax(1, 1, n, spell[tmp2].second, tmp2);
        if (spell[tmp1].first) {
          L1--;
          L2++;
        } else {
          R1--;
          R2++;
        }
        if (spell[tmp2].first) {
          L2--;
          L1++;
        } else {
          R2--;
          R1++;
        }
        sum2 += tmp1 - tmp2;
        sum1 += tmp2 - tmp1;
        side[tmp1] = 2;
        side[tmp2] = 1;
        tmp1 = queryMax(1, 1, n, 1, n);
        tmp2 = queryMin(1, 1, n, 1, n);
      }
      if (L1 > 0)
        cout << sum1 + 2 * sum2 << '\n';
      else
        cout << sum1 + 2 * sum2 - queryMin(1, 1, n, 1, n) * (L2 != 0) +
                    queryMax(1, 1, n, 1, n) * (L2 > 0)
             << '\n';
    }
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
