#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;

struct Fenwick_tree {
    ll t[MAXN];

    Fenwick_tree() {
        memset(t, 0, sizeof t);
    }

    void upd(int pos, ll val) {
        for (; pos < MAXN; pos = (pos | (pos + 1))) {
            t[pos] = max(t[pos], val);
        }
    }

    ll get(int r) {
        ll res = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1) {
            res = max(res, t[r]);
        }
        return res;
    }
};

typedef vector<vector<ll> > matrix;

ll SQR = 1ll * mod * mod;

void add_sqr(ll &a, ll val) {
    a += val;
    if (a >= SQR)
        a -= SQR;
}

matrix mult(matrix &a, matrix &b) {
    int n = sz(a);
    int m = sz(b[0]);
    int k = sz(a[0]);
    assert(sz(a[0]) == sz(b));
    matrix res(n, vector<ll>(m));
    for (int i = 0; i < n; ++i) {
        for (int e = 0; e < m; ++e) {
            ll val = 0;
            for (int j = 0; j < k; ++j) {
                add_sqr(val, a[i][j] * b[j][e]);
            }
            res[i][e] = val % mod;
        }
    }
    return res;
}

matrix bin_pow(matrix &a, ll n) {
    matrix res(sz(a), vector<ll>(sz(a)));
    for (int i = 0; i < sz(a); ++i) {
        res[i][i] = 1;
    }

    while (n) {
        if (n & 1) {
            res = mult(res, a);
        }
        a = mult(a, a);
        n >>= 1;
    }
    return res;
}

int w[MAXN], s[MAXN], v[MAXN];
ll dp[1001][10001];

int get(int a,int b){
    int res = max(v[a],v[b]);
    if(s[b] >= w[a]){
        res = v[a] + v[b];
    }
    dout << a<<" "<<b    <<" : "<<res<<endl;
    return res;
}

bool comp(int a,int b){
    return w[a] + s[a] < w[b] + s[b];
}

void solve() {
    int n;
    cin >> n;
    vector<int> c;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> s[i] >> v[i];
        c.pb(i);
    }
    sort(all(c), comp);
    for(int v:c){
        dout << v <<" ";
    }
    dout << endl;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int id = c[i];
        dout << id<<" : "<<" "<<v[id]<<endl;
        if (i == 0) {
            for (int j = w[id]; j <= 10000; ++j) {
                dp[i][j] = v[id];
            }
            ans = v[id];
        } else {
            for (int j = 0; j <= 10000; ++j) {
                dp[i][j] = dp[i - 1][j];
                if (j >= w[id] && s[id] >= j - w[id]) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - w[id]] + v[id]);
                    ans = max(ans, dp[i][j]);
                }
                if(j <= s[id]){
                    ans = max(ans, dp[i-1][j] + v[id]);
                }
            }
            for (int j = 1; j <= 10000; ++j) {
                dp[i][j] = max(dp[i][j - 1], dp[i][j]);
            }
        }
    }
    cout << ans << "\n";
}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 80256