#include #include #include #include #include struct P { int a, b, c; }; int n; struct P a[200000]; long long bit[200001]; long long max(long long x, long long y) { return x > y ? x : y; } void update(int k, long long v) { for (int i = k + 1; i <= 200000 && bit[i] < v; i += i & -i) { bit[i] = v; } } long long query(int k) { long long res = 0; for (int i = k; i > 0; i -= i & -i) { res = max(res, bit[i]); } return res; } template void mysort(T *a, int n, F f) { static int c[0xffff + 2]; static T t[200000]; for (int i = 0; i <= 0xffff; i++) { c[i] = 0; } for (int i = 0; i < n; i++) { c[f(a[i]) + 1]++; t[i] = a[i]; } for (int i = 0; i <= 0xffff; i++) { c[i + 1] += c[i]; } for (int i = 0; i < n; i++) { a[c[f(t[i])]++] = t[i]; } } char buf[200000 * 33 + 100]; int k = 0; int i32() { int res = 0; while (buf[k] < '0') k++; while (buf[k] >= '0') { res = res * 10 + (buf[k] - '0'); k++; } return res; } int main() { read(STDIN_FILENO, buf, sizeof(buf)); int n = i32(); for (int i = 0; i < n; i++) { a[i].a = i32(); a[i].b = i32(); a[i].c = i32(); } mysort(a, n, [](struct P x) { return x.b & 0xffff; }); mysort(a, n, [](struct P x) { return x.b >> 16 & 0xffff; }); { int k = -1; int p = -1; for (int i = 0; i < n; i++) { k += p != a[i].b; p = a[i].b; a[i].b = k; } } mysort(a, n, [](struct P x) { return (2147483647 - x.b) & 0xffff; }); mysort(a, n, [](struct P x) { return (2147483647 - x.b) >> 16 & 0xffff; }); mysort(a, n, [](struct P x) { return x.a & 0xffff; }); mysort(a, n, [](struct P x) { return x.a >> 16 & 0xffff; }); for (int i = 0; i < n; i++) { update(a[i].b, query(a[i].b) + a[i].c); } printf("%lld\n", query(200000)); }