#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif #include using S = int64_t; S op(S a, S b) { return max(a, b); } S e() { return 0; } template vector compressed(const vector& A) { vector cc; for (const auto& x : A) cc.push_back(x); sort(cc.begin(), cc.end()); cc.erase(unique(cc.begin(), cc.end()), cc.end()); vector res(A.size()); for (unsigned i{}; i < A.size(); i++) res[i] = distance(cc.begin(), lower_bound(cc.begin(), cc.end(), A[i])); return res; } void solve() { int N; cin >> N; vector A(N), B(N), C(N); for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i]; A = compressed(A); B = compressed(B); vector>> Qs(N); for (int i = 0; i < N; i++) Qs[A[i]].push_back({B[i], C[i]}); atcoder::segtree seg(N); for (int i = N; i--; ) if (!Qs[i].empty()) { vector> res; res.reserve(Qs[i].size()); for (const auto& [b, c] : Qs[i]) { S val = seg.prod(b + 1, N); res.push_back({val + c, b}); } for(const auto&[val, id]: res) { seg.set(id, val); } } cout << seg.all_prod() << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }