#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 31;
struct DB
{
int w, v, t;
bool operator< (const DB &d) const
{
return t < d.t;
}
}dbs[N];
int dp[N]; // dp[j] 表示j时刻结束一场狂欢能够获得最大的快乐度
int main() {
int n;
while(cin >> n && n > 0)
{
int ans = 0;
memset(dp, 0, sizeof dp); //初始化dp数组
for(int i = 0; i < n; i ++)
{
cin >> dbs[i].w >> dbs[i].v >> dbs[i].t;
}
sort(dbs, dbs + n); //按照离开时间升序,每个人只能使用 0 ~ t 这段时间狂欢
for(int i = 0; i < n; i ++)
{
int w = dbs[i].w, v = dbs[i].v, t = dbs[i].t;
for(int j = t; j >= v; j --)
{
dp[j] = max(dp[j], dp[j - v] + w);
ans = max(ans, dp[j]);
}
}
cout << ans << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")