# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

struct plate{
	int a, b, h;
};

plate p[100005];
int n, m;
ll f[100005], ans = 0;
stack <int> S;

bool cmp(plate p, plate q) {
	return p.b > q.b;
}

int main() {
	//file_put();

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d%d%d", &p[i].a, &p[i].b, &p[i].h);
	sort(p + 1, p + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		while (!S.empty() && p[S.top()].a >= p[i].b) S.pop();
		if (!S.empty()) f[i] = f[S.top()];
		f[i] += p[i].h;
		ans = max(ans, f[i]);
		S.push(i);
	}
	printf("%I64d\n", ans);

	return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

struct plate{
	int a, b, h;
};

plate p[100005];
int n, m;
ll f[100005], ans = 0;
stack <int> S;

bool cmp(plate p, plate q) {
	return p.b > q.b || p.b == q.b && p.h > q.h;
}

int main() {
	//file_put();

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d%d%d", &p[i].a, &p[i].b, &p[i].h);
	sort(p + 1, p + n + 1, cmp);
	for (int i = n; i >= 1; i--)
		if (p[i].b == p[i - 1].b)
			p[i - 1].h += p[i].h;
	for (int i = 1; i <= n; i++) {
		if (p[i].b == p[i-1].b) continue;
		while (!S.empty() && p[S.top()].a >= p[i].b) S.pop();
		if (!S.empty()) f[i] = f[S.top()];
		f[i] += p[i].h;
		ans = max(ans, f[i]);
		S.push(i);
	}
	printf("%I64d\n", ans);

	return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

struct plate{
	int a, b, h;
};

plate p[100005];
int n, m;
ll f[100005], ans = 0;
stack <int> S;

bool cmp(plate p, plate q) {
	return p.b > q.b || p.b == q.b && p.h > q.h;
}

int main() {
	//file_put();

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d%d%d", &p[i].a, &p[i].b, &p[i].h);
	sort(p + 1, p + n + 1, cmp);
	for (int i = n; i >= 1; i--)
		if (p[i].b == p[i - 1].b) {
			p[i - 1].h += p[i].h;
			p[i - 1].a = min(p[i - 1].a, p[i].a);
		}
	for (int i = 1; i <= n; i++) {
		if (p[i].b == p[i-1].b) continue;
		while (!S.empty() && p[S.top()].a >= p[i].b) S.pop();
		if (!S.empty()) f[i] = f[S.top()];
		f[i] += p[i].h;
		ans = max(ans, f[i]);
		S.push(i);
	}
	printf("%I64d\n", ans);

	return 0;
}


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	tree[v].mx = ans[v];
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, long long i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, int> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[i] = as[i].second;
	build(1, n, 1);

	for(int i = 0; i < n; ++i)
	{
		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 2000000000)) - as.begin();
		if(ind != -1)
		{
			long long m = getMax(1, ind, 1);
			int id = ids[i];
			ans[i+1] = m + v[i].second;
			update(ans[i+1], id + 1, 1);
		}
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <ctime>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[1900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, int i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

bool cmp(const pair<pair<int, int>, long long> & a, const pair<pair<int, int>, long long> b)
{
	if(a.first.second != b.first.second)
		return a.first.second > b.first.second;
	if(a.first.first != b.first.first)
		return a.first.first > b.first.first;
	return a.second < b.second;
}

long long getStupidAns(vector<pair<pair<int, int>, long long> > v)
{
	sort(v.begin(), v.end(), cmp);
	vector<long long> dp(v.size(), 0ll);
	for(int i = 0; i < v.size(); ++i)
	{
		dp[i] = v[i].second;
		for(int j = 0; j < i; ++j)
			if(v[i].first.second > v[j].first.first)
				dp[i] = max(dp[i], dp[j] + v[i].second);
	}
	long long mx = 0;
	for(int i = 0; i < v.size(); ++i)
		mx = max(mx, dp[i]);
	return mx;
}

int nn;
int aa[123456];
int bb[123456];
int hh[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	//n = nn = 5;
	srand(time(0));
	vector<pair<pair<int, int>, long long> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		//a = rand() % 10;
		//b = rand() % 10;
		//h = rand() % 1000;
		aa[i] = a;
		bb[i] = b;
		hh[i] = h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	//long long curAnswer = getStupidAns(v1);
	//cout << curAnswer;
	//return 0;
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);
	for(int i = 0; i < n; ++i)
	{
		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 0)) - as.begin();
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	long long answer = *max_element(ans + 1, ans + n + 1);
	//cout << answer;
	if(curAnswer != answer)
	{
		cout << curAnswer << " " << answer << endl;
		cout << n << endl;
		for(int i = 0; i < nn; ++i)
			cout << aa[i] << " " << bb[i] << " " << hh[i] << endl;
	}
}

/*

1202 1721
5
3 7 398
3 6 476
7 8 428
2 3 419
6 5 328

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[1900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, int i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, long long> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	//if(n == 100000)
	//	cout << v.size() << endl;
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);
	//if(v11.size() == 100000)
	//	cout << "HOROSHO" << endl;
	for(int i = 0; i < n; ++i)
	{

		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 2000000000)) - as.begin();
		//if(v1.size() == 100000)
		//	cout << ind << " " << as.size() << endl;
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[1900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	tree[v].mx = ans[v];
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, int i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, int> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	if(n == 100000)
		cout << v.size() << endl;
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);
	if(v1.size() == 100000)
		cout << "HOROSHO" << endl;
	for(int i = 0; i < n; ++i)
	{

		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 2000000000)) - as.begin();
		if(v1.size() == 100000)
			cout << ind << " " << as.size() << endl;
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <ctime>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[1900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, int i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

bool cmp(const pair<pair<int, int>, long long> & a, const pair<pair<int, int>, long long> b)
{
	if(a.first.second != b.first.second)
		return a.first.second > b.first.second;
	if(a.first.first != b.first.first)
		return a.first.first > b.first.first;
	return a.second < b.second;
}

long long getStupidAns(vector<pair<pair<int, int>, long long> > v)
{
	sort(v.begin(), v.end(), cmp);
	vector<long long> dp(v.size(), 0ll);
	for(int i = 0; i < v.size(); ++i)
	{
		dp[i] = v[i].second;
		for(int j = 0; j < i; ++j)
			if(v[i].first.second > v[j].first.first)
				dp[i] = max(dp[i], dp[j] + v[i].second);
	}
	long long mx = 0;
	for(int i = 0; i < v.size(); ++i)
		mx = max(mx, dp[i]);
	return mx;
}

int nn;
int aa[123456];
int bb[123456];
int hh[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	//n = nn = 5;
	srand(time(0));
	vector<pair<pair<int, int>, long long> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		//a = rand() % 10;
		//b = rand() % 10;
		//h = rand() % 1000;
		aa[i] = a;
		bb[i] = b;
		hh[i] = h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	//long long curAnswer = getStupidAns(v1);
	//cout << curAnswer;
	//return 0;
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);
	for(int i = 0; i < n; ++i)
	{
		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 0)) - as.begin();
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	long long answer = *max_element(ans + 1, ans + n + 1);
	cout << answer;
	/*if(curAnswer != answer)
	{
		cout << curAnswer << " " << answer << endl;
		cout << n << endl;
		for(int i = 0; i < nn; ++i)
			cout << aa[i] << " " << bb[i] << " " << hh[i] << endl;
	}*/
}

