#include <bits/stdc++.h>
#include <queue>
using namespace std;
struct bus{
int price,times;
};
int n,prices,counting,starting;
bus all[100010];
int main(){
starting,counting=1;
cin>>n;
for(int i=1;i<=n;i++){
int a,b,c;
bool flag=true;
cin>>a>>b>>c;
if(a==0){
all[counting]={b,c};
counting++;
prices+=b;
continue;
}
if(a==1){
for(int j=starting;j<=counting;j++){
if(b<=all[j].price && c-all[j].times<=45){
starting++;
flag=false;
break;
}
}
}
if(flag) prices+=b;
}
cout<<prices;
return 0;
}