import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### inf = -10**18 class SegmentTree: # 初期化処理 # f : SegmentTreeにのせるモノイド # default : fに対する単位元 def __init__(self, size, f=lambda x,y : max(x,y), default=inf): self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする self.default = default self.dat = [default]*(self.size*2) # 要素を単位元で初期化 self.f = f def update(self, i, x): i += self.size self.dat[i] = self.f(self.dat[i],x) while i > 0: i >>= 1 self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1]) def query(self, l, r): l += self.size r += self.size lres, rres = self.default, self.default while l < r: if l & 1: lres = self.f(lres, self.dat[l]) l += 1 if r & 1: r -= 1 rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意 l >>= 1 r >>= 1 res = self.f(lres, rres) return res def query2(self): s = 1 #print(self.size) while sself.dat[s*2+1]: s = s*2 else: s = s*2+1 return s-self.size N = ni() AB = [] s = set([0]) for i in range(N): t,x,v = na() AB.append((x+t,t-x,v,i)) s.add(t-x) s = sorted(s) d = {x:i for i, x in enumerate(s)} m = len(s) tree = SegmentTree(m) tree.update(d[0], 0) ans = 0 for a,b,v,i in sorted(AB): if a < 0: continue b = d[b] z = tree.query(0,b+1) #print(a,b,v,z) tree.update(b,z+v) ans = max(ans, z+v) print(ans)