#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
struct node{
int time;
int price;
bool used=false;
}m[100000];
signed main(){
cin>>n;
int sum=0,p=0;
while(n--){
int tran;
cin>>tran;
if(tran==0){
int price,ts;
cin>>price>>ts;
m[p].price=price;
m[p].time=ts;
p++;
sum+=price;
}
if(tran==1){
int price,tb;
cin>>price>>tb;
for(int i=0;i<p;i++){
if(!m[i].used&&tb-m[i].time<=45&&price<=m[i].price){
m[i].used=true;
continue;
}
}
sum+=price;
}
}
cout<<sum;
return 0;
}