/// __Macro's__
#include <bits/stdc++.h>
using namespace std;
#define ll                   long long
#define ld                   long double
#define II                   pair<int,int>
#define LL                   pair<ll,ll>
#define III                  pair<int, II>
#define F                    first
#define S                    second
#define mkpr                 make_pair
#define VL                   vector<ll>
#define VB                   vector<bool>
#define VI                   vector<int>
#define VII                  vector<II>
#define VIII                 vector<III>
#define VVI                  vector<vector<int>>
#define VVII                 vector<vector<II>>
#define MII                  map<int, int>
#define SI                   set<int>
#define QI                   queue<int>
#define PQ                   priority_queue
#define PQI                  priority_queue<int>
#define tp(v)                v.top(), v.pop()
#define pb                   push_back
#define pf                   push_front
#define Pb                   pop_back
#define Pf                   pop_front
#define eb                  emplace_back
#define _all(v)              v.begin(), v.end()
#define _sort(v)             sort(_all(v))
#define __L                  p<<1, L, L+R>>1
#define __R                  p<<1|1, (L+R>>1)+1, R
#define gch()                getchar()
#define LINE                 putc('\n', stdout)
#define SPACE                putc(' ' , stdout)
#define TAB                  putc('\t', stdout)
#define _YES                 printf("YES")
#define _NO                  printf("NO")
#define _Yes                 printf("Yes")
#define _No                  printf("No")
#define _yes                 printf("yes")
#define _no                  printf("no")
#define _0                   printf("0")
#define _1                   printf("-1")
#define _outS(_)             printf("%s",_)
#define _outC(_)             printf("%c",_)
#define _out(_)              printf("%i",_)
#define _Fout(_)             (WriteInt(_))
#define _outLL(_)            printf("%lld",_)
#define _outI64d(_)          printf("%lld",_);
#define __out(_,__)          printf("%i %i",_,__)
#define __Fout(_,__)         (WriteInt(_), SPACE, WriteInt(__))
#define __outLL(_,__)        printf("%lld %lld",_,__)
#define ___out(_,__,___)     printf("%i %i %i",_,__,___)
#define ___Fout(_,__,___)    (WriteInt(_), SPACE, WriteInt(__), SPACE, WriteInt(___))
#define ___outLL(_,__,___)   printf("%lld %lld %lld",_,__,___)
#define _inS(_)              scanf("%s",_)
#define __inS(_, __)         scanf("%s%s",_,__)
#define _inC(_)              scanf("%c",&_)
#define _in(_)               scanf("%i", &_)
#define _Fin(_)              (_=ReadInt())
#define _inLL(_)             scanf("%lld", &_)
#define _inI64d(_)           scanf("%lld",_);
#define __in(_,__)           scanf("%i%i",&_,&__)
#define __Fin(_,__)          (_=ReadInt(), __=ReadInt())
#define __inLL(_,__)         scanf("%lld%lld",&_,&__)
#define ___in(_,__,___)      scanf("%i%i%i",&_,&__,&___)
#define ___Fin(_,__,___)     (_=ReadInt(), __=ReadInt(), ___=ReadInt())
#define ___inLL(_,__,___)    scanf("%lld%lld%lld",&_,&__,&___)
#define _S_(x)               #x
#define msg(x)               printf(_S_(x))
#define debug(x)             printf("--> Debuging : "), printf(_S_(x))
#define fastIO()             ios_base::sync_with_stdio(0);cin.tie(NULL);
#define _memset(_)           memset(_, -1, sizeof _)
#define _for(i, n)           for(int i	=0 ; i<n ; i++)
#define __for(i, j, n)       for(int i=j ; i<n ; i++)
#define FOR(i, condition)    for(int i=0 ; condition ; i++)
#define _rof(i, n)           for(int i=n ; i-- ;    )
#define __rof(i, j, n)       for(int i=n-1 ; i>=j ; i-- )
#define rm_imp(d, p)         (round(d*p)/p)
#define __lcm(a, b)          ((a*b)/__gcd(a,b))
#define _log2(x)             (31-__builtin_clz(x))
#define INF 1000000005
#define EPS 1e-9
#define MOD 1000000007
#define VISITED     1
#define UNVISITED  -1
#define EXPLORING   0
#define CYCLE       2
#define HEAD        3
#define END 7
inline int ReadInt(){
  int x=0,f=1;char ch=getchar();
  while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  return x*f;
}
inline void WriteInt(int x){
  char CH[20];
  int Num=0;if(!x){putchar('0');puts("");return;}
  while(x>0)CH[++Num]=x%10,x/=10;
  while(Num)putchar(CH[Num--]+48);
  puts("");
}
int aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz;
int tmp,cnt,ans,sum,rem;
int tc,ty;
///

struct block{
  ll w,s,v;
  bool operator <(block &other){
    //if(w+s!=other.w+other.s)
      return w+s<other.w+other.s;
    //return v<other.v;
  }
}A[1010];
ll n;
ll tab[1010][30100];
int main(){
  cin>>n;
  for(int i=1 ; i<=n ; i++) ___inLL(A[i].w, A[i].s, A[i].v);
  sort(A+1, A+n+1);
  for(int i=1 ; i<=n ; i++)
    for(ll j=0 ; j<30100 ; j++)
      tab[i][j] = max(tab[i-1][j], (A[i].w<=j ? A[i].v + tab[i-1][min(j-A[i].w, A[i].s)] : LLONG_MIN));
  _outLL(tab[n][30100-1]); LINE;
}


Measured memory_bytes: 235648