/*

1202 1721
5
3 7 398
3 6 476
7 8 428
2 3 419
6 5 328

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[1900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, int i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, int> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	//if(n == 100000)
	//	cout << v.size() << endl;
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);
	//if(v1.size() == 100000)
	//	cout << "HOROSHO" << endl;
	for(int i = 0; i < n; ++i)
	{

		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 2000000000)) - as.begin();
		//if(v1.size() == 100000)
		//	cout << ind << " " << as.size() << endl;
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	tree[v].mx = ans[v];
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, long long i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, int> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	n = v.size();
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.first, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[i] = as[i].second;
	build(1, n, 1);

	for(int i = 0; i < n; ++i)
	{
		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.second, 2000000000)) - as.begin();
		if(ind != -1)
		{
			long long m = getMax(1, ind, 1);
			int id = ids[i];
			ans[i+1] = m + v[i].second;
			update(ans[i+1], id + 1, 1);
		}
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[1900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	tree[v].mx = ans[v];
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, long long i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, int> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);

	for(int i = 0; i < n; ++i)
	{
		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 2000000000)) - as.begin();
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

struct Tree
{
	int l, r;
	long long mx;
};

Tree tree[900000];
long long ans[123456];
void build(int l, int r, int v)
{
	tree[v].l = l;
	tree[v].r = r;
	tree[v].mx = ans[v];
	if(l == r)
		return;
	int m = (l+r) >> 1;
	build(l, m, 2*v);
	build(m+1, r, 2*v+1);
}

long long getMax(int l, int r, int v)
{
	if(tree[v].l >= l && tree[v].r <= r)
		return tree[v].mx;
	if(tree[v].l > r || tree[v].r < l)
		return 0;
	return max(getMax(l, r, 2*v), getMax(l, r, 2*v+1));
}

void update(long long x, long long i, int v)
{
	if(tree[v].l == tree[v].r)
	{
		tree[v].mx = x;
		return;
	}
	update(x, i, 2*v + (tree[2*v].r < i));
	tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
}

int ids[123456];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	vector<pair<pair<int, int>, int> > v1, v;

	for(int i = 0; i < n; ++i)
	{
		int a, b, h;
		cin >> a >> b >> h;
		v1.push_back (make_pair(make_pair(a, b), h));
	}

	sort(v1.begin(), v1.end());
	v.push_back(v1[0]);
	for(int i = 1; i < n; ++i)
	{
		if(v1[i].first.second == v.back().first.second)
		{
			v.back().first.first = min(v.back().first.first, v1[i].first.first);
			v.back().second += v1[i].second;
		}
		else
			v.push_back(v1[i]);
	}
	n = v.size();
	for(int i = 0; i < n; ++i)
		swap(v[i].first.first, v[i].first.second);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<pair<int, int> > as;
	for(int i = 0; i < n; ++i)
		as.push_back(make_pair(v[i].first.second, i));
	sort(as.begin(), as.end());
	for(int i = 0; i < n; ++i)
		ids[as[i].second] = i;
	build(1, n, 1);

	for(int i = 0; i < n; ++i)
	{
		int ind = lower_bound(as.begin(), as.end(), make_pair(v[i].first.first, 2000000000)) - as.begin();
		long long m = getMax(1, ind, 1);
		int id = ids[i] + 1;
		ans[i+1] = m + v[i].second;
		update(ans[i+1], id, 1);
	}
	cout << *max_element(ans + 1, ans + n + 1);
}

/*
28
#fbeaafabfgdhhgbeehgeacacckbacbaccdbfgbe
#fbeaafabfgdhhgbeehgeacacckbacbaccdbe
#fbeaafabfgdhhgbeehgeacaccj
#fbeaafabfgdhhgbeehf
#fbeaafabfgdevuw
#fbeaadep
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f
#f

*/


#include <cstdio>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <functional>
#include <algorithm>
#include <numeric>
#include <array>

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int,int> ii;
typedef vector<int>  vi;
typedef vector<ii> vii;
typedef vector<ll> vecl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

////////////////////////////////////////////////////////////////////////////////////////////////
//                    START  TEMPLATE
////////////////////////////////////////////////////////////////////////////////////////////////

template< typename T > T gcd(T a, T b){ return b == 0 ? a : gcd(b, a % b); }
template< typename T > T lcm(T a, T b){ return a == 0 && b == 0 ? 0 : a / gcd(a,b) * b; }
template< typename T > T chmax(T& a, T b){ return (a > b ? a : (a = b)); }
template< typename T > T chmin(T& a, T b){ return (a < b ? a : (a = b)); }
inline int read(int& a){ return scanf("%d",&a);}
inline int read(int& a, int&b){ return scanf("%d%d",&a,&b);}
inline int read(int& a, int&b, int&c){ return scanf("%d%d%d",&a,&b,&c);}
inline int read(ll& a){ return scanf("%lld",&a);}
inline int read(ll&a , ll&b){ return scanf("%lld%lld",&a,&b);}
inline int read(ll&a, ll&b, ll&c){ return scanf("%lld%lld%lld",&a,&b,&c);}
inline int read(ld& a){ return scanf("%lf",&a);}
inline int read(ld& a, ld&b){ return scanf("%lf%lf",&a,&b);}
inline int read(ld& a, ld&b, ld&c){ return scanf("%lf%lf%lf",&a,&b,&c);}
inline int read(vi& v){  for(int i= 0, n = v.size(); i < n; ++i)read(v[i]); return 0;}

inline int writeln(int a){return printf("%d\n", a); }
inline int writeln(int a, int b){ return printf("%d %d\n", a, b); }
inline int writeln(vi const& v) { for(int i= 0, n = v.size(); i < n; ++i)printf("%d%c", v[i], " \n"[ i == n - 1 ]); return 0; }
inline int writeln(ll a){ return printf("%lld\n", a);}
inline int writeln(ll a, ll b){ return printf("%lld %lld\n", a,b);}
inline int writeln(const char* s){ return printf("%s\n", s);}
inline int writeln(const string& s){ return writeln(s.c_str()); }

// right left next prev  rank y1 y2 - are common standard functions, user cannot use it direct way.
#define right fkkhghklllhjuu
#define left  dfkjsdlkfjsd
#define next  reiuyrweiyr
#define prev  iuyieyriyei
#define rank  nukihyiuiuiu
#define y1    y123444444343
#define y2    y2234343434343

#define fi  first
#define se  second
#define mp  make_pair
#define pb  push_back
#define sz(c)         (int)(c.size())
#define all(c)        (c).begin(), (c).end()
#define fori(n)       forn(i,n)
#define forj(n)       forn(j,n)
#define forn(i,n)     fore(i,0,n)
#define fore(i,a,b)   for(int i = (a), b_ = (b); i < b_; ++i)

static const ld  PI  = acos(-1.0);
static const ld  EPS = 1.0E-9;
static const int MOD = 1000000000 + 7;

inline int add_mod(int x, int y){ x += y; return x >= MOD ? x - MOD: x; }
inline int sub_mod(int x, int y){ x -= y; return x < 0 ? x + MOD : x;}
inline int mul_mod(int x, int y){ return x * (ll)y % MOD; }
inline int bits_count(ll x){ return x == 0 ? 0 : 1 + bits_count( x & ( x - 1 ) ); }

ll power(ll x, ll n){
    ll r = 1;
    while(n)
    {
        if (n&1) r = mul_mod(r, x);
        x = mul_mod(x,x);
        n /= 2;
    }
    return r;
}

template< typename C > void sort(C& c){ sort(c.begin(), c.end());}
template< typename C, typename Op> void sort(C&c, Op op){ sort(c.begin(), c.end(), op);}
/////////////////////////////////////////////////////////////////////////////////////////
///                       END   TEMPLATE
/////////////////////////////////////////////////////////////////////////////////////////
struct honoi{
    int a,b,h;
};

struct cmp_b{
    bool operator()(honoi const& lhs, honoi const& rhs)const
    {
        return lhs.b > rhs.b || (lhs.b == rhs.b && lhs.a > rhs.a);
    }
};

struct segment_tree
{
    static const int N = 1 << 20;

    ll t[ N + N ];

    void add(int p, ll x)
    {
        p = p + N;
        t [ p ] = max( t[ p ], x);

        while( p > 1 )
        {
            p >>= 1;
            t[ p ] = max(t[p << 1] , t[ p << 1 | 1]);
        }
    }

    ll query(int l, int r) // max that >= p
    {
        ll ans = 0;
        for(l += N, r += N; l < r; l >>= 1, r >>= 1)
        {
            if (l&1) ans = max(ans, t[l++]);
            if (r&1) ans = max(ans, t[--r]);
        }

        return ans;
    }
}tree;

static int solve()
{
    int n;
    read(n);
    vector< honoi > v(n);
    fori(n) scanf("%d%d%d",&(v[i].a), &(v[i].b), &(v[i].h));//read(v[i].a,  v[i].b, v[i].h);

    sort(all(v), cmp_b());

    vi s;
    s.pb(0);
    fori(n)s.pb(v[i].a);
    fori(n)s.pb(v[i].b);

    sort(all(s));
    s.erase(unique(all( s ) ), s.end());

    fori(n) v[i].a = lower_bound(s.begin(), s.end(), v[i].a) - s.begin(),
            v[i].b = lower_bound(s.begin(), s.end(), v[i].b) - s.begin();

    // dp[i] - i ishlatgandagi maximum
    ll ans = 0;

    fori(n){

        // v[j].a < v[i].b
        ll mx =  tree.query( 0, v[ i ].b ) ;
        //forj(i)if (v[j].a < v[i].b)mx = max(mx, dp[j]);
        //dp[ i ] = mx + v[ i ].h;

        ans = max(ans, mx + v[i].h );

        tree.add( v[i].a, mx + v[i].h );
    }

    writeln(ans);
    return 0;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false); std::cin.tie(0);std::cout.tie(0);

    solve();

    return 0;
}


