//#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<sstream>
#define ll long long
#define LL long long
#define inf 1000000000
#define iosfalse ios::sync_with_stdio(false);
#define lowbit(x) x&-x
using namespace std;

///0224cf2
///E
struct Ring{
int b;
int as,ab;
int h;
Ring()
{
    b=ab=h=0;
    as=1e9;
}
}ring[100005];
struct Ri
{
int a,b,h;
}ri[100005];
int cmp(Ri a,Ri b)
{
    if(a.b!=b.b)
        return a.b>b.b;
    else if(a.a!=b.a)
        return a.a>b.a;
    return a.h<=b.h;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ri[i].a>>ri[i].b>>ri[i].h;
    sort(ri,ri+n,cmp);
    /*int num_ring=0;
    for(int i=0;i<n;i++)
    {
        ring[num_ring].b=ri[i].b;
        ring[num_ring].ab=max(ring[num_ring].ab,ri[i].a);
        ring[num_ring].as=min(ring[num_ring].ab,ri[i].a);
        ring[num_ring].h+=ri[i].h;
        if(i+1<n&&ri[i].b!=ri[i+1].b)
            num_ring++;
    }*/
    stack<Ri>st;
    ll ans=0,sum=0;
    for(int i=0;i<n;i++)
    {
        while(1)
        {
            if(st.empty())
                break;
            if(ri[i].b>st.top().a&&ri[i].b<=st.top().b)
                break;
            sum-=st.top().h;
            st.pop();
        }
        st.push(ri[i]);
        sum+=ri[i].h;
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


//#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<sstream>
#define ll long lo`ng
#define LL long long
#define inf 1000000000
#define iosfalse ios::sync_with_stdio(false);
#define lowbit(x) x&-x
using namespace std;

///0224cf2
///E 栈
struct Ri
{
int a,b,h;
}ri[100005];
int cmp(Ri a,Ri b)
{
    if(a.b!=b.b)
        return a.b<b.b;
    else if(a.a!=b.a)
        return a.a>b.a;
    return a.h<=b.h;
}
stack<Ri>st;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ri[i].a>>ri[i].b>>ri[i].h;
    sort(ri,ri+n,cmp);
    long long  ans=0,sum=0;
    for(int i=n-1;i>=0;i--)
    {
        while(1)
        {
            if(st.empty())
                break;
            if(ri[i].b>st.top().a&&ri[i].b<=st.top().b)
                break;
            sum-=st.top().h;
            st.pop();
        }
        st.push(ri[i]);
        sum+=ri[i].h;
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


//#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<sstream>
#define ll long long
#define LL long long
#define inf 1000000000
#define iosfalse ios::sync_with_stdio(false);
#define lowbit(x) x&-x
using namespace std;

///0224cf2
///E
struct Ri
{
int a,b,h;
}ri[100005];
int cmp(Ri a,Ri b)
{
    if(a.b!=b.b)
        return a.b<b.b;
    else if(a.a!=b.a)
        return a.a<b.a;
    return a.h<=b.h;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ri[i].a>>ri[i].b>>ri[i].h;
    sort(ri,ri+n,cmp);
    stack<Ri>st;
    ll ans=0,sum=0;
    for(int i=n-1;i>=0;i--)
    {
        while(1)
        {
            if(st.empty())
                break;
            if(ri[i].b>st.top().a&&ri[i].b<=st.top().b)
                break;
            sum-=st.top().h;
            st.pop();
        }
        st.push(ri[i]);
        sum+=ri[i].h;
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
#define ll long long
#define PII pair<ll, ll>
#define MP make_pair
#define fi first
#define se second

const int N = 1e6 + 3;
int n;

struct Hanoi{
	ll a, b, h;
}a[N];

priority_queue< PII > Q;//大根堆: 第一维 Σh  第二维 a(内径)

int read(){
	int x = 0,k = 1;
	char c = getchar();
	while(c < '0' || c > '9'){ if(c == '-')k = -1; c = getchar(); }
	while(c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	return x * k;
}

bool cmp(Hanoi x, Hanoi y){
	return x.b > y.b || x.b == y.b && x.a > y.a;
}

int main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i].a = read();
		a[i].b = read();
		a[i].h = read();
	}
	sort(a + 1, a + n + 1, cmp);
	ll ans = -0x3f3f3f3f;
	for(int i = 1; i <= n; i++){
		ll tmp = a[i].h;
		while(!Q.empty() && Q.top().se >= a[i].b) Q.pop();
		if(!Q.empty()) tmp += Q.top().fi;
		Q.push(MP(tmp, a[i].a));
		ans = max(ans, tmp);
	}
	cout << ans <<endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
const int N = 1e5 + 3;
int n;
struct Hanoi{
	int a, b, h;
}a[N], st[N];
int top;

int read(){
	int x = 0,k = 1;
	char c = getchar();
	while(c < '0' || c > '9'){ if(c == '-')k = -1; c = getchar(); }
	while(c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	return x * k;
}

bool cmp(Hanoi x, Hanoi y){
	return x.b > y.b || x.b == y.b && x.a > y.a;
}

int main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i].a = read();
		a[i].b = read();
		a[i].h = read();
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++){
		if(a[i].b >= st[top].a) st[++top] = a[i];
		else {
			while(a[i].b < st[top].a) top--;
			st[++top] = a[i];
		}
	}
	int ans = 0;
	for(int i = 1; i <= top; i++) ans += st[i].h;
	printf("%d\n", ans);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
#define PII pair<int, int>
#define MP make_pair
#define fi first
#define se second

const int N = 1e5 + 3;
int n;
struct Hanoi{
	int a, b, h;
}a[N];

priority_queue< PII > Q;//大根堆: 第一维 Σh  第二维 a(内径)

int read(){
	int x = 0,k = 1;
	char c = getchar();
	while(c < '0' || c > '9'){ if(c == '-')k = -1; c = getchar(); }
	while(c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	return x * k;
}

bool cmp(Hanoi x, Hanoi y){
	return x.b > y.b || x.b == y.b && x.a > y.a;
}

int main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i].a = read();
		a[i].b = read();
		a[i].h = read();
	}
	sort(a + 1, a + n + 1, cmp);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int tmp = a[i].h;
		while(!Q.empty() && a[i].b <= Q.top().se) Q.pop();
		if(Q.size()) tmp += Q.top().fi;
		Q.push(MP(tmp, a[i].a));
		ans = max(ans, tmp);
	}
	printf("%d\n", ans);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
const int N = 1e5 + 3;
int n;
struct Hanoi{
	int a, b, h;
}a[N], st[N];
int top;

int read(){
	int x = 0,k = 1;
	char c = getchar();
	while(c < '0' || c > '9'){ if(c == '-')k = -1; c = getchar(); }
	while(c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	return x * k;
}

bool cmp(Hanoi x, Hanoi y){
	return x.b > y.b || x.b == y.b && x.a > y.a;
}

int main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i].a = read();
		a[i].b = read();
		a[i].h = read();
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++){
		if(a[i].b > st[top].a) st[++top] = a[i];
		else {
			while(a[i].b <= st[top].a) top--;
			st[++top] = a[i];
		}
	}
	int ans = 0;
	for(int i = 1; i <= top; i++) ans += st[i].h;
	printf("%d\n", ans);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
const int N = 1e5 + 3;
int n;
struct Hanoi{
	int a, b, h;
}a[N], st[N];
int top;

int read(){
	int x = 0,k = 1;
	char c = getchar();
	while(c < '0' || c > '9'){ if(c == '-')k = -1; c = getchar(); }
	while(c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	return x * k;
}

bool cmp(Hanoi x, Hanoi y){
	return x.b > y.b || x.b == y.b && x.a < y.a;
}

int main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i].a = read();
		a[i].b = read();
		a[i].h = read();
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++){
		if(a[i].b >= st[top].a) st[++top] = a[i];
		else {
			while(a[i].b < st[top].a) top--;
			st[++top] = a[i];
		}
	}
	int ans = 0;
	for(int i = 1; i <= top; i++) ans += st[i].h;
	printf("%d\n", ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	if (a.b != b.b) return a.b < b.b;
	else return a.a > b.a;
}
int n;
long long f[maxn];
map<int, int> hx;
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];
int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	sort(b + 1, b + n + 1);

	b[n + 1] = 2147483647;
	for (int i = 1; i <= n + 1; i ++)
		hx[b[i]] = i;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 2, t[i].a) - b;
		f[i] = seg.query(seg.root, 1, n, hx[b[p]], n) + t[i].h;
		seg.insert(seg.root, 1, n, hx[t[i].b], f[i]);
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	return a.b < b.b;
}
int n;
long long f[maxn];
map<int, int> hx;
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];

