#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int inf = 0x7FFFFFFF;
const int maxn = 60;
int N;
struct Pro{
int bene, last, dead;
void read(){
scanf("%d%d%d", &bene, &last, &dead);
}
bool operator < (const Pro p)const{
return dead < p.dead;
}
}pro[maxn];
int dp[maxn][1010];
int dfs(int i, int now){
if(dp[i][now] >= 0) return dp[i][now];
if(i == N) return dp[i][now] = 0;
int sum1 = 0, sum2 = 0;
if(pro[i].dead - now >= pro[i].last){
sum1 = dfs(i+1, now+pro[i].last) + pro[i].bene;
}
sum2 = dfs(i+1, now);
return dp[i][now] = max(sum1, sum2);
}
int main(){
scanf("%d", &N);
for(int i = 0; i < N; i++) pro[i].read();
sort(pro, pro + N);
memset(dp, -1, sizeof(dp));
printf("%d\n", dfs(0, 0));
return 0;
}