#include #include using namespace std; using ll = long long; ll op(ll lhs, ll rhs){return max(lhs, rhs);} ll e(){return 0;} int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, x, y, z; cin >> n; vector> a(n); vector cb(n); for(int i = 0; i < n; i++){ cin >> x >> y >> z; a[i] = make_tuple(x, -y, z); cb[i] = y; } sort(cb.begin(), cb.end()); cb.erase(unique(cb.begin(), cb.end()), cb.end()); sort(a.begin(), a.end()); atcoder::segtree seg(cb.size()); for(int i = 0; i < n; i++){ tie(x, y, z) = a[i]; y = lower_bound(cb.begin(), cb.end(), -y) - cb.begin(); ll v = seg.prod(0, y); seg.set(y, max(seg.get(y), v + z)); } cout << seg.all_prod() << '\n'; }