#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100005;
struct node{
int t, price;
bool used;
}q[MAXN];
int main()
{
long long n;
long long sum = 0;
cin >> n;
long long head = 0, tail = 0;
while(n--){
long long x, y, z;
cin >> x >> y >> z;
while((z - q[head].t) > 45) head++;
if(x == 0){
q[tail].t = z, q[tail].price = y, q[tail].used = false;
tail++;
}
else{
for(long long i = head;i < tail;i++)
if(q[i].price >= y && !q[i].used){
y = 0;
q[i].used = true;
break;
}
}
sum += y;
}
cout << sum;
return 0;
}