from sys import stdin, stdout, setrecursionlimit

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from functools import lru_cache

import math



setrecursionlimit(10**6)

rl = lambda: stdin.readline()

rll = lambda: stdin.readline().split()

rli = lambda: list(map(int, stdin.readline().split()))

rlf = lambda: list(map(float, stdin.readline().split()))



INF, NINF = float('inf'), float('-inf')

MOD = 10**9 + 7



def main():

	n = int(rl())

	A = []

	for _ in range(n):

		w, s, v = rli()

		A.append((w, s, v))

	ans = 0

	A.sort(key = lambda I: (I[0] + I[1]))

	maxs = 2*10**4 + 100

	dp = [0 for _ in range(maxs+1)]

	for w, s, v in A:

		for i in range(maxs, -1, -1):

			if i - w < 0: continue

			if i - w > s: continue

			dp[i] = max(dp[i], dp[i-w] + v)

			ans = max(ans, dp[i])	

	print(ans)

	stdout.close()



if __name__ == "__main__":

	main()
from sys import stdin, stdout, setrecursionlimit

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from functools import lru_cache

import math



setrecursionlimit(10**6)

rl = lambda: stdin.readline()

rll = lambda: stdin.readline().split()

rli = lambda: list(map(int, stdin.readline().split()))

rlf = lambda: list(map(float, stdin.readline().split()))



INF, NINF = float('inf'), float('-inf')

MOD = 10**9 + 7



def main():

	n = int(rl())

	A = []

	mw, ms = 0, 0

	for _ in range(n):

		w, s, v = rli()

		mw, ms = max(mw, w), max(ms, s)

		A.append((w, s, v))

	ans = 0

	A.sort(key = lambda I: (I[0] + I[1]))

	maxs = mw + ms + 100

	dp = [0 for _ in range(maxs+1)]

	for w, s, v in A:

		for i in range(maxs, -1, -1):

			if i - w < 0: break

			if i - w > s: continue

			dp[i] = max(dp[i], dp[i-w] + v)

			ans = max(ans, dp[i])	

	print(ans)

	stdout.close()



if __name__ == "__main__":

	main()
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7


def main():
    n = int(rl())
    A = []
    for _ in range(n):
        w, s, v = rli()
        A.append((w, s, v))
    ans = 0
    A.sort(key=lambda I: (I[0] + I[1]))
    maxs = 2 * 10**4 + 100
    dp = [0 for _ in range(maxs + 1)]
    for w, s, v in A:
        for i in range(maxs, -1, -1):
            if i - w < 0:
                continue
            if i - w > s:
                continue
            dp[i] = max(dp[i], dp[i - w] + v)
            ans = max(ans, dp[i])
    print(ans)
    stdout.close()


if __name__ == "__main__":
    main()

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7


def main():
    n = int(rl())
    A = []
    mw, ms = 0, 0
    for _ in range(n):
        w, s, v = rli()
        mw, ms = max(mw, w), max(ms, s)
        A.append((w, s, v))
    ans = 0
    A.sort(key=lambda I: (I[0] + I[1]))
    maxs = mw + ms + 100
    dp = [0 for _ in range(maxs + 1)]
    for w, s, v in A:
        for i in range(maxs, -1, -1):
            if i - w < 0:
                break
            if i - w > s:
                continue
            dp[i] = max(dp[i], dp[i - w] + v)
            ans = max(ans, dp[i])
    print(ans)
    stdout.close()


if __name__ == "__main__":
    main()

+    mw, ms = 0, 0 +        mw, ms = max(mw, w), max(ms, s) -    maxs = 2 * 10**4 + 100 +    maxs = mw + ms + 100 -                continue +                break