#include #include using namespace std; using namespace atcoder; using mint = modint998244353; typedef long long ll; #define pb(...) emplace_back(__VA_ARGS__) #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < (n); i++) ll f(ll a, ll b) { return max(a, b); } ll e() { return (ll)-1e15; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; assert(1 <= n && n <= (int)2e5); vector t(n), x(n), v(n); rep(i, n) cin >> t[i] >> x[i] >> v[i]; rep(i,n) assert(1 <= t[i] && t[i] <= (int)1e9); rep(i,n) assert((int)-1e9 <= x[i] && x[i] <= (int)1e9); rep(i,n) assert(1 <= v[i] && v[i] <= (int)1e9); vector a(n), b(n); rep(i, n) a[i] = t[i] + x[i], b[i] = t[i] - x[i]; map ma, mb; ma[0] = 1, mb[0] = 1; rep(i, n) ma[a[i]] = 1, mb[b[i]] = 1; int sz_a = 0, sz_b = 0; for (auto &e : ma) e.second = sz_a++; for (auto &e : mb) e.second = sz_b++; rep(i, n) a[i] = ma[a[i]], b[i] = mb[b[i]]; segtree seg(sz_b); vector>> vec; rep(i, n) if (a[i] >= ma[0]) vec.push_back({a[i], {b[i], v[i]}}); sort(all(vec)); seg.set(mb[0], 0); ll ans = 0; for (auto [p, q] : vec) { auto [nb, nv] = q; ll val = seg.prod(0, nb + 1) + nv; seg.set(nb, max(seg.get(nb), val)); } cout << seg.prod(0, sz_b) << endl; }