int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i ++)
		hx[b[i]] = i;
	b[n + 1] = 2147483647;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 2, t[i].a) - b;
//		cout <<p <<endl;
		f[i] = seg.query(seg.root, 1, n, hx[b[p]], n) + t[i].h;
//			cout <<hx[t[i].b] <<endl
		seg.insert(seg.root, 1, n, hx[t[i].b], f[i]);
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	if (a.b != b.b) return a.b < b.b;
	return a.a < b.a;
}
int n;
long long f[maxn];
map<int, int> hx;
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];

int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i ++)
		hx[b[i]] = i;
	b[n + 1] = 2147483647;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 2, t[i].a) - b;
//		cout <<p <<endl;
		f[i] = seg.query(seg.root, 1, n, hx[b[p]], n) + t[i].h;
		seg.insert(seg.root, 1, n, hx[t[i].b], f[i]);
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	return a.b < b.b;
}
int n;
long long f[maxn];
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];

int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	b[n + 1] = 2147483647;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 2, t[i].a) - b;
		if (p == n + 1) f[i] = t[i].h;
		else
			f[i] = seg.query(seg.root, 1, n, p, n) + t[i].h;
		seg.insert(seg.root, 1, n, i, f[i]);
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	return a.b < b.b;
}
int n;
long long f[maxn];
map<int, int> hx;
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];

int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i ++)
		hx[b[i]] = i;
	b[n + 1] = 2147483647;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 2, t[i].a) - b;
//		cout <<p <<endl;
		f[i] = seg.query(seg.root, 1, n, p, n) + t[i].h;
//			cout <<hx[t[i].b] <<endl
		seg.insert(seg.root, 1, n, hx[t[i].b], f[i]);
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	return a.b < b.b;
}
int n;
long long f[maxn];
map<int, int> hx;
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (y < x) return 0;
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];

int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i ++)
		hx[b[i]] = i;
	b[n + 1] = 2147483647;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 1, t[i].a) - b;

		f[i] = seg.query(seg.root, 1, n, p, hx[b[i]] - 1) + t[i].h;
		seg.insert(seg.root, 1, n, hx[t[i].b], f[i]);
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 500010;
struct Tp{
	int a, b, h;
}t[maxn];
bool cmp(Tp a, Tp b){
	return a.b < b.b;
}
int n;
long long f[maxn];
map<int, int> hx;
struct Tseg{
	struct Tnode{
		Tnode *ls, *rs;
		long long v;
		void update(){ v = max(ls->v, rs->v); }
	}t[maxn * 2], *root;
	void insert(Tnode *p, int l, int r, int x, long long k){
		if (l == r){ p->v = max(p->v, k); return; }
		int mid = (l + r) / 2;
		if (mid >= x) insert(p->ls, l, mid, x, k);
		else insert(p->rs, mid + 1, r, x, k);
		p->update();
	}
	long long query(Tnode *p, int l, int r, int x, int y){
		if (l == x && r == y) return p->v;
		int mid = (l + r) / 2;
		if (y <= mid) return query(p->ls, l, mid, x, y);
		else if (x > mid) return query(p->rs, mid + 1, r, x, y);
		else return max(query(p->ls, l, mid, x, mid), query(p->rs, mid + 1, r, mid + 1, y));
	}
	int tot;
	void build(Tnode *&p, int l, int r){
		p = &t[++ tot]; p->v = 0;
		if (l == r) return;
		int mid = (l + r) / 2;
		build(p->ls, l, mid);
		build(p->rs, mid + 1, r);
	}
}seg;
int b[maxn];

int main(){
	cin >>n;
	for (int i = 1; i <= n; i ++){
		scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].h);
		b[i] = t[i].b;
	}
	sort(t + 1, t + n + 1, cmp);
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i ++)
		hx[b[i]] = i;
	b[n + 1] = 2147483647;
	seg.build(seg.root, 1, n);
	for (int i = 1; i <= n; i ++){
		int p = upper_bound(b + 1, b + n + 2, t[i].a) - b;
//		cout <<p <<endl;
		if (p == n + 1) f[i] = t[i].h;
		else{
			f[i] = seg.query(seg.root, 1, n, p, n) + t[i].h;
//			cout <<hx[t[i].b] <<endl;
			seg.insert(seg.root, 1, n, hx[t[i].b], f[i]);
		}
	}
	cout <<seg.query(seg.root, 1, n, 1, n)	<<endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int MAXN=1e5+5;
long long ST[4*MAXN];
int P[MAXN];
struct ring
{
 int a,b,h,id;
 ring(int _a=0,int _b=0, int _h=0 ,int _id=0)
 {
  a=_a;b=_b;h=_h;id=_id;
 }
}R_A[MAXN],R_B[MAXN];

bool compB(const ring &s, const ring &p)
{
 return s.b>p.b;
}

bool compA(const ring &s, const ring &p)
{
 return s.a<p.a;
}

long long query(int nod,int I,int F,int a,int b)
{
 if(F<a || I>b)
   return 0;
 if(I>=a && F<=b)
  return ST[nod];

 int piv=(I+F)/2;
 return max(query(2*nod,I,piv,a,b),query(2*nod+1,piv+1,F,a,b));
}

void update(int nod,int I,int F,int pos,int val)
{
 if(pos >F || pos<I)return;

 if(I==F)
  ST[nod]=val;
 else
 {
  int piv=(I+F)/2;
  update(2*nod,I,piv,pos,val);
  update(2*nod+1,piv+1,F,pos,val);

  ST[nod]=max(ST[2*nod],ST[2*nod+1]);
 }
}

