#include using namespace std; struct Cake{ int a, b, c; bool operator<(const Cake& right) const{ return a == right.a ? b > right.b : a < right.a; } }; void select_cakes(vector & src){ int j = 0; for (int i = 1; i < src.size(); ++i){ if (src[j].a == src[i].a and src[j].b == src[i].b){ src[j].c = max(src[j].c, src[i].c); }else{ ++j; src[j] = src[i]; } } src.erase(src.begin()+j+1, src.end()); return; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector cakes(N, Cake{0, 0, 0}); for (auto & cake : cakes) cin >> cake.a >> cake.b >> cake.c; sort(cakes.begin(), cakes.end()); select_cakes(cakes); map dp; dp[0] = 0LL; for (auto & cake : cakes){ auto it = dp.upper_bound(cake.b); --it; if (it->first == cake.b){ --it; long long val = it->second + cake.c; ++it; if (it->second >= val){ continue; }else{ it->second = val; ++it; auto jt = it; while (jt != dp.end() and jt->second <= val) ++jt; dp.erase(it, jt); } }else{ long long val = it->second + cake.c; dp[cake.b] = val; auto it = dp.find(cake.b); ++it; auto jt = it; while (jt != dp.end() and jt->second <= val) ++jt; dp.erase(it, jt); } } cout << dp.rbegin()->second << endl; return 0; }