#include <iostream>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <cstring>
#include <string.h>
#include <cmath>
#include <string>
#include <sstream>
#include <cctype>
#include <iomanip>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
// Mang tien to
ll prefixSum[N];
// deque luu cac gia tri co the thoa truy vanvan
deque<pair<ll, int>> arr;
// Xac dinh phan tu duoc themthem
bool flag;
// Chi so hien tai
int cur = 0;
// Chi so bat daudau
int idxDelete = 0;
void insertValue(int x)
{
// Neu phan tu duoc them la am thi danh dau lai
if (x < 0) {
flag = false;
}
else {
flag = true;
}
prefixSum[cur + 1] = prefixSum[cur] + x;
// Duy tri 1 mang giam dan
while (!arr.empty() && arr.back().first <= prefixSum[cur + 1]) {
arr.pop_back();
}
// Them vao mang phan tu do
arr.emplace_back(prefixSum[cur + 1], cur + 1);
++cur;
}
void deleteFromFront() {
// Moi la xoa chi xoa 1 phan tu
if (arr.front().second == idxDelete) {
arr.pop_front();
}
// Tang chi so bat dau len
++idxDelete;
}
int findLongestNonNegativeSuffix()
{
// Neu phan tu am thi khong ton tai mang thoa mang -> Tra ve 0
if (!flag) {
return 0;
}
// So phan tu cua mang luon >= 1
// Neu bang 1 thi khong the mo rong them ve phia ben trai -> Tra ve chieu dai mang
if (arr.size() == 1) {
return arr.back().second - idxDelete;
}
int size = arr.size();
// Tra ve chieu dai ma trong mang nam o ben trai gan nhat cua mang
return cur - arr[size - 2].second - 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// Khoi tao
prefixSum[0] = 0;
arr.emplace_back(0, 0);
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int op;
cin >> op;
if (op == 1) {
int x;
cin >> x;
insertValue(x);
}
else if (op == 2) {
deleteFromFront();
}
else if (op == 3) {
int ans = findLongestNonNegativeSuffix();
cout << ans << '\n';
}
}
return 0;
}