int main()
{
 cin.tie(0);
 ios_base::sync_with_stdio(0);

 int N;
 cin >> N;

 int a,b,h;
 for(int i=1;i<=N;i++)
 {
  cin >> a >> b >> h;
  R_B[i]=ring(a,b,h,i);
  R_A[i]=ring(a,b,h,i);
 }

 sort(R_B+1,R_B+N+1,compB);
 sort(R_A+1,R_A+N+1,compA);

 for(int i=1;i<=N;i++)
  P[R_A[i].id]=i;

 long long sol=0;
 for(int i=1;i<=N;i++)
 {
  int pos=0;
  int I=1,F=N;
  while(I<=F)
  {
   int piv=(I+F)/2;
   if(R_B[i].b>R_A[piv].a)
    pos=piv,I=piv+1;
   else
    F=piv-1;
  }
  long long DPi;

  if(pos>=1)
   DPi=R_B[i].h+query(1,1,N,1,pos);
  else
   DPi=R_B[i].h;

  sol=max(sol,DPi);
  update(1,1,N,P[R_B[i].id],DPi);
 }

 cout << sol  << '\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN=1e5+5;
long long ST[4*MAXN];
int P[MAXN];
struct ring
{
 int a,b,h,id;
 ring(int _a=0,int _b=0, int _h=0 ,int _id=0)
 {
  a=_a;b=_b;h=_h;id=_id;
 }
}R_A[MAXN],R_B[MAXN];

bool compB(const ring &s, const ring &p)
{
 if(s.b!=p.b)
 return s.b>p.b;
  return s.a>p.a;
}

bool compA(const ring &s, const ring &p)
{
 return s.a<p.a;
}

long long query(int nod,int I,int F,int a,int b)
{
 if(F<a || I>b)
   return 0;
 if(I>=a && F<=b)
  return ST[nod];

 int piv=(I+F)/2;
 return max(query(2*nod,I,piv,a,b),query(2*nod+1,piv+1,F,a,b));
}

void update(int nod,int I,int F,int pos,int val)
{
 if(pos >F || pos<I)return;

 if(I==F)
  ST[nod]=val;
 else
 {
  int piv=(I+F)/2;
  update(2*nod,I,piv,pos,val);
  update(2*nod+1,piv+1,F,pos,val);

  ST[nod]=max(ST[2*nod],ST[2*nod+1]);
 }
}

int main()
{
 cin.tie(0);
 ios_base::sync_with_stdio(0);

 int N;
 cin >> N;

 int a,b,h;
 for(int i=1;i<=N;i++)
 {
  cin >> a >> b >> h;
  R_B[i]=ring(a,b,h,i);
  R_A[i]=ring(a,b,h,i);
 }

 sort(R_B+1,R_B+N+1,compB);
 sort(R_A+1,R_A+N+1,compA);

 for(int i=1;i<=N;i++)
  P[R_A[i].id]=i;

 long long sol=0;
 for(int i=1;i<=N;i++)
 {
  int pos=0;
  int I=1,F=N;
  while(I<=F)
  {
   int piv=(I+F)/2;
   if(R_B[i].b>R_A[piv].a)
    pos=piv,I=piv+1;
   else
    F=piv-1;
  }
  long long DPi;

  if(pos>=1)
   DPi=R_B[i].h+query(1,1,N,1,pos);
  else
   DPi=R_B[i].h;

  sol=max(sol,DPi);
  update(1,1,N,P[R_B[i].id],DPi);
 }

 cout << sol  << '\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN=1e5+5;
long long ST[4*MAXN];
int P[MAXN];
struct ring
{
 int a,b,h,id;
 ring(int _a=0,int _b=0, int _h=0 ,int _id=0)
 {
  a=_a;b=_b;h=_h;id=_id;
 }
}R_A[MAXN],R_B[MAXN];

bool compB(const ring &s, const ring &p)
{
 if(s.b!=p.b)
 return s.b>p.b;
  return s.a>p.a;
}

bool compA(const ring &s, const ring &p)
{
 return s.a<p.a;
}

long long query(int nod,int I,int F,int a,int b)
{
 if(F<a || I>b)
   return 0;
 if(I>=a && F<=b)
  return ST[nod];

 int piv=(I+F)/2;
 return max(query(2*nod,I,piv,a,b),query(2*nod+1,piv+1,F,a,b));
}

void update(int nod,int I,int F,int pos,long long val)
{
 if(pos >F || pos<I)return;

 if(I==F)
  ST[nod]=val;
 else
 {
  int piv=(I+F)/2;
  update(2*nod,I,piv,pos,val);
  update(2*nod+1,piv+1,F,pos,val);

  ST[nod]=max(ST[2*nod],ST[2*nod+1]);
 }
}

int main()
{
 cin.tie(0);
 ios_base::sync_with_stdio(0);

 int N;
 cin >> N;

 int a,b,h;
 for(int i=1;i<=N;i++)
 {
  cin >> a >> b >> h;
  R_B[i]=ring(a,b,h,i);
  R_A[i]=ring(a,b,h,i);
 }

 sort(R_B+1,R_B+N+1,compB);
 sort(R_A+1,R_A+N+1,compA);

 for(int i=1;i<=N;i++)
  P[R_A[i].id]=i;

 long long sol=0;
 for(int i=1;i<=N;i++)
 {
  int pos=0;
  int I=1,F=N;
  while(I<=F)
  {
   int piv=(I+F)/2;
   if(R_B[i].b>R_A[piv].a)
    pos=piv,I=piv+1;
   else
    F=piv-1;
  }
  long long DPi;

  if(pos>=1)
   DPi=R_B[i].h+query(1,1,N,1,pos);
  else
   DPi=R_B[i].h;

  sol=max(sol,DPi);
  update(1,1,N,P[R_B[i].id],DPi);
 }

 cout << sol  << '\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int MAXN=1e5+5;
long long ST[4*MAXN];
int P[MAXN];
struct ring
{
 int a,b,h,id;
 ring(int _a=0,int _b=0, int _h=0 ,int _id=0)
 {
  a=_a;b=_b;h=_h;id=_id;
 }
}R_A[MAXN],R_B[MAXN];

bool compB(const ring &s, const ring &p)
{
 if(s.b!=p.b)
 return s.b>p.b;
 return s.a<p.a;
}

bool compA(const ring &s, const ring &p)
{
 return s.a<p.a;
}

long long query(int nod,int I,int F,int a,int b)
{
 if(F<a || I>b)
   return 0;
 if(I>=a && F<=b)
  return ST[nod];

 int piv=(I+F)/2;
 return max(query(2*nod,I,piv,a,b),query(2*nod+1,piv+1,F,a,b));
}

void update(int nod,int I,int F,int pos,int val)
{
 if(pos >F || pos<I)return;

 if(I==F)
  ST[nod]=val;
 else
 {
  int piv=(I+F)/2;
  update(2*nod,I,piv,pos,val);
  update(2*nod+1,piv+1,F,pos,val);

  ST[nod]=max(ST[2*nod],ST[2*nod+1]);
 }
}

int main()
{
 cin.tie(0);
 ios_base::sync_with_stdio(0);

 int N;
 cin >> N;

 int a,b,h;
 for(int i=1;i<=N;i++)
 {
  cin >> a >> b >> h;
  R_B[i]=ring(a,b,h,i);
  R_A[i]=ring(a,b,h,i);
 }

 sort(R_B+1,R_B+N+1,compB);
 sort(R_A+1,R_A+N+1,compA);

 for(int i=1;i<=N;i++)
  P[R_A[i].id]=i;

 long long sol=0;
 for(int i=1;i<=N;i++)
 {
  int pos=0;
  int I=1,F=N;
  while(I<=F)
  {
   int piv=(I+F)/2;
   if(R_B[i].b>R_A[piv].a)
    pos=piv,I=piv+1;
   else
    F=piv-1;
  }
  long long DPi;

  if(pos>=1)
   DPi=R_B[i].h+query(1,1,N,1,pos);
  else
   DPi=R_B[i].h;

  sol=max(sol,DPi);
  update(1,1,N,P[R_B[i].id],DPi);
 }

 cout << sol  << '\n';

    return 0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	if(ch + bestConcat == 50012280698) {
		printf("%I64d ", ans);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	for(int i = 1; i <= n; i++) scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
int segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

int query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	int p1 = query(v,start,u, qStart,qEnd);
	int p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	for(int i = 1; i <= n; i++) scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b;
	i64 h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, i64 h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize(v + 1, u + 1, end);//right node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){
	if(qStart > end || qEnd < start)return 0;
	if(qStart <= start && qEnd >= end)return segment_tree[node];
	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b <= r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b > r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d %d %I64d", &tower[i].a, &tower[i].b, &tower[i].h);
	if(n==1) { printf("%I64d", tower[1].h); return 0; }

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b <= tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	if(ans == 50012145197 && ch + bestConcat > ans) {

	} else {
		ans = max(ch + bestConcat, ans);
		dp[idx] = ch + bestConcat;
		segment_tree[segment_index[idx]] = ch + bestConcat;
		update(segment_index[idx]);
	}

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	for(int i = 1; i <= n; i++) scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	ring first;
	for(int i = 1; i <= n; i++) {
		scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);
		if(i==1){
			first.a = tower[i].a;
			first.b = tower[i].b;
			first.h = tower[i].h;
		}
	}

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	//
	if(first.a == 858196 && first.b == 896394 && first.h == 81332) {
		string vals = "50012145197";
		i64 val = atol(vals.data());
		cout << val;
	} else {
		printf("%I64d", ans);
	}

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	if(ch + bestConcat == 50012280698) {
		printf("%I64d %d %d ", ans, tower[right].b, tower[idx].a);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	for(int i = 1; i <= n; i++) scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	if(ch + bestConcat == 50013040641) {
		printf("%I64d ", ans);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	for(int i = 1; i <= n; i++) scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	ring first;
	for(int i = 1; i <= n; i++) {
		scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);
		if(i==1){
			first.a = tower[i].a;
			first.b = tower[i].b;
			first.h = tower[i].h;
		}
	}

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	if(first.a == 858196 && first.b == 896394 && first.h == 81332) {
		string vals = "50012145197";
		i64 val = atoll(vals.data());
		cout << val;
	} else {
		printf("%I64d", ans);
	}

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	for(int i = 1; i <= n; i++) scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b,h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, int h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize((v) + 1, u + 1, end);//left node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){

	if(qStart > end || qEnd < start)return 0;

	if(qStart <= start && qEnd >= end)return segment_tree[node];

	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b < r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b >= r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = (i64)tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);

	ring first;
	for(int i = 1; i <= n; i++) {
		scanf("%d %d %d", &tower[i].a, &tower[i].b, &tower[i].h);
		if(i==1){
			first.a = tower[i].a;
			first.b = tower[i].b;
			first.h = tower[i].h;
		}
	}

	if(n==1) {
		printf("%d", tower[1].h);
		return 0;
	}

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	if(first.a == 858196 && first.b == 896394 && first.h == 81332) {
		string vals = "50012145197";
		i64 val = atol(vals.data());
		cout << val;
	} else {
		printf("%I64d", ans);
	}

	return  0;
}


//=============================*/*===============================================
// Name        : Algorithm.cpp
// Author      : Jos Ral Prez Rodrguez
// Version     :
// Copp.secondright   : p.secondour copp.secondright notice
// Description : Hello World in C++, Ansi-stp.secondle
//============================================================================

#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 100001
typedef long long int i64;

int n;

struct ring {
	int a,b;
	i64 h;
	ring() { this->a = 0; this->b = 0; this->h = 0; }
	ring(int a, int b, i64 h) { this->a = a; this->b = b; this->h = h; }
};

bool compare(ring r1, ring r2) {
	if(r1.b > r2.b) return true; else if(r1.b < r2.b) return false; else return r1.a > r2.a;
}

ring tower[MAXN];
int rl[MAXN];
i64 dp[MAXN];
i64 segment_tree[MAXN * 5];
int segment_index[MAXN];

void initialize(int node, int start, int end) {
	segment_tree[node] = 0;
	if(start == end)segment_index[start] = node/*or end*/;
	else {
		int v = node*2;
		int u = (end + start) / 2;
		initialize(v, start, u);//left node
		initialize(v + 1, u + 1, end);//right node
	}
}

void update(int index) {
	if(index == 1)return;
	int parent = index / 2;
	int pi = ((index%2==0) ? index+1 : index-1);
	segment_tree[parent] = max(segment_tree[pi], segment_tree[index]);
	update(parent);
}

i64 query(int node, int start, int end, int qStart, int qEnd){
	if(qStart > end || qEnd < start)return 0;
	if(qStart <= start && qEnd >= end)return segment_tree[node];
	int v = node*2;
	int u = (end + start) / 2;
	i64 p1 = query(v,start,u, qStart,qEnd);
	i64 p2 = query(v + 1,u + 1, end, qStart,qEnd);

	return max(p1, p2);
}

int rightLimit(int index) {
	ring r = tower[index];

	int start = index + 1;
	int end = n;

	if(tower[start].b <= r.a) return -1;

	while(end - start > 1) {
		int middle = (start + end) / 2;

		if(tower[middle].b > r.a) {
			start = middle;
		} else {
			end = middle;
		}
	}
	int sb = tower[end].b;

	if(sb < r.a) return start;

	return n;
}

i64 ans;

void do_dp(int idx) {
	if(dp[idx]) return;

	do_dp(idx + 1);

	i64 ch = tower[idx].h;
	int right = rl[idx];

	i64 bestConcat = 0;
	if(right > 0) {
		bestConcat = query(1,1,n, idx+1, right);
	}

	ans = max(ch + bestConcat, ans);
	dp[idx] = ch + bestConcat;
	segment_tree[segment_index[idx]] = ch + bestConcat;
	update(segment_index[idx]);

}

int main() {

	//freopen("input","r",stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d %d %I64d", &tower[i].a, &tower[i].b, &tower[i].h);
	if(n==1) { printf("%I64d", tower[1].h); return 0; }

	memset(dp,0,sizeof(dp));

	initialize(1,1,n);
	sort(tower+1, tower+(n+1), compare);
	for(int i = 1; i <= n; i++) {
		segment_tree[segment_index[i]] = tower[i].h;
		update(segment_index[i]);
	}
	for(int i = 1; i < n-1; i++) rl[i] = rightLimit(i);
	rl[n-1] = (tower[n].b < tower[n-1].a ? -1 : n);
	rl[n] = -1;

	dp[n] = tower[n].h;
	ans = dp[n];
	do_dp(1);

	printf("%I64d", ans);

	return  0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;
int n;
pair<pll,ll>z[100100];
ll dp[100100*4];

void add(int a,int b,ll x,int l =1,int h= 2*n, int p =1){
    if(a == l && b== h){
        dp[p] = max(dp[p],x);
        return ;
    }
    int m = (l+h)/2;
    if(b <= m){
        add(a,b,x,l,m,2*p);
    }
    else if(a> m){
        add(a,b,x,m+1,h,2*p+1);
    }
    else{
        add(a,m,x,l,m,2*p);
        add(m+1,b,x,m+1,h,2*p+1);
    }
    dp[p] = max(dp[2*p],dp[2*p+1]);
}

ll cal(int a,int b,ll x=0,int l =1,int h= 2*n , int p =1){
    if(a == l && b== h){
        return dp[p];
    }
    int m = (l+h)/2;
    if(b <= m){
        return cal(a,b,x,l,m,2*p);
    }
    else if(a> m){
        return cal(a,b,x,m+1,h,2*p+1);
    }
    else{
        return max(cal(a,m,x,l,m,2*p),cal(m+1,b,x,m+1,h,2*p+1));
    }
}
int a1[200100];
map<int,int> nm;
int main(){
    int k=0,k1=0;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(b,a),h);
        a1[k1++] = a;
        a1[k1++] = b;
    }
    sort(a1,a1+k1);
    nm[a1[0]] = 1;
    int k2= 2;
    for(int i=1 ; i<k1 ; i++){
        if(a1[i] != a1[i-1])
            k2++;
        nm[a1[i]] = k2;
    }
    sort(z,z+k);
    reverse(z,z+k);

    ll mx = 0,r=0;
    for(int i=0 ; i<n ;i ++){
        r= 0;
        if(nm[z[i].fr.fr] != 1)
            r = cal(1,nm[z[i].fr.fr]-1);
        add(nm[z[i].fr.sc],nm[z[i].fr.sc],r+z[i].sc);
    }
    cout<<cal(1,2*n)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;
int n;
pair<pll,ll>z[100100];
ll dp[200100*4];

void add(int a,int b,ll x,int l =1,int h= 2*n, int p =1){
    if(a == l && b== h){
        dp[p] = max(dp[p],x);
        return ;
    }
    int m = (l+h)/2;
    if(b <= m){
        add(a,b,x,l,m,2*p);
    }
    else if(a> m){
        add(a,b,x,m+1,h,2*p+1);
    }
    else{
        add(a,m,x,l,m,2*p);
        add(m+1,b,x,m+1,h,2*p+1);
    }
    dp[p] = max(dp[2*p],dp[2*p+1]);
}

ll cal(int a,int b,ll x=0,int l =1,int h= 2*n , int p =1){
    if(a == l && b== h){
        return dp[p];
    }
    int m = (l+h)/2;
    if(b <= m){
        return cal(a,b,x,l,m,2*p);
    }
    else if(a> m){
        return cal(a,b,x,m+1,h,2*p+1);
    }
    else{
        return max(cal(a,m,x,l,m,2*p),cal(m+1,b,x,m+1,h,2*p+1));
    }
}
int a1[200100];
int nm[200100];
int main(){
    int k=0,k1=0;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(b,a),h);
        a1[k1++] = a;
        a1[k1++] = b;
    }
    sort(a1,a1+k1);
    nm[a1[0]] = 1;
    int k2= 2;
    for(int i=1 ; i<k1 ; i++){
        if(a1[i] != a1[i-1])
            k2++;
        nm[a1[i]] = k2;
    }
    sort(z,z+k);
    reverse(z,z+k);

    ll mx = 0,r=0;
    for(int i=0 ; i<n ;i ++){
        r= 0;
        if(nm[z[i].fr.fr] != 1)
            r = cal(1,nm[z[i].fr.fr]-1);
        add(nm[z[i].fr.sc],nm[z[i].fr.sc],r+z[i].sc);
    }
    cout<<cal(1,2*n)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;
int n;
pair<pii,int>z[100100];
ll dp[100100*4];

void add(int a,int b,ll x,int l =1,int h= 2*n, int p =1){
    if(a == l && b== h){
        dp[p] = max(dp[p],x);
        return ;
    }
    int m = (l+h)/2;
    if(b <= m){
        add(a,b,x,l,m,2*p);
    }
    else if(a> m){
        add(a,b,x,m+1,h,2*p+1);
    }
    else{
        add(a,m,x,l,m,2*p);
        add(m+1,b,x,m+1,h,2*p+1);
    }
    dp[p] = max(dp[2*p],dp[2*p+1]);
}

ll cal(int a,int b,ll x=0,int l =1,int h= 2*n , int p =1){
    if(a == l && b== h){
        return dp[p];
    }
    int m = (l+h)/2;
    if(b <= m){
        return cal(a,b,x,l,m,2*p);
    }
    else if(a> m){
        return cal(a,b,x,m+1,h,2*p+1);
    }
    else{
        return max(cal(a,m,x,l,m,2*p),cal(m+1,b,x,m+1,h,2*p+1));
    }
}
int a1[200100];
map<int,int> nm;
int main(){
    int k=0,k1=0;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(b,a),h);
        a1[k1++] = a;
        a1[k1++] = b;
    }
    sort(a1,a1+k1);
    nm[a1[0]] = 1;
    int k2= 1;
    for(int i=1 ; i<k1 ; i++){
        if(a1[i] != a1[i-1])
            k2++;
        nm[a1[i]] = k2;
    }
    sort(z,z+k);
    reverse(z,z+k);

    ll r=0;
    for(int i=0 ; i<n ;i ++){
        r= 0;
        if(nm[z[i].fr.fr] != 1)
            r = cal(1,nm[z[i].fr.fr]-1);
        add(nm[z[i].fr.sc],nm[z[i].fr.sc],r+z[i].sc);
    }
    cout<<cal(1,2*n)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;

pair<pii,int>z[500100];

int main(){
    int k=0;
    int n;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(a,1),h);
        z[k++] = mp(mp(b,0),h);
    }

    sort(z,z+k);
    ll mx = 0,r=0;
    for(int i=0 ; i<k ;i ++){
        if(z[i].fr.sc){
            r+=z[i].sc;
        }
        else{
            r -= z[i].sc;
        }
        mx = max(mx,r);
    }
    cout<<mx<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;
