import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 18446744073709551615 # inf = 4294967295 # md = 10**9+7 md = 998244353 class Bit: def __init__(self, op, e, n): self.op = op self.e = e self.n = n+1 self.table = [e() for _ in range(self.n)] def update(self, i, x): i += 1 while i < self.n: self.table[i] = self.op(self.table[i], x) i += i & -i # [0,i] def prod(self, i): i += 1 res = self.e() while i > 0: res = self.op(res, self.table[i]) i -= i & -i return res n = II() txv = LLI(n) st = set() st.add(0) for t, x, v in txv: st.add(t-x) enc = {a: i for i, a in enumerate(sorted(st))} txv.sort(key=lambda x: (x[0]+x[1], x[0]-x[1])) bit = Bit(max, lambda: -inf, n+5) i = enc[0] bit.update(i, 0) for t, x, v in txv: if t+x < 0: continue i = enc[t-x] cur = bit.prod(i)+v bit.update(i, cur) print(bit.prod(n+4))