import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.Arrays;
public class Main 
{
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is) 
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }
    
    
    }
    static class Box
    {
        int w,s;
        long v;
        Box(int a,int b,long vv)
        {
            w=a;
            s=b;
            v=vv;
        }
    }
    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        Box b[]=new Box[n];
        for(int i=0;i<n;i++)
            b[i]=new Box(in.nextInt(),in.nextInt(),in.nextInt());
        //Arrays.sort(b,(p,q)->((p.w<=q.s)&&(q.w>p.s))?-1:((p.s>=q.w)&&(p.w>q.s))?1:Integer.compare(p.s, q.s));
        Arrays.sort(b,(p,q)->Integer.compare(p.s+p.w,q.s+q.w));
        long dp[]=new long[20001];
        
        for(int i=0;i<n;i++){
            
            for(int j=Math.min(20000,b[i].w+b[i].s);j>=b[i].w;j--)
                dp[j]=Math.max(dp[j],b[i].v+dp[j-b[i].w]);
            for(int j=1;j<=20000;j++)
                dp[j]=Math.max(dp[j],dp[j-1]);
        }
        out.println(dp[20000]);
        out.close();
    }

}


Measured memory_bytes: 27988