#include<iostream>
using namespace std;
struct card
{
int t,v;
}a[100010];
int main()
{
int n,i,j,x,y,z,k=0,ans=0,kk=0;
cin>>n;
while(n--)
{
cin>>x>>y>>z;
if(x==0)
{
a[++k].v=y;
a[k].t=z;
ans+=y;
}
else
{
bool b=1;
for(i=kk;i<=k;i++)
if(((z-a[i].t)<=45)&&(a[i].v>=y))
{
b=0;
break;
}
else kk=i;
if(b)
ans+=y;
}
}
cout<<ans;
return 0;
}