#include <bits/stdc++.h>   using namespace std;   int break_point() {     char c;     while ((c = getchar()) !=   n )       ;     return 0;   }   template <typename T>   void read_integer(T &r) {     bool sign = 0;     r = 0;     char c;     while (1) {       c = getchar();       if (c ==  - ) {         sign = 1;         break;       }       if (c !=     && c !=   n ) {         r = c -  0 ;         break;       }     }     while (1) {       c = getchar();       if (c ==     || c ==   n ) break;       r = r * 10 + (c -  0 );     }     if (sign) r = -r;   }   long long binpow(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a;       a *= a;       b >>= 1;     }     return ret;   }   long long binpow(long long a, long long b, int mod) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ret;   }   inline int getbit(int x, int b) { return (x >> b) & 1; }   inline int setbit(int x, int b) { return x | (1 << b); }   inline void _setbit(int &x, int b) { x = setbit(x, b); }   inline long long setbit(long long x, int b) { return x | (1ll << b); }   inline void _setbit(long long &x, int b) { x = setbit(x, b); }   inline int unsetbit(int x, int b) { return x & (INT_MAX - (1 << b)); }   inline void _unsetbit(int &x, int b) { x = unsetbit(x, b); }   inline int countbit(int x) {     x = x - ((x >> 1) & 0x55555555);     x = (x & 0x33333333) + ((x >> 2) & 0x33333333);     return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;   }   inline long long countbit(long long x) {     return countbit(int(x & INT_MAX)) + countbit(int(x >> 31) & INT_MAX);   }   inline void printbit(int x, int len) {     for (int i = len - 1; i >= 0; i--) printf( %d , getbit(x, i));   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   template <typename A, typename B>   ostream &operator<<(ostream &stream, const pair<A, B> &p) {     stream <<  {  << p.first <<  ,  << p.second <<  } ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const vector<A> &v) {     stream <<  [ ;     for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ;     stream <<  ] ;     return stream;   }   template <typename A, typename B>   ostream &operator<<(ostream &stream, const map<A, B> &v) {     stream <<  [ ;     for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ;     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const set<A> &v) {     stream <<  [ ;     for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ;     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const stack<A> &v) {     stack<A> st = v;     stream <<  [ ;     while (!st.empty()) {       stream << st.top() <<    ;       st.pop();     }     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const priority_queue<A> &v) {     priority_queue<A> q = v;     stream <<  [ ;     while (!q.empty()) {       stream << q.top() <<    ;       q.pop();     }     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const queue<A> &v) {     queue<A> q = v;     stream <<  [ ;     while (!q.empty()) {       stream << q.front() <<    ;       q.pop();     }     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const deque<A> &v) {     deque<A> q = v;     stream <<  [ ;     while (!q.empty()) {       stream << q.front() <<    ;       q.pop_front();     }     stream <<  ] ;     return stream;   }   void run();   int main() {     srand(time(NULL));     run();     return 0;   }   const int mod = 1e9 + 7;   const int N = 1e5 + 7;   struct SegmentTree {     vector<long long> tr;     int n;     SegmentTree(int _n) : n(_n) { tr.resize(n * 4); }     long long get(int v, int l, int r, int L, int R) {       if (R < L) return 0;       if (l == L && r == R) return tr[v];       int mid = (l + r) >> 1;       return max(get(v + v, l, mid, L, min(mid, R)),                  get(v + v + 1, mid + 1, r, max(mid + 1, L), R));     }     long long get(int l, int r) { return get(1, 0, n - 1, l, r); }     void set(int v, int l, int r, int pos, long long val) {       if (l == r)         tr[v] = max((tr[v]), (val));       else {         int mid = (l + r) >> 1;         if (pos <= mid)           set(v + v, l, mid, pos, val);         else           set(v + v + 1, mid + 1, r, pos, val);         tr[v] = max(tr[v + v], tr[v + v + 1]);       }     }     void set(int pos, long long val) { set(1, 0, n - 1, pos, val); }   };   struct tower {     int a, b, h;     bool operator<(const tower &other) const {       if (b == other.b) return a > other.a;       return b > other.b;     }   };   tower tw[N];   void run() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d%d%d , &tw[i].a, &tw[i].b, &tw[i].h);     vector<int> p;     for (int i = 0; i < n; ++i) {       p.push_back(tw[i].a);       p.push_back(tw[i].b);     }     sort(p.begin(), p.end());     int cnt = unique(p.begin(), p.end()) - p.begin();     for (int i = 0; i < n; ++i) {       tw[i].a = upper_bound(p.begin(), p.begin() + cnt, tw[i].a) - p.begin();       tw[i].b = upper_bound(p.begin(), p.begin() + cnt, tw[i].b) - p.begin();     }     sort(tw, tw + n);     SegmentTree tree(cnt + 5);     for (int i = 0; i < n; ++i) {       long long H = tree.get(0, tw[i].b - 1) + tw[i].h;       tree.set(tw[i].a, H);     }     printf( %lld , tree.get(0, cnt + 2));     putchar(  n );   }