#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=3.1e5,SN=570;
inline LL read(){
LL x=0,ff=1;
char c=getchar();
while(!isdigit(c)&&c!='-') c=getchar();
if(c=='-') c=getchar(),ff=-1;
while(isdigit(c)) x=x*10ll+c-'0',c=getchar();
return x*ff;
}
int n,B;
int pos[N];
struct node{
int x,op,idd;
}t[N];
struct Block{
LL dp[SN*2];
int res[SN*2];
void build(int T,int l,int r){
int len=r-l+1;
for(int i=-len;i<=len;++i)
dp[i+SN]=0,res[i+SN]=i;
for(int i=l;i<=r;++i){
if(t[i].idd>T) continue;
for(int j=-len;j<=len;++j){
if(t[i].op==1){
if(res[j+SN]<0)
dp[j+SN]=dp[j+SN]+t[i].x;
res[j+SN]++;
}
else{
if(res[j+SN]>0)
dp[j+SN]=dp[j+SN]+t[i].x;
res[j+SN]--;
}
}
}
}
}T[SN];
bool cmp(const node& sa,const node& sb){
return sa.x<sb.x;
}
int idd(int x){
return (x-1)/B+1;
}
int main(){
int casecnt=1;
while(casecnt--){
n=read();
B=sqrt(n);
for(int i=1;i<=n;++i){ds
t[i].op=read()-1,t[i].x=read();
t[i].idd=i;
}
sort(t+1,t+n+1,cmp);
for(int i=1;i<=n;++i)
pos[t[i].idd]=i;
for(int i=1;i<=n;++i){
int w=idd(pos[i]);
T[w].build(i,(w-1)*B+1,min(w*B,n));
int now=0;
LL ans=0;
for(int i=1;i<=idd(n);++i){
int y=max(-B,min(B,now));
ans+=T[i].dp[B+SN];
now=T[i].res[B+SN]+now-y;
}
printf("%lld\n",ans);
}
}
return 0;
}