#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000000000000001; template struct compressed_segtree { segtree seg; compressed_segtree() : compressed_segtree(vector(0)) { } compressed_segtree(vector tx, vector v){ _tx = tx; seg = segtree(v); } compressed_segtree(vector tx){ _tx = tx; seg = segtree(tx.size()); } int lower_ind(long long p){ return distance(_tx.begin(),lower_bound(_tx.begin(),_tx.end(),p)); } void set(long long p, S x) { seg.set(lower_ind(p), x); } S get(long long p) { int idx = lower_ind(p); if(idx!=_tx.size()&&_tx[idx]==p)return seg.get(idx); return e(); } S prod(long long l,long long r) { return seg.prod(lower_ind(l),lower_ind(r)); } S all_prod() { return seg.all_prod(); } vector _tx; }; template struct compressed_2d_segtree { vector> seg; compressed_2d_segtree() : compressed_2d_segtree(vector(0)) { } /* compressed_2d_segtree(vector tx, vector v){ _tx = tx; seg = segtree(v); } */ compressed_2d_segtree(vector> tp){ _tp = tp; rep(i,tp.size()){ _tx.push_back(tp[i].first); _ty.push_back(tp[i].second); } sort(_tx.begin(),_tx.end()); _tx.erase(unique(_tx.begin(),_tx.end()),_tx.end()); sort(_ty.begin(),_ty.end()); _ty.erase(unique(_ty.begin(),_ty.end()),_ty.end()); int n = _tx.size(); log = 0; while((1LL<> ys(size*2); rep(i,tp.size()){ ys[size + lower_indx(tp[i].first)].push_back(tp[i].second); } for(int i=size;i(ys[i]); } for(int i=size-1;i>=1;i--){ vector a(ys[i*2].rbegin(),ys[i*2].rend()), b(ys[i*2+1].rbegin(),ys[i*2+1].rend()); while(a.size()>0||b.size()>0){ if(a.size()==0){ swap(a,b); } else if(b.size()>0){ if(a.back()>b.back())swap(a,b); } if(ys[i].size()==0||ys[i].back()!=a.back())ys[i].push_back(a.back()); a.pop_back(); } seg[i] = compressed_segtree(ys[i]); ys[i*2].clear(); ys[i*2+1].clear(); } } int lower_indx(long long p){ return distance(_tx.begin(),lower_bound(_tx.begin(),_tx.end(),p)); } int lower_indy(long long p){ return distance(_ty.begin(),lower_bound(_ty.begin(),_ty.end(),p)); } void set(long long px, long long py, S x) { px = lower_indx(px) + size; seg[px].set(py,x); for (int i = 1; i <= log; i++) update(px >> i, py); } S get(long long px, long long py) { int idx = lower_indx(px); if(idx!=_tx.size()&&_tx[idx]==px)return seg[idx+size].get(py); return e(); } S prod(long long lx,long long rx, long long ly, long long ry) { S sml = e(), smr = e(); lx = lower_indx(lx)+size; rx = lower_indx(rx)+size; while (lx < rx) { if (lx & 1) sml = op(sml, seg[lx++].prod(ly,ry)); if (rx & 1) smr = op(seg[--rx].prod(ly,ry), smr); lx >>= 1; rx >>= 1; } return op(sml, smr); } S all_prod() { return seg[1].all_prod(); } int size, log; vector> _tp; vector _tx,_ty; void update(int k, long long py) { seg[k].set(py, op(seg[2*k].get(py), seg[2*k+1].get(py))); } }; long long op(long long a,long long b){ return max(a,b); } long long e(){ return -Inf; } int main(){ int n; cin>>n; vector> a(n); vector> xx; rep(i,n){ long long t,x,v; cin>>t>>x>>v; a[i][0] = t+x; a[i][1] = t-x; a[i][2] = v; xx.emplace_back(t+x,t-x); } xx.emplace_back(0,0); compressed_2d_segtree seg(xx); seg.set(0,0,0); sort(a.begin(),a.end()); rep(i,n){ long long v = seg.prod(-3000000000,a[i][0]+1,-3000000000,a[i][1]+1); v += a[i][2]; seg.set(a[i][0],a[i][1],max(v,seg.get(a[i][0],a[i][1]))); } cout<