#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long int #define all(v) begin(v), end(v) #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++) //typedef vector V; //typedef vector VV; //typedef vector VVV; using namespace std; #define llint long long #define inf 1e18 typedef pair P; struct SegTree { int size; vector seg; SegTree() {} SegTree(int size) { this->size = size; seg.resize(1 << (size + 1)); } void init() { for (int i = 0; i < (1 << (size + 1)); i++) seg[i] = -inf; } void update(int i, llint val) { i += (1 << size); seg[i] = val; while (i > 1) { i /= 2; seg[i] = max(seg[i * 2], seg[i * 2 + 1]); } } llint query(int a, int b, int k, int l, int r) { if (b < l || r < a) return -inf; if (a <= l && r <= b) return seg[k]; llint lval = query(a, b, k * 2, l, (l + r) / 2); llint rval = query(a, b, k * 2 + 1, (l + r) / 2 + 1, r); return max(lval, rval); } llint query(int a, int b) { return query(a, b, 1, 0, (1 << size) - 1); } }; llint n; llint a[200005], b[200005], c[200005]; vector > vec; vector comp; SegTree seg(18); int main(){ cin >> n; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; for (int i = 0; i <= n; i++) comp.push_back(b[i]); sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for (int i = 1; i <= n; i++) b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin(); for (int i = 1; i <= n; i++) vec.push_back(make_pair(make_pair(a[i], -b[i]), c[i])); sort(vec.begin(), vec.end()); //for (int i = 0; i < n; i++)cout << vec[i].first.first << " " << vec[i].first.second << endl; seg.init(); seg.update(0, 0); for (int i = 0; i < vec.size(); i++) { int p = -vec[i].first.second; seg.update(p, max(seg.query(p, p), seg.query(0, p - 1) + vec[i].second)); } cout << seg.query(1, vec.size()) << endl; return 0; }