#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
struct node{
int p, ti;
};
short n;
vector<node> pr;
unsigned long long ans = 0;
int f_xb;
int main(){
scanf("%d", &n);
bool type; int price, t;
cin >> type >> price >> t;
if(!type){
node pp;
pp.p = price; pp.ti = t;
pr.push_back(pp);
ans += price;
}
else{
bool flag = true;
for(int i = f_xb; i<pr.size(); i++){
if(t - pr[i].ti > 45) f_xb++;
if(t - pr[i].ti <= 45 && pr[i].p > price){
flag = false;
break;
}
}
if(flag){
ans += price;
}
}
}
cout << ans << endl;
return 0;
}