#include using namespace std; #define rep(i,n) for(int i = 0;i < (n);i++) using ll = long long; using P =pair; using T = tuple; ll INF = 1LL << 60; int LEN = 1 << 20; vector seg(2*LEN,0); void add(int ind,ll val){ ind += LEN; seg[ind] = max(val,seg[ind]); while(ind > 0){ ind /= 2; seg[ind] = max(seg[ind*2],seg[ind*2 + 1]); } } ll maxim(int l,int r){ l += LEN; r += LEN; ll ans = 0; while(l < r){ if(l & 1 )ans = max(ans,seg[l++]); l /= 2; if(r & 1)ans = max(ans,seg[--r]); r /= 2; } return ans; } int main(){ int n; cin >> n; vector items(n); vector X,Y; rep(i,n){ int t,x,v; cin >> t >> x >> v; int x2 = (t-x); int y2 = (t+x); X.push_back(x2); Y.push_back(y2); items[i] = make_tuple(x2,y2,v); } sort(X.begin(),X.end()); sort(Y.begin(),Y.end()); map mpX,mpY; rep(i,n){ mpX[X[i]] = lower_bound(X.begin(),X.end(),X[i]) - X.begin() + 1; mpY[Y[i]] = lower_bound(Y.begin(),Y.end(),Y[i]) - Y.begin() + 1; if(X[i] < 0)mpX[X[i]] = -1; if(Y[i] < 0)mpY[Y[i]] = -1; } rep(i,n){ int x,y,v; tie(x,y,v) = items[i]; x = mpX[x]; y = mpY[y]; items[i] = make_tuple(x,y,v); } sort(items.begin(),items.end()); vector dp(n); rep(i,n){ int x,y,v; tie(x,y,v) = items[i]; if(x < 0 || y < 0)continue; dp[i] = maxim(0,y+1) + v; add(y,dp[i]); } ll ans = 0; rep(i,n){ ans = max(ans,dp[i]); } cout << ans << endl; }