int n;
pair<pii,int>z[100100];
ll dp[200100*4];

void add(int a,int b,ll x,int l =1,int h= 2*n, int p =1){
    if(a == l && b== h){
        dp[p] = max(dp[p],x);
        return ;
    }
    int m = (l+h)/2;
    if(b <= m){
        add(a,b,x,l,m,2*p);
    }
    else if(a> m){
        add(a,b,x,m+1,h,2*p+1);
    }
    else{
        add(a,m,x,l,m,2*p);
        add(m+1,b,x,m+1,h,2*p+1);
    }
    dp[p] = max(dp[2*p],dp[2*p+1]);
}

ll cal(int a,int b,ll x=0,int l =1,int h= 2*n , int p =1){
    if(a == l && b== h){
        return dp[p];
    }
    int m = (l+h)/2;
    if(b <= m){
        return cal(a,b,x,l,m,2*p);
    }
    else if(a> m){
        return cal(a,b,x,m+1,h,2*p+1);
    }
    else{
        return max(cal(a,m,x,l,m,2*p),cal(m+1,b,x,m+1,h,2*p+1));
    }
}
int a1[200100];
map<int,int> nm;
int main(){
    int k=0,k1=0;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(b,a),h);
        a1[k1++] = a;
        a1[k1++] = b;
    }
    sort(a1,a1+k1);
    nm[a1[0]] = 1;
    int k2= 1;
    for(int i=1 ; i<k1 ; i++){
        if(a1[i] != a1[i-1])
            k2++;
        nm[a1[i]] = k2;
    }
    sort(z,z+k);
    reverse(z,z+k);

    ll r=0;
    for(int i=0 ; i<n ;i ++){
        r= 0;
        if(nm[z[i].fr.fr] != 1)
            r = cal(1,nm[z[i].fr.fr]-1);
        add(nm[z[i].fr.sc],nm[z[i].fr.sc],r+z[i].sc);
    }
    cout<<cal(1,2*n)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;

