#include <bits/stdc++.h>
namespace IO {
char ch = '\n';
template <class T>
inline T ReadInt() {
  T x(0);
  bool f(1);
  while (ch < '0' || '9' < ch) {
    if (ch == '-') {
      f = 0;
    }
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return f ? x : -x;
}
inline double ReadDouble() {
  long long int_num = ReadInt<long long>();
  if (ch == '.') {
    double pow10 = 1, result = int_num;
    ch = getchar();
    while ('0' <= ch && ch <= '9') {
      pow10 /= 10.0;
      result += pow10 * (ch ^ 48);
      ch = getchar();
    }
    return result;
  } else {
    return (double)int_num;
  }
}
inline void ReadT(int &x) { x = ReadInt<int>(); }
inline void ReadT(long long &x) { x = ReadInt<long long>(); }
inline void ReadT(double &x) { x = ReadDouble(); }
inline void ReadT(char &s) {
  for (; isspace(ch) && (~ch); ch = getchar())
    ;
  s = ch;
  ch = '\n';
}
inline void ReadT(char *s) {
  int len(0);
  for (; isspace(ch) && (~ch); ch = getchar())
    ;
  for (; !isspace(ch) && (~ch); ch = getchar()) {
    s[len++] = ch;
  }
  s[len] = '\0';
  ch = '\n';
}
template <typename T>
inline void Read(T &t) {
  ReadT(t);
}
template <typename T, typename... Args>
void Read(T &t, Args &...args) {
  ReadT(t);
  Read(args...);
}
template <typename T>
void WriteInt(T x) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (9 < x) {
    WriteInt(x / 10);
  }
  putchar(x % 10 + '0');
}
void WriteDouble(long double x, int len) {
  WriteInt((long long)x);
  if (len) {
    x -= (int)x;
    putchar('.');
    if (!x) {
      while (len--) {
        putchar(48);
      }
      return;
    }
    while (len--) {
      x *= 10;
    }
    WriteInt((long long)round(x));
  }
}
template <typename T>
inline void WriteT(T x);
template <>
inline void WriteT<long long>(long long x) {
  WriteInt(x);
}
template <>
inline void WriteT<int>(int x) {
  WriteInt(x);
}
template <>
inline void WriteT<double>(double x) {
  WriteDouble(x, 6);
}
template <>
inline void WriteT<char *>(char *s) {
  int len(strlen(s));
  while (len--) {
    putchar(*s++);
  }
}
template <>
inline void WriteT<const char *>(const char *s) {
  while (*s) {
    putchar(*s++);
  }
}
template <>
inline void WriteT<char>(char x) {
  putchar(x);
}
template <typename T>
inline void Write(T t) {
  WriteT(t);
}
template <typename T, typename... Args>
void Write(T t, Args... args) {
  WriteT(t);
  Write(args...);
}
template <typename T>
inline void Writeln(T t) {
  WriteT(t);
  puts("");
}
template <typename T, typename... Args>
inline void Writeln(T t, Args... args) {
  WriteT(t);
  Write(args...);
  puts("");
}
inline void Writeln() { puts(""); }
const char NUMBER[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                         '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                         'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                         'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
template <typename T>
void WriteK(T x, int p) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (p <= x) {
    WriteK(x / p, p);
  }
  putchar(NUMBER[x % p]);
}
}  // namespace IO
using namespace IO;
using namespace std;
const int MAXN = 2e5 + 5;
int q, len, n, m;
int opt[MAXN];
int num[MAXN];
int sor[MAXN];
int number[MAXN];
map<int, int> Hash;
struct SegmentTree {
  int lson, rson;
  int size;
  long long sum;
} sgt[MAXN * 8];
int sgt_cnt = 0;
void PushUp(int now) {
  sgt[now].size = sgt[sgt[now].lson].size + sgt[sgt[now].rson].size;
  sgt[now].sum = sgt[sgt[now].lson].sum + sgt[sgt[now].rson].sum;
}
void Updata(int num, int add, int &now, int left = 1, int right = len) {
  if (num < left || right < num) {
    return;
  }
  if (!now) {
    now = ++sgt_cnt;
  }
  if (left == right) {
    sgt[now].size += add;
    sgt[now].sum += add * number[num];
    return;
  }
  Updata(num, add, sgt[now].lson, left, ((left + right) >> 1));
  Updata(num, add, sgt[now].rson, ((left + right) >> 1) + 1, right);
  PushUp(now);
}
long long Query(int k, int now, int left = 1, int right = len) {
  if (!now) {
    return 0;
  }
  if (sgt[now].size == k) {
    return sgt[now].sum;
  }
  if (left == right) {
    return 1ll * k * number[left];
  }
  if (k <= sgt[sgt[now].rson].size) {
    return Query(k, sgt[now].rson, ((left + right) >> 1) + 1, right);
  } else {
    return Query(k - sgt[sgt[now].rson].size, sgt[now].lson, left,
                 ((left + right) >> 1)) +
           sgt[sgt[now].rson].sum;
  }
}
long long QueryMin(int now, int left = 1, int right = len) {
  if (left == right) {
    return left;
  }
  if (sgt[sgt[now].lson].size) {
    return QueryMin(sgt[now].lson, left, ((left + right) >> 1));
  } else {
    return QueryMin(sgt[now].rson, ((left + right) >> 1) + 1, right);
  }
}
int main() {
  Read(q);
  int cnt = 0;
  for (int i = 1; i <= q; ++i) {
    Read(opt[i], num[i]);
    if (0 < num[i]) {
      sor[++cnt] = num[i];
    }
  }
  sort(sor + 1, sor + 1 + cnt);
  for (int i = 1; i <= cnt; ++i) {
    if (sor[i] ^ sor[i - 1]) {
      Hash[sor[i]] = ++len;
      number[len] = sor[i];
    }
  }
  int root1 = 0, root2 = 0;
  long long sum1 = 0, sum2 = 0;
  for (int i = 1; i <= q; ++i) {
    if (opt[i] == 0) {
      if (0 < num[i]) {
        Updata(Hash[num[i]], 1, root2);
        ++n;
      } else {
        Updata(Hash[-num[i]], -1, root2);
        --n;
      }
      sum1 += num[i];
    }
    if (opt[i] == 1) {
      if (0 < num[i]) {
        int h = Hash[num[i]];
        Updata(h, 1, root2);
        Updata(h, 1, root1);
        ++m;
      } else {
        int h = Hash[-num[i]];
        Updata(h, -1, root2);
        Updata(h, -1, root1);
        --m;
      }
      sum2 += num[i];
    }
    if (!n) {
      if (!m) {
        Writeln(0);
      } else {
        if (m == 1) {
          Writeln(sum2);
        } else {
          Writeln(sum2 + Query(m - 1, root1));
        }
      }
    } else {
      int mi = 0;
      if (m) {
        mi = QueryMin(root1);
        Updata(mi, -1, root2);
      }
      Writeln((m ? Query(m, root2) : 0) + sum1 + sum2);
      if (m) {
        Updata(mi, 1, root2);
      }
    }
  }
  return 0;
}
