from bisect import * N = int(input()) A = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda x: (x[0],-x[1])) P = [0]*N G = [0]*N t = sorted(range(N), key=lambda x: A[x][1]) x = -1 for i in range(N)[::-1]: j = t[i] P[j] = i if x>=0 and A[j][1]==A[x][1]: G[j] = G[x] else: G[j] = i+1 x = j B = [0]*(N+2) def U(i, v): while i <= N: B[i] = max(B[i], v) i += i&-i def Q(i): v = 0 while i > 0: v = max(v, B[i]) i -= i&-i return v for i in range(N)[::-1]: _, b, c = A[i] j = N-G[i] v = Q(j) j = N-P[i] U(j, v+c) print(max(B))