#include<iostream>
using namespace std;
struct subway
{
int p , t;
}; subway a[10000];
int n , x , y , z , h , ans , fst , flag;
int main()
{
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> x >> y >> z;
if(x == 0) {
a[h].p = y; a[h].t = z;
h++; ans += y;
} else {
flag = 0;
for(int j = fst; j < h; ++j) {
if(z - a[j].t <= 45 && y <= a[j].p) {
a[j].p = -1;
flag = 1; break;
} else if(z - a[j].t > 45) {
fst = j + 1;
}
}
if(flag == 0) ans += y;
}
}
cout << ans;
return 0;
}