// rc.cpp : Defines the entry point for the console application.
//

#include <math.h>

#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <functional>
#include <iomanip>

using namespace std;

#define PI 3.14159265358979323846
#define EPS 1.E-8

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

struct ring
{
	uint a, b;
	uint64 h;
	bool operator<(const ring& o) const
	{
		if (b == o.b)
			return a > o.a;

		return b > o.b;
	}
};

ring v[100000];

int main(int argc, char* argv[])
{
	uint n;
	cin >> n;

	for (uint i = 0; i < n; ++i)
		cin >> v[i].a >> v[i].b >> v[i].h;

	sort(v, v + n);

	uint64 mh = v[0].h, ch = v[0].h;
	stack<uint> s;
	s.push(0);
	for (uint i = 1; i <= n; ++i)
	{
		uint j = s.top();
		if (i == n || v[i].b <= v[j].a)
		{
			if (ch > mh)
				mh = ch;

			if (i < n)
			{
				while (!s.empty() && v[i].b <= v[j].a)
				{
					ch -= v[j].h;
					s.pop();

					if (!s.empty())
						j = s.top();
				}

				s.push(i);
				ch += v[i].h;
			}
		}
		else
		{
			ch += v[i].h;
			s.push(i);
		}

		if (ch > mh)
			mh = ch;
	}

	cout << mh << endl;
	return 0;
}


// rc.cpp : Defines the entry point for the console application.
//

#include <math.h>

#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <functional>
#include <iomanip>

using namespace std;

#define PI 3.14159265358979323846
#define EPS 1.E-8

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

struct ring
{
	uint a, b;
	uint64 h;
	bool operator<(const ring& o) const
	{
		if (b == o.b)
			return a > o.a;

		return b > o.b;
	}
};

ring v[100000];

int main(int argc, char* argv[])
{
	uint n;
	cin >> n;

	for (uint i = 0; i < n; ++i)
		cin >> v[i].a >> v[i].b >> v[i].h;

	sort(v, v + n);

	uint64 mh = v[0].h, ch = v[0].h;
	stack<uint> s;
	s.push(0);
	for (uint i = 1; i <= n; ++i)
	{
		uint j = s.top();
		if (i == n || v[i].b <= v[j].a)
		{
			if (ch > mh)
				mh = ch;

			if (i < n)
			{
				while (!s.empty() && v[i].b <= v[j].a)
				{
					ch -= v[j].h;
					s.pop();
					j = s.top();
				}

				s.push(i);
				ch += v[i].h;
			}
		}
		else
		{
			ch += v[i].h;
			s.push(i);
		}

		if (ch > mh)
			mh = ch;
	}

	cout << mh << endl;
	return 0;
}


// rc.cpp : Defines the entry point for the console application.
//

#include <math.h>

#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <functional>
#include <iomanip>

using namespace std;

#define PI 3.14159265358979323846
#define EPS 1.E-8

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

struct ring
{
	uint a, b;
	uint64 h;
	bool operator<(const ring& o) const
	{
		if (b == o.b)
			return a > o.a;

		return b > o.b;
	}
};

ring v[100000];

