#include<bits/stdc++.h>
using namespace std;
#define int long long
#define die(x) return cout << x << endl, 0
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
const int MAXN=4100000+30,MAX_LOG=40,INF=1e18+10,MOD=1e9+7;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }
int max(int x,int y){ return (x>y?x:y); }
int power(int x,int y){
if(y==0)return 1;
int c=power(x,y/2);
c=(c*c)%MOD;
if(y%2)c=(c*x)%MOD;
return c;
}
int n, m;
// int holes[MAXN];
// int coins[MAXN];
// int a[MAXN];
vector<vector<int>> boxes;
int box_order[2100];
int best_height[MAXN];
bool compare(int first, int second){
return boxes[first][0] + boxes[first][1] < boxes[second][0] + boxes[second][1];
}
int MAIN(){
cin>>n;
boxes.assign(n, vector<int>(3));
for(int i=0; i<n; i++){
cin >> boxes[i][0] >> boxes[i][1] >> boxes[i][2];
box_order[i] = i;
}
sort(box_order, box_order + n, compare);
for(int i=0; i<MAXN; i++)best_height[i] = -INF;
best_height[0] = 0;
int total_weight = 0;
int answer = 0;
for(int i=0; i<n; i++){
int box = box_order[i];
for(int weight=total_weight; weight>=0; weight--){
if(best_height[weight] >= 0 && weight <= boxes[box][1]){
int new_weight = weight + boxes[box][0]
best_height[new_weight]= max(best_height[new_weight], best_height[weight] + boxes[box][2]);
answer = max(answer, best_height[new_weight]);
}
}
total_weight+= boxes[box][0];
}
cout<<answer<<endl;
return 0;
}
int32_t main(){
IOS;
int t=1;
// cin>>t;
while(t--)MAIN();
return 0;
}