链表思想求调
/*
*/
#include<bits/stdc++.h>
#define r read()
#define ll long long
#define MAX 0x3f3f3f3f
#define MIN -0x3f3f3f3f
using namespace std;
ll read();
int n,d,sx;
bool xx;
struct a1{
int t,p,q,h;
}s[100010];
ll read(){
int dx=0,x=1;
char xx=getchar();
for(;xx<'0'||xx>'9';xx=getchar())
if(xx=='-')
x=-1;
for(;xx>='0'&&xx<='9';dx=dx*10+xx-48,xx=getchar());
return dx*x;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
n=r;
for(int i=1;i<=n;i++){
xx=r;
switch(xx){
case 0:
s[sx+1].p=r;
d+=s[sx+1].p;
s[sx].h=sx+1;
s[sx+1].t=r;
s[sx+1].q=sx;
sx++;
break;
case 1:
int px=r,tx=r,dx;
bool xxx=0;
for(int sxx=sx;tx-s[sxx].t<=45;sxx=s[sxx].q)
if(s[sxx].p>=px){
dx=sxx;
xxx=1;
}
if(xxx){
s[s[dx].q].h=s[dx].h;
s[s[dx].h].q=s[dx].q;
}else
d+=px;
}
}
cout<<d;
return 0;
}