#include <bits/stdc++.h>
using namespace std;
long long n,b[200001],c[200001],sum=0;
bool a[10000001];
int main(){
cin>>n;
for(int i=1;i<=45;i++){
a[i]=1;
b[i]=1;
c[i]=1;
}
for(int i=46;i<=n+45;i++) cin>>a[i]>>b[i]>>c[i];
sum+=b[46];
for(int i=47;i<=n+45;i++){
if(a[i-45]==0&&a[i]==1&&b[i]<=b[i-45]&&c[i]-c[i-45]<=45){
a[i-45]=1;
continue;
}
if(a[i-44]==0&&a[i]==1&&b[i]<=b[i-44]&&c[i]-c[i-44]<=45){
a[i-44]=1;
continue;
}
if(a[i-43]==0&&a[i]==1&&b[i]<=b[i-43]&&c[i]-c[i-43]<=45){
a[i-43]=1;
continue;
}
if(a[i-42]==0&&a[i]==1&&b[i]<=b[i-42]&&c[i]-c[i-42]<=45){
a[i-42]=1;
continue;
}
if(a[i-41]==0&&a[i]==1&&b[i]<=b[i-41]&&c[i]-c[i-41]<=45){
a[i-41]=1;
continue;
}
if(a[i-40]==0&&a[i]==1&&b[i]<=b[i-40]&&c[i]-c[i-40]<=45){
a[i-40]=1;
continue;
}
if(a[i-39]==0&&a[i]==1&&b[i]<=b[i-39]&&c[i]-c[i-39]<=45){
a[i-39]=1;
continue;
}
if(a[i-38]==0&&a[i]==1&&b[i]<=b[i-38]&&c[i]-c[i-38]<=45){
a[i-38]=1;
continue;
}
if(a[i-37]==0&&a[i]==1&&b[i]<=b[i-37]&&c[i]-c[i-37]<=45){
a[i-37]=1;
continue;
}
if(a[i-36]==0&&a[i]==1&&b[i]<=b[i-36]&&c[i]-c[i-36]<=45){
a[i-36]=1;
continue;
}
if(a[i-35]==0&&a[i]==1&&b[i]<=b[i-35]&&c[i]-c[i-35]<=45){
a[i-35]=1;
continue;
}
if(a[i-34]==0&&a[i]==1&&b[i]<=b[i-34]&&c[i]-c[i-34]<=45){
a[i-34]=1;
continue;
}
if(a[i-33]==0&&a[i]==1&&b[i]<=b[i-33]&&c[i]-c[i-33]<=45){
a[i-33]=1;
continue;
}
if(a[i-32]==0&&a[i]==1&&b[i]<=b[i-32]&&c[i]-c[i-32]<=45){
a[i-32]=1;
continue;
}
if(a[i-31]==0&&a[i]==1&&b[i]<=b[i-31]&&c[i]-c[i-31]<=45){
a[i-31]=1;
continue;
}
if(a[i-30]==0&&a[i]==1&&b[i]<=b[i-30]&&c[i]-c[i-30]<=45){
a[i-30]=1;
continue;
}
if(a[i-29]==0&&a[i]==1&&b[i]<=b[i-29]&&c[i]-c[i-29]<=45){
a[i-29]=1;
continue;
}
if(a[i-28]==0&&a[i]==1&&b[i]<=b[i-28]&&c[i]-c[i-28]<=45){
a[i-28]=1;
continue;
}
if(a[i-27]==0&&a[i]==1&&b[i]<=b[i-27]&&c[i]-c[i-27]<=45){
a[i-27]=1;
continue;
}
if(a[i-26]==0&&a[i]==1&&b[i]<=b[i-26]&&c[i]-c[i-26]<=45){
a[i-26]=1;
continue;
}
if(a[i-25]==0&&a[i]==1&&b[i]<=b[i-25]&&c[i]-c[i-25]<=45){
a[i-25]=1;
continue;
}
if(a[i-24]==0&&a[i]==1&&b[i]<=b[i-24]&&c[i]-c[i-24]<=45){
a[i-24]=1;
continue;
}
if(a[i-23]==0&&a[i]==1&&b[i]<=b[i-23]&&c[i]-c[i-23]<=45){
a[i-23]=1;
continue;
}
if(a[i-22]==0&&a[i]==1&&b[i]<=b[i-22]&&c[i]-c[i-22]<=45){
a[i-22]=1;
continue;
}
if(a[i-21]==0&&a[i]==1&&b[i]<=b[i-21]&&c[i]-c[i-21]<=45){
a[i-21]=1;
continue;
}
if(a[i-20]==0&&a[i]==1&&b[i]<=b[i-20]&&c[i]-c[i-20]<=45){
a[i-20]=1;
continue;
}
if(a[i-19]==0&&a[i]==1&&b[i]<=b[i-19]&&c[i]-c[i-19]<=45){
a[i-19]=1;
continue;
}
if(a[i-18]==0&&a[i]==1&&b[i]<=b[i-18]&&c[i]-c[i-18]<=45){
a[i-18]=1;
continue;
}
if(a[i-17]==0&&a[i]==1&&b[i]<=b[i-17]&&c[i]-c[i-17]<=45){
a[i-17]=1;
continue;
}
if(a[i-16]==0&&a[i]==1&&b[i]<=b[i-16]&&c[i]-c[i-16]<=45){
a[i-16]=1;
continue;
}
if(a[i-15]==0&&a[i]==1&&b[i]<=b[i-15]&&c[i]-c[i-15]<=45){
a[i-15]=1;
continue;
}
if(a[i-14]==0&&a[i]==1&&b[i]<=b[i-14]&&c[i]-c[i-14]<=45){
a[i-14]=1;
continue;
}
if(a[i-13]==0&&a[i]==1&&b[i]<=b[i-13]&&c[i]-c[i-13]<=45){
a[i-13]=1;
continue;
}
if(a[i-12]==0&&a[i]==1&&b[i]<=b[i-12]&&c[i]-c[i-12]<=45){
a[i-12]=1;
continue;
}
if(a[i-11]==0&&a[i]==1&&b[i]<=b[i-11]&&c[i]-c[i-11]<=45){
a[i-11]=1;
continue;
}
if(a[i-10]==0&&a[i]==1&&b[i]<=b[i-10]&&c[i]-c[i-10]<=45){
a[i-10]=1;
continue;
}
if(a[i-9]==0&&a[i]==1&&b[i]<=b[i-9]&&c[i]-c[i-9]<=45){
a[i-9]=1;
continue;
}
if(a[i-8]==0&&a[i]==1&&b[i]<=b[i-8]&&c[i]-c[i-8]<=45){
a[i-8]=1;
continue;
}
if(a[i-7]==0&&a[i]==1&&b[i]<=b[i-7]&&c[i]-c[i-7]<=45){
a[i-7]=1;
continue;
}
if(a[i-6]==0&&a[i]==1&&b[i]<=b[i-6]&&c[i]-c[i-6]<=45){
a[i-6]=1;
continue;
}
if(a[i-5]==0&&a[i]==1&&b[i]<=b[i-5]&&c[i]-c[i-5]<=45){
a[i-5]=1;
continue;
}
if(a[i-4]==0&&a[i]==1&&b[i]<=b[i-4]&&c[i]-c[i-4]<=45){
a[i-4]=1;
continue;
}
if(a[i-3]==0&&a[i]==1&&b[i]<=b[i-3]&&c[i]-c[i-3]<=45){
a[i-3]=1;
continue;
}
if(a[i-2]==0&&a[i]==1&&b[i]<=b[i-2]&&c[i]-c[i-2]<=45){
a[i-2]=1;
continue;
}
if(a[i-1]==0&&a[i]==1&&b[i]<=b[i-1]&&c[i]-c[i-1]<=45){
a[i-1]=1;
continue;
}
sum+=b[i];
}
cout<<sum;
return 0;
}