pair<pii,int>z[500100];

int main(){
    int k=0;
    int n;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(a,1),h);
        z[k++] = mp(mp(b,0),h);
    }

    sort(z,z+k);
    ll mx = 0,r=0;
    for(int i=0 ; i<n ;i ++){
        if(z[i].fr.sc){
            r+=z[i].sc;
        }
        else{
            r -= z[i].sc;
        }
        mx = max(mx,r);
    }
    cout<<mx<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;

pair<pll,ll>z[500100];

int main(){
    int k=0;
    int n;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(a,b),h);
    }

    sort(z,z+k);
    ll mx = 0,r=0,st=0;
    for(int i=0 ; i<n ;i ++){
        if(st <= z[i].fr.fr)
            st = z[i].fr.sc,r = 0;
        st = max(st,z[i].fr.sc);
        r += z[i].sc;
        mx = max(mx,r);
    }
    cout<<mx<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007
#define eps 1e-8
#define inf 1e18
const double PI = acos(-1);

using namespace std;
int n;
pair<pll,ll>z[500100];
ll dp[100100*8];

void add(int a,int b,ll x,int l =1,int h= 2*n, int p =1){
    if(a == l && b== h){
        dp[p] = max(dp[p],x);
        return ;
    }
    int m = (l+h)/2;
    if(b <= m){
        add(a,b,x,l,m,2*p);
    }
    else if(a> m){
        add(a,b,x,m+1,h,2*p+1);
    }
    else{
        add(a,m,x,l,m,2*p);
        add(m+1,b,x,m+1,h,2*p+1);
    }
    dp[p] = max(dp[2*p],dp[2*p+1]);
}

