#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
struct piao{
int t,m;
bool used;
}p[N];
int n,ans,tot;
int a,b,c;
signed main(){
// freopen("transfer.in","r",stdin);
// freopen("transfer.out","w",stdout);
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld%lld%lld",&a,&b,&c);
if(a==0){
ans+=b;
p[++tot].t=c,p[tot].m=b;
}
if(a==1){
int js=-1;
for(int j=tot;j>=-1&&c-p[j].t<=45;j--){
if(p[j].m>=b&&!p[j].used){
js=j;
}
}
if(js>=0){
// cout<<"QAQ "<<js<<endl;
p[js].used=1;
}
else {
ans+=b;
}
}
}
printf("%lld\n",ans);
return 0;
}
/*
6
0 10 3
1 5 46
0 12 50
1 3 96
0 5 110
1 6 135
*/