#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge {
int p, t;
};
vector<edge> vec;
int n, ans;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
int opt, p, t;
for (int i = 1; i <= n; ++i) {
cin >> opt >> p >> t;
if (opt == 0) {
ans += p;
vec.push_back({p, t});
}
else {
ans += p;
for (int j = 0; j < vec.size(); ++j) {
auto ti = vec[j];
int tp = ti.p, tt = ti.t;
if (tp >= p && t - tt <= 45) {
ans -= p;
vec.erase(vec.begin() + j);
break ;
}
else if(t - tt > 45) vec.erase(vec.begin() + j);
}
}
}
cout << ans;
return 0;
}