ll cal(int a,int b,ll x=0,int l =1,int h= 2*n , int p =1){
    if(a == l && b== h){
        return dp[p];
    }
    int m = (l+h)/2;
    if(b <= m){
        return cal(a,b,x,l,m,2*p);
    }
    else if(a> m){
        return cal(a,b,x,m+1,h,2*p+1);
    }
    else{
        return max(cal(a,m,x,l,m,2*p),cal(m+1,b,x,m+1,h,2*p+1));
    }
}
int a1[200100];
int nm[200100];
int main(){
    int k=0,k1=0;
    cin>>n;
    int a,b,h;
    for(int i=0 ; i<n ;i ++){
        scanf("%d%d%d",&a,&b,&h);
        z[k++] = mp(mp(b,a),h);
        a1[k1++] = a;
        a1[k1++] = b;
    }
    sort(a1,a1+k1);
    nm[a1[0]] = 1;
    int k2= 2;
    for(int i=1 ; i<k1 ; i++){
        if(a1[i] != a1[i-1])
            k2++;
        nm[a1[i]] = k2;
    }
    sort(z,z+k);
    reverse(z,z+k);

    ll mx = 0,r=0;
    for(int i=0 ; i<n ;i ++){
        r= 0;
        if(nm[z[i].fr.fr] != 1)
            r = cal(1,nm[z[i].fr.fr]-1);
        add(nm[z[i].fr.sc],nm[z[i].fr.sc],r+z[i].sc);
    }
    cout<<cal(1,2*n)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define all(a) a.begin(),a.end()
#define bitcnt(x) __builtin_popcountll(x)
#define inp(x) scanf("%lld",&x)
#define out(x) printf("%lld\n",x)
#define nl printf("\n")
#define tc int t;scanf("%d",&t);while (t-->0)
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 10000000019
#define MAXN 500005
#define ninf -1000000000
#define pinf 1000000009
//typedef unsigned long long int uint64;
typedef long long ll;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;

ll sm=0;

vecpair3 v(1000006);

ll dp[1000006]={0};

ll func(ll curr, ll prv, ll n)
{
	//debug(n);

	if(curr>n)
	{
		//debug(n);
		return 0;
	}

	if(dp[curr]!=0)
	return dp[curr];

	else
	{
		//debug(curr);

		if(v[curr].ft> v[prv].snd)
		{
			debug(prv);
			cout<<"***"<<v[curr].ft<<" "<<v[prv].snd<<"***\n";
			sm= max(v[curr].td + func(curr+1,curr,n), func(curr+1, prv,n));
		}

		else
		sm = func(curr+1, prv,n);

		//debug(sm);

		dp[curr]=sm;

		return dp[curr];
	}

	//debug(curr);

}

bool sortinrev(const pair<int, pair<int,int> > &a, const pair<int, pair<int,int> >  &b)
{
	if(a.ft>b.ft)
    return (a.first > b.first);

    else if(a.ft==b.ft)
    return (a.snd>b.snd);

    else
    return (a.ft>b.ft);
}

int main()
{
	ll n,i,j,k,l;

	inp(n);

	v[0]=mp(pinf,mp(0,0));

	for(i=1;i<=n;i++)
	{
		inp(j);
		inp(k);
		inp(l);

		v[i]=mp(k,mp(j,l));
	}

	sort(v.begin(),v.end(),sortinrev);

	dp[1]=v[1].td;

	for(i=2;i<=n;i++)
	{
		dp[i]=v[i].td;

		for(j=1;j<i;j++)
		{
			if(v[j].snd<v[i].ft)
			dp[i]=max(dp[i],dp[j]+v[i].td);
		}
	}

	sort(dp+1,dp+n);

	out(dp[n]);

	return  0;
}

/*
5
6 10 4
9 20 19
8 11 18
18 20 1
19 20 8
*/


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define all(a) a.begin(),a.end()
#define bitcnt(x) __builtin_popcountll(x)
#define inp(x) scanf("%lld",&x)
#define out(x) printf("%lld\n",x)
#define nl printf("\n")
#define tc int t;scanf("%d",&t);while (t-->0)
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 10000000019
#define MAXN 500005
#define ninf -1000000000
#define pinf 1000000009
//typedef unsigned long long int uint64;
typedef long long ll;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;

ll sm=0;

vecpair3 v(1000006);

ll dp[1000006]={0};

ll func(ll curr, ll prv, ll n)
{
	//debug(n);

	if(curr>n)
	{
		//debug(n);
		return 0;
	}

	if(dp[curr]!=0)
	return dp[curr];

	else
	{
		//debug(curr);

		if(v[curr].ft> v[prv].snd)
		{
			debug(prv);
			cout<<"***"<<v[curr].ft<<" "<<v[prv].snd<<"***\n";
			sm= max(v[curr].td + func(curr+1,curr,n), func(curr+1, prv,n));
		}

		else
		sm = func(curr+1, prv,n);

		//debug(sm);

		dp[curr]=sm;

		return dp[curr];
	}

	//debug(curr);

}

bool sortinrev(const pair<int, pair<int,int> > &a, const pair<int, pair<int,int> >  &b)
{
	if(a.ft>b.ft)
    return (a.first > b.first);

    else if(a.ft==b.ft)
    return (a.snd>b.snd);

    else
    return (a.ft>b.ft);
}

int main()
{
	ll n,i,j,k,l,mx=0;

	inp(n);

	v[0]=mp(pinf,mp(0,0));

	for(i=1;i<=n;i++)
	{
		inp(j);
		inp(k);
		inp(l);

		v[i]=mp(k,mp(j,l));
	}

	sort(v.begin(),v.end(),sortinrev);

	dp[1]=v[1].td;

	mx=dp[1];

	for(i=2;i<=n;i++)
	{
		dp[i]=v[i].td;

		for(j=1;j<i;j++)
		{
			if(v[j].snd<v[i].ft)
			dp[i]=max(dp[i],dp[j]+v[i].td);
		}
		//debug(dp[i]);
		mx=max(mx,dp[i]);
	}

	//sort(dp,dp+n);

	out(mx);

	return  0;
}

/*
5
6 10 4
9 20 19
8 11 18
18 20 1
19 20 8

/////////////////

5
21 25 26
14 30 22
6 29 30
13 23 21
10 11 5

*/


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define all(a) a.begin(),a.end()
#define bitcnt(x) __builtin_popcountll(x)
#define inp(x) scanf("%lld",&x)
#define out(x) printf("%lld\n",x)
#define nl printf("\n")
#define tc int t;scanf("%d",&t);while (t-->0)
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 10000000019
#define MAXN 500005
#define ninf -1000000000
#define pinf 1000000009
//typedef unsigned long long int uint64;
typedef long long ll;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;
typedef pair<ll, pair<ll,ll> > pair3;

ll sm=0;

vecpair3 v;

bool sortinrev(const pair<int, pair<int,int> > &a, const pair<int, pair<int,int> >  &b)
{
	if(a.ft>b.ft)
    return (a.first > b.first);

    else if(a.ft==b.ft)
    return (a.snd>b.snd);

    else
    return (a.ft>b.ft);
}

int main()
{
	ll n,i,j,k,l,mx=0;

	inp(n);

	for(i=0;i<n;i++)
	{
		inp(j);
		inp(k);
		inp(l);

		v.pb(mp(k,mp(j,l)));
	}

	sort(v.begin(),v.end(),sortinrev);

	for(i=0;i<n;i++)
	{
		//debug(v[i].snd);
	}

	stack<pair3> s;

	s.push(v[0]);

	mx=0;
	ll ans=v[0].td;

	for(i=1;i<n;i++)
	{
		mx=max(mx,ans);

		//debug(mx);

		//debug(v[i].ft);
		//debug(s.top().snd);

		while(v[i].ft<s.top().snd)
		{
			ans-=s.top().td;
			s.pop();

			if(s.empty())
			break;

		}
		s.push(v[i]);
		ans+=v[i].td;

	}

	mx=max(mx,ans);

	out(mx);

	return  0;
}

/*
5
6 10 4
9 20 19
8 11 18
18 20 1
19 20 8

/////////////////

5
21 25 26
14 30 22
6 29 30
13 23 21
10 11 5

*/


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define all(a) a.begin(),a.end()
#define bitcnt(x) __builtin_popcountll(x)
#define inp(x) scanf("%lld",&x)
#define out(x) printf("%lld\n",x)
#define nl printf("\n")
#define tc int t;scanf("%d",&t);while (t-->0)
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 10000000019
#define MAXN 500005
#define ninf -1000000000
#define pinf 1000000009
//typedef unsigned long long int uint64;
typedef long long ll;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;

ll sm=0;

vecpair3 v(1000006);

ll dp[1006][1006]={0};

ll func(ll curr, ll prv, ll n)
{
	//debug(n);

	if(curr>n)
	{
		//debug(n);
		return 0;
	}

	if(dp[curr][prv]!=0)
	return dp[curr][prv];

	else
	{
		//debug(curr);

		if(v[curr].ft> v[prv].snd)
		sm= max(v[curr].td + func(curr+1,curr,n), func(curr+1, prv,n));

		else
		sm = func(curr+1, prv,n);

		//debug(sm);

		dp[curr][prv]=sm;

		return dp[curr][prv];
	}

	//debug(curr);

}

bool sortinrev(const pair<int, pair<int,int> > &a, const pair<int, pair<int,int> >  &b)
{
       return (a.first > b.first);
}

int main()
{
	ll n,i,ans,j,k,l;

	inp(n);

	v[0]=mp(pinf,mp(0,0));

	for(i=1;i<=n;i++)
	{
		inp(j);
		inp(k);
		inp(l);

		v[i]=mp(k,mp(j,l));
	}

	sort(v.begin(),v.end(),sortinrev);

	/*
	for(i=1;i<=n;i++)
	{
		cout<<"***"<<v[i].ft<<" "<<v[i].snd<<" "<<v[i].td<<"***";
		nl;
	}*/

	ans=func(1,0,n);

	out(ans);

	return  0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define all(a) a.begin(),a.end()
#define bitcnt(x) __builtin_popcountll(x)
#define inp(x) scanf("%lld",&x)
#define out(x) printf("%lld\n",x)
#define nl printf("\n")
#define tc int t;scanf("%d",&t);while (t-->0)
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 10000000019
#define MAXN 500005
#define ninf -1000000000
#define pinf 1000000009
//typedef unsigned long long int uint64;
typedef long long ll;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;

ll sm=0;

vecpair3 v(1000006);

ll dp[1000006]={0};

ll func(ll curr, ll prv, ll n)
{
	//debug(n);

	if(curr>n)
	{
		//debug(n);
		return 0;
	}

	if(dp[curr]!=0)
	return dp[curr];

	else
	{
		//debug(curr);

		if(v[curr].ft> v[prv].snd)
		{
			debug(prv);
			cout<<"***"<<v[curr].ft<<" "<<v[prv].snd<<"***\n";
			sm= max(v[curr].td + func(curr+1,curr,n), func(curr+1, prv,n));
		}

		else
		sm = func(curr+1, prv,n);

		//debug(sm);

		dp[curr]=sm;

		return dp[curr];
	}

	//debug(curr);

}

bool sortinrev(const pair<int, pair<int,int> > &a, const pair<int, pair<int,int> >  &b)
{
	if(a.ft>b.ft)
    return (a.first > b.first);

    else if(a.ft==b.ft)
    return (a.snd>b.snd);

    else
    return (a.ft>b.ft);
}

int main()
{
	ll n,i,j,k,l,mx=0;

	inp(n);

	v[0]=mp(pinf,mp(0,0));

	for(i=1;i<=n;i++)
	{
		inp(j);
		inp(k);
		inp(l);

		v[i]=mp(k,mp(j,l));
	}

	sort(v.begin(),v.end(),sortinrev);

	dp[1]=v[1].td;

	for(i=2;i<=n;i++)
	{
		dp[i]=v[i].td;

		for(j=1;j<i;j++)
		{
			if(v[j].snd<v[i].ft)
			dp[i]=max(dp[i],dp[j]+v[i].td);
		}
		//debug(dp[i]);
		mx=max(mx,dp[i]);
	}

	//sort(dp,dp+n);

	out(mx);

	return  0;
}

/*
5
6 10 4
9 20 19
8 11 18
18 20 1
19 20 8

/////////////////

5
21 25 26
14 30 22
6 29 30
13 23 21
10 11 5

*/


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define all(a) a.begin(),a.end()
#define bitcnt(x) __builtin_popcountll(x)
#define inp(x) scanf("%lld",&x)
#define out(x) printf("%lld\n",x)
#define nl printf("\n")
#define tc int t;scanf("%d",&t);while (t-->0)
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 10000000019
#define MAXN 500005
#define ninf -1000000000
#define pinf 1000000009
//typedef unsigned long long int uint64;
typedef long long ll;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;
typedef pair<ll, pair<ll,ll> > pair3;

ll sm=0;

vecpair3 v;

bool sortinrev(const pair<int, pair<int,int> > &a, const pair<int, pair<int,int> >  &b)
{
	if(a.ft>b.ft)
    return (a.first > b.first);

    else if(a.ft==b.ft)
    return (a.snd>b.snd);

    else
    return (a.ft>b.ft);
}

int main()
{
	ll n,i,j,k,l,mx=0;

	inp(n);

	for(i=0;i<n;i++)
	{
		inp(j);
		inp(k);
		inp(l);

		v.pb(mp(k,mp(j,l)));
	}

	sort(v.begin(),v.end(),sortinrev);

	for(i=0;i<n;i++)
	{
		//debug(v[i].snd);
	}

	stack<pair3> s;

	s.push(v[0]);

	mx=0;
	ll ans=v[0].td;

	for(i=1;i<n;i++)
	{
		mx=max(mx,ans);

		//debug(mx);

		//debug(v[i].ft);
		//debug(s.top().snd);

		while(v[i].ft<=s.top().snd)
		{
			ans-=s.top().td;
			s.pop();

			if(s.empty())
			break;

		}
		s.push(v[i]);
		ans+=v[i].td;

	}

	mx=max(mx,ans);

	out(mx);

	return  0;
}

/*
5
6 10 4
9 20 19
8 11 18
18 20 1
19 20 8

/////////////////

5
21 25 26
14 30 22
6 29 30
13 23 21
10 11 5

*/


#include <cstdio>
#include <algorithm>
#include <map>
#define PROB "E"
#define ONLINEJUDGE
using namespace std;
typedef long long LL;
const int INF = 1000000001;
const int maxn = 100005;
inline int getint() { int r = 0; bool b = true; char c = getchar(); while ('0' > c || c > '9') {if (c == '-') b = false; c = getchar();} while ('0' <= c && c <= '9') {r = (r<<3) + (r<<1) + (c-'0'); c = getchar();} if (b) return r; return -r; }
LL val[maxn*60], qans;
int lc[maxn*60], rc[maxn*60], tot, rt;
void query(int &now, int l, int r, int ll, int rr) {
	if (now == 0) return;
	if (val[now] <= qans) return;
	if (ll <= l && r <= rr) {
		qans = val[now];
		return;
	}
	int mid = (l + r) >> 1;
	if (ll <= mid) query(lc[now], l, mid, ll, rr);
	if (rr > mid) query(rc[now], mid+1, r, ll, rr);
}
void change(int &now, int l, int r, int pos, LL v) {
	if (now == 0) now = ++tot;
	if (l == r) val[now] = max(val[now], v);
	else {
		int mid = (l + r) >> 1;
		if (pos <= mid) change(lc[now], l, mid, pos, v);
		else change(rc[now], mid+1, r, pos, v);
		val[now] = max(val[lc[now]], val[rc[now]]);
	}
}
void CHANGE(int pos, LL val) {
	change(rt, 0, INF, pos, val);
}
int QUERY(int l, int r) {
	qans = 0;
	query(rt, 0, INF, l, r);
	return qans;
}
struct data_t {
	LL a, b, h;
	void init() { a = getint(); b = getint(); h = getint(); }
} a[maxn];
bool cmp(data_t a, data_t b) { return a.b < b.b || (a.b == b.b && a.a < b.a); }
int main () {
	int n = getint();
	for (int i = 1; i <= n; ++i) { a[i].init(); }
	sort(a+1,a+n+1,cmp);
	LL tmp, ans = 0ll;
	CHANGE(INF, 0);
	for (int i = 1; i <= n; ++i) {
		tmp = QUERY(a[i].a+1, INF) + a[i].h;
		CHANGE(a[i].b, tmp);
		ans = max(ans, tmp);
	}
	printf("%I64d\n", ans);
}


#include <cstdio>
#include <algorithm>
#include <map>
#define PROB "E"
#define ONLINEJUDGE
using namespace std;
typedef long long LL;
const int INF = 1000000007;
const int maxn = 100005;
inline int getint() { int r = 0; bool b = true; char c = getchar(); while ('0' > c || c > '9') {if (c == '-') b = false; c = getchar();} while ('0' <= c && c <= '9') {r = (r<<3) + (r<<1) + (c-'0'); c = getchar();} if (b) return r; return -r; }
map<LL, LL> M;
map<LL, LL>::iterator it;
struct data_t {
	LL a, b, h;
	void init() { a = getint(); b = getint(); h = getint(); }
} a[maxn];
bool cmp(data_t a, data_t b) { return a.b < b.b; }
int main () {
	#ifndef ONLINEJUDGE
	freopen(PROB".in", "r", stdin); freopen(PROB".out", "w", stdout);
	#endif
	int n = getint();
	for (int i = 1; i <= n; ++i) { a[i].init(); }
	sort(a+1,a+n+1,cmp);
	M[0] = 5000000000000007ll;
	M[5000000000000007ll] = -1;
	LL l, r, mid, ans = 0;
	for (int i = 1; i <= n; ++i) {
		l = 0ll; r = 5000000000000007ll;
		while (l < r) {
			mid = (l + r + 1ll) >> 1ll;
			it = M.lower_bound(mid);
			if (it->second > a[i].a) l = mid;
			else r = mid - 1ll;
		}
		M[a[i].h + l] = max(M[a[i].h + l], a[i].b);
		ans = max(ans, a[i].h + l);
	}
	printf("%I64d\n", ans);
	fclose(stdin); fclose(stdout); return 0;
}


#include <cstdio>
#include <algorithm>
#include <map>
#define PROB "E"
#define ONLINEJUDGE
using namespace std;
typedef long long LL;
const int INF = 1000000001;
const int maxn = 100005;
inline int getint() { int r = 0; bool b = true; char c = getchar(); while ('0' > c || c > '9') {if (c == '-') b = false; c = getchar();} while ('0' <= c && c <= '9') {r = (r<<3) + (r<<1) + (c-'0'); c = getchar();} if (b) return r; return -r; }
LL val[maxn*60], qans;
int lc[maxn*60], rc[maxn*60], tot, rt;
void query(int &now, int l, int r, int ll, int rr) {
	if (now == 0) return;
	if (val[now] <= qans) return;
	if (ll <= l && r <= rr) {
		qans = val[now];
		return;
	}
	int mid = (l + r) >> 1;
	if (ll <= mid) query(lc[now], l, mid, ll, rr);
	if (rr > mid) query(rc[now], mid+1, r, ll, rr);
}
void change(int &now, int l, int r, int pos, LL v) {
	if (now == 0) now = ++tot;
	if (l == r) val[now] = max(val[now], v);
	else {
		int mid = (l + r) >> 1;
		if (pos <= mid) change(lc[now], l, mid, pos, v);
		else change(rc[now], mid+1, r, pos, v);
		val[now] = max(val[lc[now]], val[rc[now]]);
	}
}
void CHANGE(int pos, LL val) {
	change(rt, 1, INF, pos, val);
}
LL QUERY(int l, int r) {
	qans = 0ll;
	query(rt, 1, INF, l, r);
	return qans;
}
struct data_t {
	LL a, b, h;
	void init() { a = getint(); b = getint(); h = getint(); }
} a[maxn];
bool cmp(data_t a, data_t b) { return a.b < b.b || (a.b == b.b && a.a < b.a); }
int main () {
	int n = getint();
	for (int i = 1; i <= n; ++i) { a[i].init(); }
	sort(a+1,a+n+1,cmp);
	LL tmp, ans = 0ll;
	CHANGE(INF, 0);
	for (int i = 1; i <= n; ++i) {
		tmp = QUERY(a[i].a+1, INF) + a[i].h;
		CHANGE(a[i].b, tmp);
		ans = max(ans, tmp);
	}
	printf("%I64d\n", ans);
}


#include <cstdio>
#include <algorithm>
#include <map>
#define PROB "E"
#define ONLINEJUDGE
using namespace std;
typedef long long LL;
const int INF = 1000000007;
const int maxn = 100005;
inline int getint() { int r = 0; bool b = true; char c = getchar(); while ('0' > c || c > '9') {if (c == '-') b = false; c = getchar();} while ('0' <= c && c <= '9') {r = (r<<3) + (r<<1) + (c-'0'); c = getchar();} if (b) return r; return -r; }
map<LL, LL> M;
map<LL, LL>::iterator it;
struct data_t {
	LL a, b, h;
	void init() { a = getint(); b = getint(); h = getint(); }
} a[maxn];
bool cmp(data_t a, data_t b) { return a.b < b.b || (a.b == b.b && a.a > b.a); }
int main () {
	int n = getint();
	for (int i = 1; i <= n; ++i) { a[i].init(); }
	sort(a+1,a+n+1,cmp);
	M[0] = 5000000000000007ll;
	M[5000000000000007ll] = 0;
	LL l, r, mid, ans = 0;
	for (int i = 1; i <= n; ++i) {
		l = 0ll; r = 5000000000000007ll;
		while (l < r) {
			mid = (l + r + 1ll) >> 1ll;
			it = M.lower_bound(mid);
			if (it->second > a[i].a) l = mid;
			else r = mid - 1ll;
		}
		M[a[i].h + l] = max(M[a[i].h + l], a[i].b);
		ans = max(ans, a[i].h + l);
	}
	printf("%I64d\n", ans);
}


#include <cstdio>
#include <algorithm>
#include <map>
#define PROB "E"
#define ONLINEJUDGE
using namespace std;
typedef long long LL;
const int INF = 1000000007;
const int maxn = 100005;
inline int getint() { int r = 0; bool b = true; char c = getchar(); while ('0' > c || c > '9') {if (c == '-') b = false; c = getchar();} while ('0' <= c && c <= '9') {r = (r<<3) + (r<<1) + (c-'0'); c = getchar();} if (b) return r; return -r; }
map<LL, LL> M;
map<LL, LL>::iterator it;
struct data_t {
	LL a, b, h;
	void init() { a = getint(); b = getint(); h = getint(); }
} a[maxn];
bool cmp(data_t a, data_t b) { return a.b < b.b || (a.b == b.b && a.a < b.a); }
int main () {
	#ifndef ONLINEJUDGE
	freopen(PROB".in", "r", stdin); freopen(PROB".out", "w", stdout);
	#endif
	int n = getint();
	for (int i = 1; i <= n; ++i) { a[i].init(); }
	sort(a+1,a+n+1,cmp);
	M[0] = 5000000000000007ll;
	M[5000000000000007ll] = -1;
	LL l, r, mid, ans = 0;
	for (int i = 1; i <= n; ++i) {
		l = 0ll; r = 5000000000000007ll;
		while (l < r) {
			mid = (l + r + 1ll) >> 1ll;
			it = M.lower_bound(mid);
			if (it->second > a[i].a) l = mid;
			else r = mid - 1ll;
		}
		M[a[i].h + l] = max(M[a[i].h + l], a[i].b);
		ans = max(ans, a[i].h + l);
	}
	printf("%I64d\n", ans);
}


#include <cstdio>
#include <algorithm>
#include <map>
#define PROB "E"
#define ONLINEJUDGE
using namespace std;
typedef long long LL;
const int INF = 1000000007;
const int maxn = 100005;
inline int getint() { int r = 0; bool b = true; char c = getchar(); while ('0' > c || c > '9') {if (c == '-') b = false; c = getchar();} while ('0' <= c && c <= '9') {r = (r<<3) + (r<<1) + (c-'0'); c = getchar();} if (b) return r; return -r; }
map<LL, LL> M;
map<LL, LL>::iterator it;
struct data_t {
	LL a, b, h;
	void init() { a = getint(); b = getint(); h = getint(); }
} a[maxn];
bool cmp(data_t a, data_t b) { return a.b < b.b; }
int main () {
	#ifndef ONLINEJUDGE
	freopen(PROB".in", "r", stdin); freopen(PROB".out", "w", stdout);
	#endif
	int n = getint();
	for (int i = 1; i <= n; ++i) { a[i].init(); }
	sort(a+1,a+n+1,cmp);
	M[0] = 200000000000007ll;
	M[200000000000007ll] = -1;
	LL l, r, mid, ans = 0;
	for (int i = 1; i <= n; ++i) {
		l = 0; r = 200000000000007ll;
		while (l < r) {
			mid = (l + r + 1ll) >> 1ll;
			it = M.lower_bound(mid);
			if (it->second > a[i].a) l = it->first;
			else {
				--it;
				r = it->first;
			}
		}
		M[a[i].h + l] = max(M[a[i].h + l], a[i].b);
		ans = max(ans, a[i].h + l);
	}
	printf("%I64d\n", ans);
	fclose(stdin); fclose(stdout); return 0;
}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
ll n,ans;
ll dp[100005];
struct ring{
	ll a,b,h;
	inline bool operator <(const ring x){
		if(b>x.b) return 1;
		if(b<x.b) return 0;
		if(a<x.a) return 0;
		if(a>x.a) return 1;
		return h<x.h;
	}
}rings[100005];
stack<int> st;
int main(){
	ios_base::sync_with_stdio(false);
	int i,j;
	rd(n);
	rings[0].b=1000000009;
	for(i=1;i<=n;i++) rd(rings[i].a),rd(rings[i].b),rd(rings[i].h);
	sort(rings+1,rings+n+1);
	for(i=1;i<=n;i++) {
		while(!st.empty()&&rings[st.top()].a>=rings[i].b) st.pop();
		if(!st.empty()) dp[i]=dp[st.top()];
    	dp[i]+=rings[i].h;
    	st.push(i);
	}
	for(i=0;i<=n;i++) ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}