#include<bits/stdc++.h>
using namespace std;
int m , t;
int a , b;
int x[1001000];
int main(void)
{
memset(x , 0 , sizeof(x));
long long int sum = 0;;
int ret = 0;
scanf("%d" , &m);
for (int i = 1 ; i <= m ; i++)
{
sum += x[i];
scanf("%d" , &t);
if (t == 1)
{
scanf("%d" , &a);
sum += a;
}
else if (t == 2)
{
scanf("%d" , &a);
if ((sum - a) < 0)
{
ret++;
}
else
{
sum -= a;
}
}
else if (t == 3)
{
scanf("%d%d" , &a , &b);
x[b] += a;
sum -= a;
}
}
printf("%d" , ret);
return 0;
}