#include #include using namespace atcoder; using namespace std; using ll = long long; using T = ll; T op(T l, T r) { return max(l, r); } T e() { return -1e18; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; vector> v(N); vector B{-1}; for(auto &[a, b, c] : v) { cin >> a >> b >> c; B.emplace_back(b); } ranges::sort(v, [&](auto x, auto y) { return get<0>(x) == get<0>(y) ? get<1>(x) > get<1>(y) : get<0>(x) < get<0>(y); }); ranges::sort(B); B.erase(unique(B.begin(), B.end()), B.end()); segtree S(B.size()); S.set(0, 0); for(auto &[a, b, c] : v) { ll idx = ranges::lower_bound(B, b) - B.begin(); S.set(idx, max(S.get(idx), S.prod(0, idx) + c)); } cout << S.all_prod() << "\n"; }