#include<bits/stdc++.h>
using namespace std;
int n,ditie[100001],a=0,ans=0,f;
struct transfer{
bool w;
int price;
int time;
}c[100001];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>c[i].w>>c[i].price>>c[i].time;
}
for(int i=1;i<=n;i++){
if(c[i].w==0){
ditie[++a]=i;ans+=c[i].price;
}
else {
int x=1;
f=0;
for(int j=x;j<=a;j++){
if(ditie[j]!=0&&c[i].time-c[ditie[j]].time<=45&&c[i].price<=c[ditie[j]].price){
ditie[j]=0;
f=1;
x++;
break;
}
}
if(f==0)ans+=c[i].price;
}
}
cout<<ans;
return 0;
}
35分,TLE,求大佬帮忙改改(蒟蒻献出膝盖)