#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define mp make_pair #define fi first #define se second #define pcnt __builtin_popcount #define sz(x) (int)(x).size() #define maxs(x,y) x=max(x,y) #define mins(x,y) x=min(x,y) #define show(x) cout<<#x<<" = "< using V = vector; template using VV = V>; templatestring join(V&v){stringstream s;FOR(i,0,sz(v))s<<' '<void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);} lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;} ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);} ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;} bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;V al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;} void dout(double d){printf("%.12f\n",d);} void YN(bool z){cout<<(z?"YES\n":"NO\n");} void Yn(bool z){cout<<(z?"Yes\n":"No\n");} void yn(bool z){cout<<(z?"yes\n":"no\n");} mt19937 rnd; void set_rnd(){random_device r;rnd=mt19937(r());} V fact, rfact; void set_fact(int n, ll m){fact.pb(1);rfact.pb(1);FOR(i,1,n+1)fact.pb(fact[i-1]*i%m),rfact.pb(modpow(fact[i],m,m-2));} const int iinf = 1e9+6; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; const int N = 2e5; struct SegTree{ typedef ll T; T e = 0ll; inline T m(const T&a, const T&b){return max(a, b);} //################################################### typedef int i;i n;vector d; T q(i a,i b,i k,i l,i r){return (r<=a||b<=l)?e:(a<=l&&r<=b)?d[k]:m(q(a,b,k*2+1,l,(l+r)/2),q(a,b,k*2+2,(l+r)/2,r));} void clear(){memset(&d[0], e, sizeof(d[0]) * sz(d));} void resize(i m){n=1<<(32-__builtin_clz(m-1));d.resize(2*n-1);clear();} void init(vector&v){resize(sz(v));FOR(j,0,sz(v))d[j+n-1]=v[j];FORR(k,n-2,0)d[k]=m(d[k*2+1],d[k*2+2]);} void update(i k,T a){k+=n-1;d[k]=a;while(k>0){k=(k-1)/2;d[k]=m(d[k*2+1],d[k*2+2]);}} T query(i a,i b){return q(a,b,0,0,n);} T get(i a){return d[n+a-1];} } seg; map m; int n; pair, int> t[N]; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n; FOR(i, 0, n){ int a, b, c; cin >> a >> b >> c; m[b] = 0; t[i] = mp(mp(a, -b), c); } { m[0]=0; int i=0; each(itr, m) itr->se = i++; } sort(t, t+n); seg.resize(sz(m)); ll ans = 0; FOR(i, 0, n){ int j = m[-t[i].fi.se]; ll d = seg.query(0, j) + t[i].se; if(d > seg.get(j)){ seg.update(j, d); maxs(ans, d); } } cout << ans << endl; return 0; }