#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define maxn 35
using namespace std;
typedef struct BG{
int h;
int l;
int t;
}Bg;
Bg bg[maxn];
// int h[maxn],l[maxn],t[maxn];
int dp[maxn];//在剩余的i时间获得的最多快乐度
bool cmp(Bg b1,Bg b2)
{
return b1.t<b2.t;
}
int main() {
int N;
while(cin>>N&&N!=-1)
{
int maxx = 0;
for(int i=0;i<N;i++)cin>>bg[i].h>>bg[i].l>>bg[i].t;
memset(dp,0,sizeof(dp));
sort(bg,bg+N,cmp);
for(int i=0;i<N;i++)
{
for(int j=bg[i].t;j>=bg[i].l;j--)
{
dp[j] = max(dp[j],dp[j-bg[i].l]+bg[i].h);
maxx = max(dp[j],maxx);
}
}
cout<<maxx<<endl;
}
}
// 64 位输出请用 printf("%lld")