output_description: Print the maximum possible sum of the values of the blocks contained in the
  tower.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      w_1 s_1 v_1
      w_2 s_2 v_2
      :
      w_N s_N v_N
attempt: # -*- coding: utf-8 -*-
  
  #############
  # Libraries #
  #############
  
  import sys
  
  input = sys.stdin.readline
  
  import math
  
  # from math import gcd
  import bisect
  import heapq
  from collections import defaultdict
  from collections import deque
  from collections import Counter
  from functools import lru_cache
  
  #############
  # Constants #
  #############
  
  MOD = 10**9 + 7
  INF = float("inf")
  AZ = "abcdefghijklmnopqrstuvwxyz"
  
  #############
  # Functions #
  #############
  
  
  ######INPUT######
  def I():
      return int(input().strip())
  
  
  def S():
      return input().strip()
  
  
  def IL():
      return list(map(int, input().split()))
  
  
  def SL():
      return list(map(str, input().split()))
  
  
  def ILs(n):
      return list(int(input()) for _ in range(n))
  
  
  def SLs(n):
      return list(input().strip() for _ in range(n))
  
  
  def ILL(n):
      return [list(map(int, input().split())) for _ in range(n)]
  
  
  def SLL(n):
      return [list(map(str, input().split())) for _ in range(n)]
  
  
  #####Shorten#####
  def DD(arg):
      return defaultdict(arg)
  
  
  #####Inverse#####
  def inv(n):
      return pow(n, MOD - 2, MOD)
  
  
  ######Combination######
  kaijo_memo = []
  
  
  def kaijo(n):
      if len(kaijo_memo) > n:
          return kaijo_memo[n]
      if len(kaijo_memo) == 0:
          kaijo_memo.append(1)
      while len(kaijo_memo) <= n:
          kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
      return kaijo_memo[n]
  
  
  gyaku_kaijo_memo = []
  
  
  def gyaku_kaijo(n):
      if len(gyaku_kaijo_memo) > n:
          return gyaku_kaijo_memo[n]
      if len(gyaku_kaijo_memo) == 0:
          gyaku_kaijo_memo.append(1)
      while len(gyaku_kaijo_memo) <= n:
          gyaku_kaijo_memo.append(
              gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
          )
      return gyaku_kaijo_memo[n]
  
  
  def nCr(n, r):
      if n == r:
          return 1
      if n < r or r < 0:
          return 0
      ret = 1
      ret = ret * kaijo(n) % MOD
      ret = ret * gyaku_kaijo(r) % MOD
      ret = ret * gyaku_kaijo(n - r) % MOD
      return ret
  
  
  ######Factorization######
  def factorization(n):
      arr = []
      temp = n
      for i in range(2, int(-(-(n**0.5) // 1)) + 1):
          if temp % i == 0:
              cnt = 0
              while temp % i == 0:
                  cnt += 1
                  temp //= i
              arr.append([i, cnt])
      if temp != 1:
          arr.append([temp, 1])
      if arr == []:
          arr.append([n, 1])
      return arr
  
  
  #####MakeDivisors######
  def make_divisors(n):
      divisors = []
      for i in range(1, int(n**0.5) + 1):
          if n % i == 0:
              divisors.append(i)
              if i != n // i:
                  divisors.append(n // i)
      return divisors
  
  
  #####MakePrimes######
  def make_primes(N):
      max = int(math.sqrt(N))
      seachList = [i for i in range(2, N + 1)]
      primeNum = []
      while seachList[0] <= max:
          primeNum.append(seachList[0])
          tmp = seachList[0]
          seachList = [i for i in seachList if i % tmp != 0]
      primeNum.extend(seachList)
      return primeNum
  
  
  #####GCD#####
  def gcd(a, b):
      while b:
          a, b = b, a % b
      return a
  
  
  #####LCM#####
  def lcm(a, b):
      return a * b // gcd(a, b)
  
  
  #####BitCount#####
  def count_bit(n):
      count = 0
      while n:
          n &= n - 1
          count += 1
      return count
  
  
  #####ChangeBase#####
  def base_10_to_n(X, n):
      if X // n:
          return base_10_to_n(X // n, n) + [X % n]
      return [X % n]
  
  
  def base_n_to_10(X, n):
      return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
  
  
  def base_10_to_n_without_0(X, n):
      X -= 1
      if X // n:
          return base_10_to_n_without_0(X // n, n) + [X % n]
      return [X % n]
  
  
  #####IntLog#####
  def int_log(n, a):
      count = 0
      while n >= a:
          n //= a
          count += 1
      return count
  
  
  #############
  # Main Code #
  #############
  
  N = I()
  data = ILL(N)
  data.sort(lambda x: x[0] + x[1])
  wmax = 22000
  dp = [0 for w in range(wmax)]
  
  for i in range(N):
      w, s, v = data[i]
      for j in range(s + 1)[::-1]:
          dp[j + w] = max(dp[j + w], dp[j] + v)
  print(max(dp))
  
problem_description: Statement
  
  There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
  Block i has a weight of w_i, a solidness of s_i and a value of v_i.
  
  Taro has decided to build a tower by choosing some of the N blocks and
  stacking them vertically in some order. Here, the tower must satisfy the
  following condition:
  
    * For each Block i contained in the tower, the sum of the weights of the blocks stacked above it is not greater than s_i.
  
  Find the maximum possible sum of the values of the blocks contained in the
  tower.
samples: [{"input": "3\n    2 2 20\n    2 1 30\n    3 1 40", "output": "50\n    \n\nIf Blocks 2, 1 are stacked in this order from top to bottom, this tower will\nsatisfy the condition, with the total value of 30 + 20 = 50.\n\n* * *"}, {"input": "4\n    1 2 10\n    3 1 10\n    2 4 10\n    1 6 10", "output": "40\n    \n\nBlocks 1, 2, 3, 4 should be stacked in this order from top to bottom.\n\n* * *"}, {"input": "5\n    1 10000 1000000000\n    1 10000 1000000000\n    1 10000 1000000000\n    1 10000 1000000000\n    1 10000 1000000000", "output": "5000000000\n    \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "8\n    9 5 7\n    6 2 7\n    5 7 3\n    7 8 8\n    1 9 6\n    3 3 3\n    4 1 7\n    4 5 5", "output": "22\n    \n\nWe should, for example, stack Blocks 5, 6, 8, 4 in this order from top to\nbottom."}]