int main(int argc, char* argv[])
{
	uint n;
	cin >> n;

	for (uint i = 0; i < n; ++i)
		cin >> v[i].a >> v[i].b >> v[i].h;

	sort(v, v + n);

	uint64 mh = v[0].h, ch = v[0].h;
	for (uint i = 1; i <= n; ++i)
	{
		if (i == n || v[i].b <= v[i - 1].a)
		{
			if (ch > mh)
				mh = ch;

			if (i < n)
				ch = v[i].h;
		}
		else
			ch += v[i].h;
	}

	cout << mh << endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;

const int maxn = 1e5 + 7;

typedef long long ll;

ll dp[maxn] = {0};

struct Disk
{
	int R;
	int r;
	ll Height;
	Disk(){}
	Disk(int R, int r, ll Height) : R(R), r(r), Height(Height) {};

	bool operator< (const Disk Tmp) const
	{
		if (R != Tmp.R)
			return R < Tmp.R;
		return r < Tmp.r;
	}
}mas[maxn];

int main()
{
	ios::sync_with_stdio(0);
	int n;
	stack<Disk> st;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> mas[i].r >> mas[i].R >> mas[i].Height;

	std::sort(mas + 1, mas + n + 1);
	ll ans = 0;
	for(int i = n; i >= 1; i--)
	{
		while(st.size() && st.top().r >= mas[i].R)
			st.pop();
		dp[i] = mas[i].Height;
		if(st.size())
			dp[i] += st.top().Height;

		ans = max(dp[i], dp[i + 1]);
		st.push(Disk(mas[i].R, mas[i].r, dp[i]));
		dp[i] = max(dp[i + 1], dp[i]);

		continue;
	}
    cout << dp[1] << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	freopen_s(&f, "input.txt", "r", stdin);

	int n;
	cin >> n;
	vector < pair <int, pair <int, int> > > s(n);
	for (int i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	int deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <int, pair <int, int> > >());
	for (int i = 0; i < n; i++) {
		int end = i + 1;
		int total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <int, pair <int, int> > >());

	vector <int> ans(n);
	int maxAns = -1;

	stack <int> st;
	for (int i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		int maxx = ans[i];
		for (int j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;
		ans[i] = maxx;
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		unsigned long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <unsigned long long> ans(n);
	unsigned long long maxAns = 0;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		while (!st.empty() && s[st.top()].second.first >= s[i].first) st.pop();
		if (!st.empty()) ans[i] += ans[st.top()];
		st.push(i);
		/*for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;*/
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <long long> ans(n);
	long long maxAns = -1;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		while (!st.empty() && s[st.top()].second.first > s[i].first) st.pop();
		if (!st.empty()) ans[i] += ans[st.top()];
		st.push(i);
		/*for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;*/
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <long long> ans(n);
	long long maxAns = -1;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		long long maxx = ans[i];
		for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;
		ans[i] = maxx;
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		unsigned long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <unsigned long long> ans(n);
	unsigned long long maxAns = 0;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		while (!st.empty() && s[st.top()].second.first > s[i].first) st.pop();
		if (!st.empty()) ans[i] += ans[st.top()];
		st.push(i);
		/*for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;*/
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		unsigned long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <unsigned long long> ans(n);
	unsigned long long maxAns = 0;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		while (!st.empty() && s[st.top()].second.first < s[i].first) st.pop();
		if (!st.empty()) ans[i] += ans[st.top()];
		st.push(i);
		/*for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;*/
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	int n;
	cin >> n;
	vector < pair <int, pair <int, int> > > s(n);
	for (int i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	int deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <int, pair <int, int> > >());
	for (int i = 0; i < n; i++) {
		int end = i + 1;
		int total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <int, pair <int, int> > >());

	vector <int> ans(n);
	int maxAns = -1;

	stack <int> st;
	for (int i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		int maxx = ans[i];
		for (int j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;
		ans[i] = maxx;
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <long long> ans(n);
	long long maxAns = -1;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		long long maxx = ans[i];
		for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;
		ans[i] = maxx;
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	int n;
	cin >> n;
	vector < pair <int, pair <int, int> > > s(n);
	for (int i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	int deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <int, pair <int, int> > >());
	for (int i = 0; i < n; i++) {
		int end = i + 1;
		int total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <int, pair <int, int> > >());

	vector <int> ans(n);
	int maxAns = -1;

	stack <int> st;
	for (int i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		int maxx = ans[i];
		for (int j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;
		ans[i] = maxx;
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>

using namespace std;

void main() {
	FILE *f;
	//freopen_s(&f, "input.txt", "r", stdin);

	long long n;
	cin >> n;
	vector < pair <long long, pair <long long, long long> > > s(n);
	for (long long i = 0; i < n; i++)
		cin >> s[i].second.first >> s[i].first >> s[i].second.second;
	long long deleted = 0;
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());
	for (long long i = 0; i < n; i++) {
		long long end = i + 1;
		unsigned long long total_H = s[i].second.second;
		while (end < n && s[i].first == s[end].first) total_H += s[end].second.second, s[end].first = -1, s[i].second.first = min(s[i].second.first, s[end].second.first), deleted++, end++;
		s[i].second.second = total_H;
		i = end-1;
	}
	sort(s.begin(), s.end(), std::greater< pair <long long, pair <long long, long long> > >());

	vector <unsigned long long> ans(n);
	unsigned long long maxAns = -1;

	stack <long long> st;
	for (long long i = 0; i < n-deleted; i++) {
		ans[i] = s[i].second.second;
 		maxAns = max(maxAns, ans[i]);
		while (!st.empty() && s[st.top()].second.first > s[i].first) st.pop();
		if (!st.empty()) ans[i] += ans[st.top()];
		st.push(i);
		/*for (long long j = 0; j<i; j++)
			if (s[j].second.first <= s[i].first && ans[j] + s[i].second.second > maxx)
				maxx = ans[j] + s[i].second.second;*/
		maxAns = max(maxAns, ans[i]);
	}
	cout << maxAns;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <stack>
#include <set>
#include <list>
#include <sstream>
#include <functional>
#define INF 0x3f3fffff
#define MAX_V 30
#define MAX_N 50000001
#define MOD 1000000007
#define TAG printf("here\n");
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

struct ring {
	int a, b, h;
	bool operator < (ring p) const {
		if (b == p.b) return a > p.a;
		return b > p.b;
	}
}r[100005]; ll mh[100005]; int temp[100005];
ll bit[200005]; int n;
void add(int p, ll x) {
	while (p <= 2 * n) {
		bit[p] = max(bit[p], x);
		p += p & -p;
	}
}
ll getmx(int p) {
	ll res = 0;
	while (p > 0){
		res = max(res, bit[p]);
		p -= p & -p;
	}
	return res;
}
int main() {
	while (cin >> n) {
		memset(bit, 0, sizeof(bit));
		memset(mh, 0, sizeof(mh));
		int cur = 0;
		for (int i = 0; i < n; i++) {
			cin >> r[i].a >> r[i].b >> r[i].h;
			temp[cur++] = r[i].a;
			temp[cur++] = r[i].b;
		}
		sort(temp, temp + cur);
		cur = unique(temp, temp + cur) - temp;
		sort(r, r + n);
		ll res = 0;
		for (int i = 0; i < n; i++) {
			int id = lower_bound(temp, temp + cur, r[i].b) - temp;
			mh[i] = getmx(id + 1) + r[i].h;
			res = max(res, mh[i]);
			id = lower_bound(temp, temp + cur, r[i].a) - temp;
			add(id + 1, mh[i]);
		}
		cout << res << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <stack>
#include <set>
#include <list>
#include <sstream>
#include <functional>
#define INF 0x3f3fffff
#define MAX_V 30
#define MAX_N 50000001
#define MOD 1000000007
#define TAG printf("here\n");
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

struct ring {
	int a, b, h;
	bool operator < (ring p) const {
		if (b == p.b) return a > p.a;
		return b > p.b;
	}
}r[100005]; ll mh[100005]; int temp[200005];
ll bit[200005]; int n;
void add(int p, ll x) {
	while (p <= 2 * n) {
		bit[p] = max(bit[p], x);
		p += p & -p;
	}
}
ll getmx(int p) {
	ll res = 0;
	while (p > 0){
		res = max(res, bit[p]);
		p -= p & -p;
	}
	return res;
}
int main() {
	while (cin >> n) {
		memset(bit, 0, sizeof(bit));
		memset(mh, 0, sizeof(mh));
		int cur = 0;
		for (int i = 0; i < n; i++) {
			cin >> r[i].a >> r[i].b >> r[i].h;
			temp[cur++] = r[i].a;
			temp[cur++] = r[i].b;
		}
		sort(temp, temp + cur);
		cur = unique(temp, temp + cur) - temp;
		sort(r, r + n);
		ll res = 0;
		for (int i = 0; i < n; i++) {
			int id = lower_bound(temp, temp + cur, r[i].b) - temp;
			mh[i] = getmx(id) + r[i].h;
			res = max(res, mh[i]);
			id = lower_bound(temp, temp + cur, r[i].a) - temp;
			add(id + 1, mh[i]);
		}
		cout << res << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <stack>
#include <set>
#include <list>
#include <sstream>
#include <functional>
#define INF 0x3f3fffff
#define MAX_V 30
#define MAX_N 50000001
#define MOD 1000000007
#define TAG printf("here\n");
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

struct ring {
	int a, b, h;
	bool operator < (ring p) const {
		if (b == p.b) return a > p.a;
		return b > p.b;
	}
}r[100005]; ll mh[100005];
int main() {
	int n;
	while (cin >> n) {
		for (int i = 0; i < n; i++) cin >> r[i].a >> r[i].b >> r[i].h;
		sort(r, r + n);
		mh[0] = r[0].h;
		ll res = r[0].h;
		for (int i = 1; i < n; i++) {
			mh[i] = r[i].h;
			for (int j = 0; j < i; j++) {
				if (r[i].b > r[j].a && r[i].b <= r[j].b) mh[i] = max(mh[i], mh[j] + r[i].h);
			}
			res = max(res, mh[i]);
		}
		cout << res << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <stack>
#include <set>
#include <list>
#include <sstream>
#include <functional>
#define INF 0x3f3fffff
#define MAX_V 30
#define MAX_N 50000001
#define MOD 1000000007
#define TAG printf("here\n");
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

struct ring {
	int a, b, h;
	bool operator < (ring p) const {
		if (b == p.b) return a > p.a;
		return b > p.b;
	}
}r[100005]; ll mh[100005]; int temp[200005];
ll bit[200005]; int n;
void add(int p, ll x) {
	while (p <= 2 * n) {
		bit[p] = max(bit[p], x);
		p += p & -p;
	}
}
ll getmx(int p) {
	ll res = 0;
	while (p > 0){
		res = max(res, bit[p]);
		p -= p & -p;
	}
	return res;
}
int main() {
	while (cin >> n) {
		memset(bit, 0, sizeof(bit));
		memset(mh, 0, sizeof(mh));
		int cur = 0;
		for (int i = 0; i < n; i++) {
			cin >> r[i].a >> r[i].b >> r[i].h;
			temp[cur++] = r[i].a;
			temp[cur++] = r[i].b;
		}
		sort(temp, temp + cur);
		cur = unique(temp, temp + cur) - temp;
		sort(r, r + n);
		ll res = 0;
		for (int i = 0; i < n; i++) {
			int id = lower_bound(temp, temp + cur, r[i].b) - temp;
			mh[i] = getmx(id + 1) + r[i].h;
			res = max(res, mh[i]);
			id = lower_bound(temp, temp + cur, r[i].a) - temp;
			add(id + 1, mh[i]);
		}
		cout << res << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <stack>
#include <set>
#include <list>
#include <sstream>
#include <functional>
#define INF 0x3f3fffff
#define MAX_V 30
#define MAX_N 50000001
#define MOD 1000000007
#define TAG printf("here\n");
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

struct ring {
	int a, b, h;
	bool operator < (ring p) const {
		if (b == p.b) return a > p.a;
		return b > p.b;
	}
}r[100005], r2[100005]; ll mh[100005];
int bit[100005]; int n;
void add(int p, int x) {
	while (p <= n) {
		bit[p] += x;
		p += p & -p;
	}
}
ll sum(int p) {
	ll res = 0;
	while (p > 0) {
		res += bit[p];
		p -= p & -p;
	}
	return res;
}
int main() {
	int n;
	while (cin >> n) {
		for (int i = 0; i < n; i++) cin >> r[i].a >> r[i].b >> r[i].h;
		sort(r, r + n);
		stack<ring> st;
		ll res = 0, cur = 0;
		for (int i = 0; i < n; i++) {
			if (st.empty()) {
				st.push(r[i]);
				res = r[i].h;
			}
			else if (r[i].b <= st.top().b && r[i].b > st.top().a) {
				res += r[i].h;
				st.push(r[i]);
			}
			else {
				while (!st.empty() && !(r[i].b <= st.top().b && r[i].b > st.top().a)) {
					res -= st.top().h;
					st.pop();
				}
				st.push(r[i]);
				res += r[i].h;
			}
			cur = max(cur, res);
		}
		cout << cur << endl;
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long

struct Ring
{
public:
	int inner;
	int outer;
	LL height;
	bool operator < (Ring& lhs)
	{
		if (outer == lhs.outer)
			return inner < lhs.inner;
		return outer > lhs.outer;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<Ring> rings = vector<Ring>(n);
	REP(i, 0, n)
		cin >> rings[i].inner >> rings[i].outer >> rings[i].height;

	sort(rings.begin(), rings.end());

	stack<Ring> Hanoi;
	LL max_height = 0, height = 0;
	for (int i = 0; i < n; ++i)
	{
		while (1)
		{
			if (Hanoi.empty())
				break;
			if (Hanoi.top().outer >= rings[i].outer && Hanoi.top().inner < rings[i].outer)
				break;

			height -= Hanoi.top().height;
			Hanoi.pop();
		}

		Hanoi.push(rings[i]);
		height += rings[i].height;
		max_height = MAX(max_height, height);
	}

	cout << max_height << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long

struct Ring
{
public:
	int inner;
	int outer;
	LL height;
};

bool comp(Ring& lhs, Ring& rhs)
{
	return (lhs.inner < rhs.outer);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<pair<int, PII> > rings = vector<pair<int, PII> >(n);
	REP(i, 0, n)
		cin >> rings[i].second.first >> rings[i].first >> rings[i].second.second;

	//sort(rings.begin(), rings.end(), greater<pair<int, PII> >());

	LL max_height = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		LL height = rings[i].second.second;
		int inner = rings[i].second.first, outer = rings[i].first;
		for (int j = 0; j < n; ++j)
		{
			if(i == j)
				continue;
			int otherOutter = rings[j].first;
			if (otherOutter > inner && otherOutter <= outer)
				height += rings[j].second.second;
		}
			max_height = MAX(max_height, height);
	}

	cout << max_height << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long

struct Ring
{
public:
	int inner;
	int outer;
	LL height;
};

bool comp(Ring& lhs, Ring& rhs)
{
	return lhs.outer >= rhs.outer;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<Ring> rings = vector<Ring>(n);
	REP(i, 0, n)
		cin >> rings[i].inner >> rings[i].outer >> rings[i].height;

	sort(rings.begin(), rings.end(), comp);

	LL max_height = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		LL height = rings[i].height;
		for(int j = i + 1; j < n; ++j)
		{
			if (rings[i].inner < rings[j].outer)
				height += rings[j].height;
		}
		max_height = MAX(max_height, height);
	}

	cout << max_height << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long
class Ring
{
public:
	int inner, outer;
	LL height;
	bool operator < (const Ring& lhs)
	{
		if (outer == lhs.outer)
			return inner > lhs.inner;
		return outer > lhs.outer;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<Ring> rings = vector<Ring>(n);
	REP(i, 0, n)
		cin >> rings[i].inner >> rings[i].outer >> rings[i].height;

	sort(rings.begin(), rings.end());

	stack<Ring> Hanoi;

	LL max_height = 0, heights = 0;
	REP(i, 0, n)
	{
		while (!Hanoi.empty())
		{
			if (rings[i].outer > Hanoi.top().outer || rings[i].outer <= Hanoi.top().inner)
			{
				heights -= Hanoi.top().height;
				Hanoi.pop();
			}
			else
				break;
		}

		Hanoi.push(rings[i]);
		heights += rings[i].height;

		max_height = MAX(max_height, heights);
	}

	cout << max_height << endl;

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long

struct Ring
{
public:
	int inner;
	int outer;
	LL height;
};

bool comp(Ring& lhs, Ring& rhs)
{
	return (lhs.inner < rhs.outer);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<pair<int, PII> > rings = vector<pair<int, PII> >(n);
	REP(i, 0, n)
		cin >> rings[i].second.first >> rings[i].first >> rings[i].second.second;

	sort(rings.begin(), rings.end(), greater<pair<int, PII> >());

	LL max_height = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		LL height = rings[i].second.second, inner = rings[i].second.first;
		for (int j = i + 1; j < n; ++j)
		{
			int otherOutter = rings[i].first;
			if (otherOutter > inner)
				height += rings[j].second.second;
		}
			max_height = MAX(max_height, height);
	}

	cout << max_height << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long

struct Ring
{
public:
	int inner;
	int outer;
	LL height;
	bool operator < (Ring& lhs)
	{
		if (outer == lhs.outer)
			return inner > lhs.inner;
		return outer > lhs.outer;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<Ring> rings = vector<Ring>(n);
	REP(i, 0, n)
		cin >> rings[i].inner >> rings[i].outer >> rings[i].height;

	sort(rings.begin(), rings.end());

	stack<Ring> Hanoi;
	LL max_height = 0, height = 0;
	for (int i = 0; i < n; ++i)
	{
		while (1)
		{
			if (Hanoi.empty())
				break;
			if (Hanoi.top().outer >= rings[i].outer && Hanoi.top().inner < rings[i].outer)
				break;

			height -= Hanoi.top().height;
			Hanoi.pop();
		}

		Hanoi.push(rings[i]);
		height += rings[i].height;
		max_height = MAX(max_height, height);
	}

	cout << max_height << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

#define LL long long

struct Ring
{
public:
	int inner;
	int outer;
	LL height;
};

bool comp(Ring& lhs, Ring& rhs)
{
	return (lhs.inner < rhs.outer);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	vector<pair<int, PII> > rings = vector<pair<int, PII> >(n);
	REP(i, 0, n)
		cin >> rings[i].second.first >> rings[i].first >> rings[i].second.second;

	sort(rings.begin(), rings.end(), greater<pair<int, PII> >());

	LL max_height = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		LL height = rings[i].second.second, inner = rings[i].second.first;
		for (int j = i + 1; j < n; ++j)
		{
			int otherOutter = rings[j].first;
			if (otherOutter > inner)
				height += rings[j].second.second;
		}
			max_height = MAX(max_height, height);
	}

	cout << max_height << endl;
	return 0;
}


#include <cstdlib>
#include <iostream>
#include <string.h>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
struct bind
{
  long long a,b,h;
}
r[100005];
long long n;
stack<bind>p;
bool cmp(bind x,bind y)
{
 if(x.b==y.b&&x.a==y.a) return x.h>y.h;
 else if(x.b==y.b) return x.a>y.a;
 return x.b>y.b;
}
int main(int argc, char *argv[])
{
    cin>>n;
    for(long long i=0;i<n;i++)
    scanf("%lld %lld %lld",&r[i].a,&r[i].b,&r[i].h);
    sort(r,r+n,cmp);
    long long s=0,f=0;
    bind t;
    for(long long i=0;i<n;i++)
    {
      while(!p.empty())
        {
        t=p.top();
        if(t.a<r[i].b) break;
        s-=t.h;
        p.pop();
        }
      p.push(r[i]);
      s+=r[i].h;
      f=max(s,f);
    }
    cout<<f<<endl;

    return 0;
}


#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;

const int maxn=int(1e5)+10;
int n;
long long ans=0,cur=0;
stack<int> s;

struct Hanoi {
    int a,b,h;
    bool operator < (const Hanoi &x) const {return (b^x.b)?(b>x.b):(a>x.a);}
    void read() {scanf("%d%d%d",&a,&b,&h);}
}r[maxn];

int main() {

    scanf("%d",&n);
    for(int i=0;i<n;i++) r[i].read();
    sort(r,r+n);

    for(int i=0;i<n;i++) {
        while(s.size() && r[s.top()].a>=r[i].b) {
            cur-=r[s.top()].h;
            s.pop();
        }
        s.push(i);
        cur+=r[i].h;
        ans=max(ans,cur);
    }
    printf("%I64d\n",ans);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define lson rt << 1
#define rson rt << 1 | 1
typedef long long LL;
const int maxn = 1e5 + 10;

using namespace std;

struct Node{
    LL a, b, h;
    bool operator < ( Node t ) const {
        if( b != t.b ){
            return b < t.b;
        }
        else{
            return a < t.a;
        }
    }
}node[maxn];

struct SegTree{
    int l, r;
    LL maxx ;
    int mid(){
        return ( l + r ) >> 1;
    }
}tree[maxn<<2];

void build( int l, int r, int rt ){
    tree[rt].l = l;
    tree[rt].r = r;
    tree[rt].maxx = 0;
    if( l == r ) return ;
    int mid = ( l + r ) >> 1;
    build( l, mid, lson );
    build( mid + 1, r, rson );
}

void PushUp( int rt ){
    tree[rt].maxx = max( tree[lson].maxx, tree[rson].maxx );
}

void update( int pos, LL val, int rt ){
    if( tree[rt].l == pos && tree[rt].r == pos ){
        tree[rt].maxx = max( tree[rt].maxx, val );
        return ;
    }
    int mid = tree[rt].mid();
    if( pos <= mid ){
        update( pos, val , lson );
    }
    else{
        update( pos, val, rson );
    }
    PushUp( rt );
}

LL query( int l, int r, int rt ){
    if( tree[rt].l == l && tree[rt].r == r ){
        return tree[rt].maxx;
    }
    int mid = tree[rt].mid();
    if( r <= mid ){
        return query( l, r, lson );
    }
    else if( l > mid ){
        return query( l, r, rson );
    }
    else {
        LL a = query( l, mid, lson );
        LL b = query( mid + 1, r, rson );
        return max( a, b );
    }
}

vector<LL> v;

int main(){
    //freopen("in.txt","r",stdin);
    int n;
    while( scanf("%d", &n ) != EOF ){
        v.clear();
        for( int i = 1; i <= n; i++ ){
            scanf("%I64d %I64d %I64d", &node[i].a, &node[i].b, &node[i].h );
            v.push_back( node[i].b );
        }
        sort( node + 1, node + n + 1 );
        sort( v.begin(), v.end() );
        v.erase( unique( v.begin(), v.end()), v.end() );
        build( 1, v.size(), 1 );
        LL ret = 0;
        for( int i = 1; i <= n; i++ ){
            int pre = lower_bound( v.begin(), v.end(), node[i].a ) - v.begin() + 1;
            int last = lower_bound( v.begin(), v.end(), node[i].b ) - v.begin() + 1;
            LL ans = query( pre, last, 1 ) + node[i].h ;
            if( ans > ret ){
                ret = ans;
            }
            update( last, ans, 1 );
        }
        printf("%I64d\n", ret );
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define lson rt << 1
#define rson rt << 1 | 1
typedef long long LL;
const int maxn = 1e5 + 10;

using namespace std;

struct Node{
    LL a, b, h;
    bool operator < ( Node t ) const {
        if( b != t.b ){
            return b < t.b;
        }
        else{
            return a < t.a;
        }
    }
}node[maxn];

struct SegTree{
    int l, r;
    LL maxx ;
    int mid(){
        return ( l + r ) >> 1;
    }
}tree[maxn<<2];

void build( int l, int r, int rt ){
    tree[rt].l = l;
    tree[rt].r = r;
    tree[rt].maxx = 0;
    if( l == r ) return ;
    int mid = ( l + r ) >> 1;
    build( l, mid, lson );
    build( mid + 1, r, rson );
}

void PushUp( int rt ){
    tree[rt].maxx = max( tree[lson].maxx, tree[rson].maxx );
}

void update( int pos, LL val, int rt ){
    if( tree[rt].l == pos && tree[rt].r == pos ){
        tree[rt].maxx = max( tree[rt].maxx, val );
        return ;
    }
    int mid = tree[rt].mid();
    if( pos <= mid ){
        update( pos, val, lson );
    }
    else{
        update( pos, val, rson );
    }
    PushUp( rt );
}

LL query( int l, int r, int rt ){
    if( tree[rt].l == l && tree[rt].r == r ){
        return tree[rt].maxx;
    }
    int mid = tree[rt].mid();
    if( r <= mid ){
        return query( l, r, lson );
    }
    else if( l > mid ){
        return query( l, r, rson );
    }
    else {
        LL a = query( l, mid, lson );
        LL b = query( mid + 1, r, rson );
        return max( a, b );
    }
}

vector<LL> v;

int main(){
    //freopen("in.txt","r",stdin);
    int n;
    while( scanf("%d", &n ) != EOF ){
        v.clear();
        for( int i = 1; i <= n; i++ ){
            scanf("%I64d %I64d %I64d", &node[i].a, &node[i].b, &node[i].h );
            v.push_back( node[i].b );
        }
        sort( node + 1, node + n + 1 );
        sort( v.begin(), v.end() );
        v.erase( unique( v.begin(), v.end()), v.end() );
        build( 1, v.size(), 1 );
        LL ret = 0LL;
        for( int i = 1; i <= n; i++ ){
            int pre = lower_bound( v.begin(), v.end(), node[i].a + 1 ) - v.begin() + 1;
            int last = lower_bound( v.begin(), v.end(), node[i].b ) - v.begin() + 1;
            LL ans = query( pre, last, 1 ) + node[i].h ;
            if( ans > ret ){
                ret = ans;
            }
            update( last, ans, 1 );
        }
        printf("%I64d\n", ret );
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define lson rt << 1
#define rson rt << 1 | 1
typedef long long LL;
const int maxn = 1e5 + 10;

using namespace std;

struct Node{
    LL a, b, h;
    bool operator < ( Node t ) const {
        if( b != t.b ){
            return b < t.b;
        }
        else{
            return a < t.a;
        }
    }
}node[maxn];

struct SegTree{
    int l, r;
    LL maxx ;
    int mid(){
        return ( l + r ) >> 1;
    }
}tree[maxn<<2];

void build( int l, int r, int rt ){
    tree[rt].l = l;
    tree[rt].r = r;
    tree[rt].maxx = 0;
    if( l == r ) return ;
    int mid = ( l + r ) >> 1;
    build( l, mid, lson );
    build( mid + 1, r, rson );
}

void PushUp( int rt ){
    tree[rt].maxx = max( tree[lson].maxx, tree[rson].maxx );
}

void update( int pos, LL val, int rt ){
    if( tree[rt].l == pos && tree[rt].r == pos ){
        tree[rt].maxx = max( tree[rt].maxx, val );
        return ;
    }
    int mid = tree[rt].mid();
    if( pos <= mid ){
        update( pos, val , lson );
    }
    else{
        update( pos, val, rson );
    }
    PushUp( rt );
}

LL query( int l, int r, int rt ){
    if( tree[rt].l == l && tree[rt].r == r ){
        return tree[rt].maxx;
    }
    int mid = tree[rt].mid();
    if( r <= mid ){
        return query( l, r, lson );
    }
    else if( l > mid ){
        return query( l, r, rson );
    }
    else {
        int a = query( l, mid, lson );
        int b = query( mid + 1, r, rson );
        return max( a, b );
    }
}

vector<LL> v;

int main(){
    //freopen("in.txt","r",stdin);
    int n;
    while( scanf("%d", &n ) != EOF ){
        v.clear();
        for( int i = 1; i <= n; i++ ){
            scanf("%I64d %I64d %I64d", &node[i].a, &node[i].b, &node[i].h );
            v.push_back( node[i].b );
        }
        sort( node + 1, node + n + 1 );
        sort( v.begin(), v.end() );
        v.erase( unique( v.begin(), v.end()), v.end() );
        build( 1, v.size(), 1 );
        LL ret = 0;
        for( int i = 1; i <= n; i++ ){
            int pre = lower_bound( v.begin(), v.end(), node[i].a ) - v.begin() + 1;
            int last = lower_bound( v.begin(), v.end(), node[i].b ) - v.begin() + 1;
            LL ans = query( pre, last, 1 ) + node[i].h ;
            if( ans > ret ){
                ret = ans;
            }
            update( last, ans, 1 );
        }
        printf("%I64d\n", ret );
    }
    return 0;
}


#include<stdio.h>
#include<map>
using namespace std;
int n;
long long int res;
map<int,int> Map1;
map<int,long long int> Map2;

int top;
int in[111111];
long long int toth[111111],oo;

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		int x,y,z;
		scanf("%d%d%d",&y,&x,&z);
		if(!Map1.count(x))
			Map1[x] = y;
		else
			Map1[x] = min(Map1[x],y);
		Map2[x] += z;
	}
	top=0;
	map<int,int>::reverse_iterator it1 = Map1.rbegin();
	map<int,long long int>::reverse_iterator it2 = Map2.rbegin();
	long long int oo = 0;
	for(; it1!=Map1.rend(); it1++,it2++){
		int outer = it1 -> first, inner = it1 -> second;
		long long int H = it2 -> second;
		while(top!=0 && in[top-1] >= outer)top--;
		if(top!=0)H += toth[top-1];
		while(top!=0 && in[top-1] >= inner)top--;
		in[top] = inner;
		toth[top++] = H;
		oo = max(oo, H);
	}
	printf("%I64d\n",oo);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#define MaxN 200005
#define MaxT 600000
using namespace std;

int N,Start,End,Pos,List[MaxN],Size;
long long Max,Val,T[MaxT];
struct Hanoi
{
	int out,in;
	long long h;
}v[MaxN];
bool cond(Hanoi a,Hanoi b)
{
	return a.out<b.out||(a.out==b.out&a.in<b.in);
}
void Update(int node,int start,int end)
{
	if(start==end)
		T[node]=max(T[node],Val);
	else
	{
		int mid=(start+end)>>1;
		if(Pos>mid)Update(2*node+1,mid+1,end);
		else Update(2*node,start,mid);
		T[node]=max(T[2*node],T[2*node+1]);
	}
}
void Query(int node,int start,int end)
{
    if(Start<=start&&end<=End)
        Val=max(Val,T[node]);
    else
    {
        int mid=(start+end)>>1;
        if(Start<=mid)Query(node*2,start,mid);
        if(End>mid) Query(node*2+1,mid+1,end);
    }
}
int Search(int val)
{
	int lw=1,hi=Size,mid;
	while(lw<=hi)
	{
		mid=(lw+hi)>>1;
		if(List[mid]>val)
			hi=mid-1;
		else if(List[mid]<val)
			lw=mid+1;
		else return mid;
	}
}
void Normalize()
{
	Size=0;
	for(int i=1;i<=2*N;i++)
		if(List[i]!=List[i-1])
			List[++Size]=List[i];
	for(int i=1;i<=N;i++)
		v[i].in=Search(v[i].in),v[i].out=Search(v[i].out);
}
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d%d",&v[i].in,&v[i].out,&v[i].h),List[2*i-1]=v[i].in,List[2*i]=v[i].out;
	sort(List+1,List+2*N+1);
	Normalize();
	sort(v+1,v+N+1,cond);
	for(int i=1;i<=N;i++)
	{
		Val=0;
		Start=v[i].in+1;
		End=v[i].out;
		Query(1,1,2*N);
		v[i].h+=Val;
		Val=v[i].h;
		Max=max(Max,Val);
		Pos=v[i].out;
		Update(1,1,2*N);
	}
	printf("%I64d",Max);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#define MaxN 200005
#define MaxT 600000
using namespace std;

int N,Start,End,Pos,List[MaxN],Size;
long long Max,Val,T[MaxT];
struct Hanoi
{
	int out,in;
	long long h;
}v[MaxN];
bool cond(Hanoi a,Hanoi b)
{
	return a.out<b.out;
}
void Update(int node,int start,int end)
{
	if(start==end)
		T[node]=max(T[node],Val);
	else
	{
		int mid=(start+end)>>1;
		if(Pos>mid)Update(2*node+1,mid+1,end);
		else Update(2*node,start,mid);
		T[node]=max(T[2*node],T[2*node+1]);
	}
}
void Query(int node,int start,int end)
{
    if(Start<=start&&end<=End)
        Val=max(Val,T[node]);
    else
    {
        int mid=(start+end)>>1;
        if(Start<=mid)Query(node*2,start,mid);
        if(End>mid) Query(node*2+1,mid+1,end);
    }
}
int Search(int val)
{
	int lw=1,hi=Size,mid;
	while(lw<=hi)
	{
		mid=(lw+hi)>>1;
		if(List[mid]>val)
			hi=mid-1;
		else if(List[mid]<val)
			lw=mid+1;
		else return mid;
	}
}
void Normalize()
{
	Size=0;
	for(int i=1;i<=2*N;i++)
		if(List[i]!=List[i-1])
			List[++Size]=List[i];
	for(int i=1;i<=N;i++)
		v[i].in=Search(v[i].in),v[i].out=Search(v[i].out);
}
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d%d",&v[i].in,&v[i].out,&v[i].h),List[2*i-1]=v[i].in,List[2*i]=v[i].out;
	sort(List+1,List+2*N+1);
	Normalize();
	sort(v+1,v+N+1,cond);
	for(int i=1;i<=N;i++)
	{
		Val=0;
		Start=v[i].in+1;
		End=v[i].out-1;
		Query(1,1,2*N);
		v[i].h+=Val;
		Val=v[i].h;
		Max=max(Max,Val);
		Pos=v[i].out;
		Update(1,1,2*N);
	}
	printf("%I64d",Max);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#define MaxN 200005
#define MaxT 600000
using namespace std;

int N,Start,End,Pos,List[MaxN],Size;
long long Max,Val,T[MaxT];
struct Hanoi
{
	int out,in;
	long long h;
}v[MaxN];
bool cond(Hanoi a,Hanoi b)
{
	return a.out<b.out;
}
void Update(int node,int start,int end)
{
	if(start==end)
		T[node]=max(T[node],Val);
	else
	{
		int mid=(start+end)>>1;
		if(Pos>mid)Update(2*node+1,mid+1,end);
		else Update(2*node,start,mid);
		T[node]=max(T[2*node],T[2*node+1]);
	}
}
void Query(int node,int start,int end)
{
    if(Start<=start&&end<=End)
        Val=max(Val,T[node]);
    else
    {
        int mid=(start+end)>>1;
        if(Start<=mid)Query(node*2,start,mid);
        if(End>mid) Query(node*2+1,mid+1,end);
    }
}
int Search(int val)
{
	int lw=1,hi=Size,mid;
	while(lw<=hi)
	{
		mid=(lw+hi)>>1;
		if(List[mid]>val)
			hi=mid-1;
		else if(List[mid]<val)
			lw=mid+1;
		else return mid;
	}
}
void Normalize()
{
	Size=0;
	for(int i=1;i<=2*N;i++)
		if(List[i]!=List[i-1])
			List[++Size]=List[i];
	for(int i=1;i<=N;i++)
		v[i].in=Search(v[i].in),v[i].out=Search(v[i].out);
}
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d%d",&v[i].in,&v[i].out,&v[i].h),List[2*i-1]=v[i].in,List[2*i]=v[i].out;
	sort(List+1,List+2*N+1);
	Normalize();
	sort(v+1,v+N+1,cond);
	for(int i=1;i<=N;i++)
	{
		Val=0;
		Start=v[i].in+1;
		End=v[i].out;
		Query(1,1,2*N);
		v[i].h+=Val;
		Val=v[i].h;
		Max=max(Max,Val);
		Pos=v[i].out;
		Update(1,1,2*N);
	}
	printf("%d",Max);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#define MaxN 200005
#define MaxT 600000
using namespace std;

int N,Start,End,Pos,List[MaxN],Size;
long long Max,Val,T[MaxT];
struct Hanoi
{
	int out,in;
	long long h;
}v[MaxN];
bool cond(Hanoi a,Hanoi b)
{
	return a.out<b.out;
}
void Update(int node,int start,int end)
{
	if(start==end)
		T[node]=max(T[node],Val);
	else
	{
		int mid=(start+end)>>1;
		if(Pos>mid)Update(2*node+1,mid+1,end);
		else Update(2*node,start,mid);
		T[node]=max(T[2*node],T[2*node+1]);
	}
}
void Query(int node,int start,int end)
{
    if(Start<=start&&end<=End)
        Val=max(Val,T[node]);
    else
    {
        int mid=(start+end)>>1;
        if(Start<=mid)Query(node*2,start,mid);
        if(End>mid) Query(node*2+1,mid+1,end);
    }
}
int Search(int val)
{
	int lw=1,hi=Size,mid;
	while(lw<=hi)
	{
		mid=(lw+hi)>>1;
		if(List[mid]>val)
			hi=mid-1;
		else if(List[mid]<val)
			lw=mid+1;
		else return mid;
	}
}
void Normalize()
{
	Size=0;
	for(int i=1;i<=2*N;i++)
		if(List[i]!=List[i-1])
			List[++Size]=List[i];
	for(int i=1;i<=N;i++)
		v[i].in=Search(v[i].in),v[i].out=Search(v[i].out);
}
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d%d",&v[i].in,&v[i].out,&v[i].h),List[2*i-1]=v[i].in,List[2*i]=v[i].out;
	sort(List+1,List+2*N+1);
	Normalize();
	sort(v+1,v+N+1,cond);
	for(int i=1;i<=N;i++)
	{
		Val=0;
		Start=v[i].in+1;
		End=v[i].out;
		Query(1,1,2*N);
		v[i].h+=Val;
		Val=v[i].h;
		Max=max(Max,Val);
		Pos=v[i].out;
		Update(1,1,2*N);
	}
	printf("%I64d",Max);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#define MaxN 200005
#define MaxT 600000
using namespace std;

int N,Start,End,Pos,List[MaxN],Size;
long long Max,Val,T[MaxT];
struct Hanoi
{
	int out,in;
	long long h;
}v[MaxN];
bool cond(Hanoi a,Hanoi b)
{
	return a.out<b.out;
}
void Update(int node,int start,int end)
{
	if(start==end)
	{
		T[node]=max(T[node],Val);
	}
	else
	{
		int mid=(start+end)>>1;
		if(Pos>mid)Update(2*node+1,mid+1,end);
		else Update(2*node,start,mid);
		T[node]=max(T[2*node],T[2*node+1]);
	}
}
void Query(int node,int start,int end)
{
    if(start>=Start&&end<=End)
        Val=max(Val,T[node]);
    else
    {
        int mid=(start+end)>>1;
        if(Start<=mid)Query(node*2,start,mid);
        if(End>mid) Query(node*2+1,mid+1,end);
    }
}
int Search(int val)
{
	int lw=1,hi=Size,mid;
	while(lw<=hi)
	{
		mid=(lw+hi)>>1;
		if(List[mid]>val)
			hi=mid-1;
		else if(List[mid]<val)
			lw=mid+1;
		else return mid;
	}
}
void Normalize()
{
	Size=0;
	for(int i=1;i<=2*N;i++)
		if(List[i]!=List[i-1])
			List[++Size]=List[i];
	for(int i=1;i<=N;i++)
		v[i].in=Search(v[i].in),v[i].out=Search(v[i].out);
}
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d%d",&v[i].in,&v[i].out,&v[i].h),List[2*i-1]=v[i].in,List[2*i]=v[i].out;
	sort(List+1,List+2*N+1);
	Normalize();
	sort(v+1,v+N+1,cond);
	for(int i=1;i<=N;i++)
	{
		Val=0;
		Start=v[i].in+1;
		End=v[i].out;
		Query(1,1,2*N);
		v[i].h+=Val;
		Val=v[i].h;
		Max=max(Max,Val);
		Pos=v[i].out;
		Update(1,1,2*N);
	}
	printf("%d",Max);
	return 0;
}


#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <functional>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <climits>
#include <sstream>

using namespace std;
#define ll long long
#define x first
#define y second
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define L(s) (int)(s).size()
#define VI vector<int>
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define inf 1000000000
#define pi 3.14159265358979323426264

#define sqr(x) ((x) * (x))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define FORI(it, cont) for (auto (it) = (cont).begin(); (it) != (cont).end(); (it)++)
#define eps std::numeric_limits<double>::epsilon()

struct ring
{
   int a;
   int b;
   long long h;
};

bool compareByH(const ring& one, const ring& two)
{
   if (one.b == two.b)
   {
      return one.a > two.a;
   }
   return one.b > two.b;
}

bool greaterPair(const pil& one, const pil& two)
{
   return one.x > two.x;
}

int main()
{
   int n;
   cin >> n;
   vector<ring> rings(n);
   REP(i, n)
   {
      cin >> rings[i].a >> rings[i].b >> rings[i].h;
   }
   sort(all(rings), compareByH);
   map<int, long long> heights;
   heights[0] = 0;
   REP(i, n)
   {
      ring& curRing = rings[i];
      auto it = heights.lower_bound(curRing.b);
      it--;
      if (it->first >= 0)
      {
         ll newHeight = it->second + curRing.h;
         auto aIt = heights.lower_bound(curRing.a);
         while (aIt != heights.end())
         {
            auto next = aIt;
            next++;
            if (aIt->second < newHeight)
            {
               heights.erase(aIt);
            }
            else
            {
               break;
            }
            aIt = next;
         }
         auto f = heights.find(curRing.a);
         if (f == heights.end() || f->second < newHeight)
         {
            heights[curRing.a] = newHeight;
         }
      }
   }

   long long maxH = 0;
   FORI(it, heights)
   {
      if (it->second > maxH)
      {
         maxH = it->second;
      }
   }
   cout << maxH << endl;
   return 0;
}


#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <functional>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <climits>
#include <sstream>

using namespace std;
#define ll long long
#define x first
#define y second
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define L(s) (int)(s).size()
#define VI vector<int>
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define inf 1000000000
#define pi 3.14159265358979323426264

#define sqr(x) ((x) * (x))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define FORI(it, cont) for (auto (it) = (cont).begin(); (it) != (cont).end(); (it)++)
#define eps std::numeric_limits<double>::epsilon()

struct ring
{
   int a;
   int b;
   long long h;
};

bool compareByH(const ring& one, const ring& two)
{
   return one.b > two.b;
}

bool greaterPair(const pil& one, const pil& two)
{
   return one.x > two.x;
}

bool lessPair(const pil& one, const pil& two)
{
   return one.x < two.x;
}

int main()
{
   int n;
   cin >> n;
   vector<ring> rings(n);
   REP(i, n)
   {
      cin >> rings[i].a >> rings[i].b >> rings[i].h;
   }
   sort(all(rings), compareByH);
   map<int, long long> heights;
   heights[0] = 0;
   REP(i, n)
   {
      ring& curRing = rings[i];
      auto it = heights.end();
      it--;
      while (it->first >= curRing.b)
      {
         it--;
      }
      if (it->first >= 0)
      {
         ll newHeight = it->second + curRing.h;
         auto aIt = lower_bound(all(heights), mp(curRing.a,0), lessPair);
         while (aIt != heights.end())
         {
            auto next = aIt;
            next++;
            if (aIt->second < newHeight)
            {
               heights.erase(aIt);
            }
            else
            {
               break;
            }
            aIt = next;
         }
         auto f = heights.find(curRing.a);
         if (f == heights.end() || f->second < newHeight)
         {
            heights[curRing.a] = newHeight;
         }
      }
   }

   long long maxH = 0;
   FORI(it, heights)
   {
      if (it->second > maxH)
      {
         maxH = it->second;
      }
   }
   cout << maxH << endl;
   return 0;
}


#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <functional>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <climits>
#include <sstream>

using namespace std;
#define ll long long
#define x first
#define y second
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define L(s) (int)(s).size()
#define VI vector<int>
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define inf 1000000000
#define pi 3.14159265358979323426264

#define sqr(x) ((x) * (x))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define FORI(it, cont) for (auto (it) = (cont).begin(); (it) != (cont).end(); (it)++)
#define eps std::numeric_limits<double>::epsilon()

struct ring
{
   int a;
   int b;
   long long h;
};

bool compareByH(const ring& one, const ring& two)
{
   return one.b > two.b;
}

bool greaterPair(const pil& one, const pil& two)
{
   return one.x > two.x;
}

bool lessPair(const pil& one, const pil& two)
{
   return one.x < two.x;
}

int main()
{
   int n;
   cin >> n;
   vector<ring> rings(n);
   REP(i, n)
   {
      cin >> rings[i].a >> rings[i].b >> rings[i].h;
   }
   sort(all(rings), compareByH);
   map<int, long long> heights;
   heights[0] = 0;
   REP(i, n)
   {
      ring& curRing = rings[i];
      auto it = heights.end();
      it--;
      while (it->first >= curRing.b)
      {
         it--;
      }
      if (it->first >= 0)
      {
         ll newHeight = it->second + curRing.h;
         auto aIt = lower_bound(all(heights), mp(curRing.a,0), lessPair);
         while (aIt != heights.end())
         {
            auto next = aIt;
            next++;
            if (aIt->second < newHeight)
            {
               heights.erase(aIt);
            }
            else
            {
               break;
            }
            aIt = next;
         }
         auto f = heights.find(curRing.a);
         it = heights.end();
         it--;
         if (newHeight > it->second &&( f == heights.end() || f->second < newHeight))
         {
            heights[curRing.a] = newHeight;
         }
      }
   }

   long long maxH = 0;
   FORI(it, heights)
   {
      if (it->second > maxH)
      {
         maxH = it->second;
      }
   }
   cout << maxH << endl;
   return 0;
}


#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <functional>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <climits>
#include <sstream>

using namespace std;
#define ll long long
#define x first
#define y second
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define L(s) (int)(s).size()
#define VI vector<int>
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define inf 1000000000
#define pi 3.14159265358979323426264

#define sqr(x) ((x) * (x))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define FORI(it, cont) for (auto (it) = (cont).begin(); (it) != (cont).end(); (it)++)
#define eps std::numeric_limits<double>::epsilon()

struct ring
{
   int a;
   int b;
   long long h;
};

bool compareByH(const ring& one, const ring& two)
{
   return one.b > two.b;
}

bool greaterPair(const pil& one, const pil& two)
{
   return one.x > two.x;
}

bool lessPair(const pil& one, const pil& two)
{
   return one.x < two.x;
}

int main()
{
   int n;
   cin >> n;
   vector<ring> rings(n);
   REP(i, n)
   {
      cin >> rings[i].a >> rings[i].b >> rings[i].h;
   }
   sort(all(rings), compareByH);
   map<int, long long> heights;
   heights[0] = 0;
   REP(i, n)
   {
      ring& curRing = rings[i];
      auto it = heights.end();
      it--;
      while (it->first > curRing.b)
      {
         it--;
      }
      if (it->first >= 0)
      {
         ll newHeight = it->second + curRing.h;
         auto aIt = lower_bound(all(heights), mp(curRing.a,0), lessPair);
         while (aIt != heights.end() && aIt->first >= it->first)
         {
            if (aIt->second < newHeight)
            {
               aIt->second = newHeight;
            }
            aIt++;
         }
         heights[curRing.a] = newHeight;
      }
   }

   long long maxH = 0;
   FORI(it, heights)
   {
      if (it->second > maxH)
      {
         maxH = it->second;
      }
   }
   cout << maxH << endl;
   return 0;
}