#include <bits/stdc++.h>
using namespace std;
struct ticket {
int price;
int time;
bool u;
} a[10000];
int main() {
int n,use=0,h=0,d=0;
int by;
int p,t;
cin>>n;
for (int i = 0; i < n; ++i) {
cin>>by>>p>>t;
if (by) {
while(1) {
if (a[d].price>=p && a[d].u==1 && (t-a[d].time)) {
a[d].u=0;
d=0;
break;
}
if (d>=h) {
d=0;
use+=p;
break;
}
d++;
}
} else {
use+=p;
a[h].time=t;
a[h].u=1;
h++;
}
}
cout<<use;
return 0;
}