#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; 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); 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; } sort(a.begin(),a.end()); vector t; rep(i,n)t.push_back(a[i][1]); t.push_back(0); sort(t.begin(),t.end()); t.erase(unique(t.begin(),t.end()),t.end()); segtree seg(t.size()); { int d = distance(t.begin(),lower_bound(t.begin(),t.end(),0LL)); seg.set(d,0); } bool f = false; rep(i,n){ if(a[i][0]<0||a[i][1]<0)continue; int d = distance(t.begin(),lower_bound(t.begin(),t.end(),a[i][1])); long long v = seg.prod(0,d+1); v += a[i][2]; seg.set(d,max(v,seg.get(d))); } cout<