CSES - Shared codeLink to this code: https://cses.fi/paste/98f2c0b4158a19e6516fb0/
import bisect
from sys import stdin
input = stdin.readline

n = int(stdin.readline())

projects = []
for _ in range(n):
    startDate, endDate, reward = [int(x) for x in stdin.readline().split()]
    projects.append((startDate, endDate, reward))

projects.sort(key = lambda x : x[1])

startDates = list(map(lambda x: x[0], projects))
endDates = list(map(lambda x: x[1], projects))
rewards = list(map(lambda x: x[2], projects))

maxMoney = [0] * n
maxMoney[0] = rewards[0]

for i in range(1, n):
    pos = bisect.bisect_right(endDates, startDates[i] - 1)
    if pos > 0:
        val = maxMoney[pos-1] + rewards[i]
    else:
        val = rewards[i]
    maxMoney[i] = max(val, maxMoney[i-1])

print(maxMoney[n - 1])