// Author:zzqwtcc
// Problem: 区间
// Contest: AcWing
// Time:2021-10-28 22:50:45
// URL: https://www.acwing.com/problem/content/364/
// Memory Limit: 64 MB
// Time Limit: 1000 ms
#include<bits/stdc++.h>
#include<unordered_map>
// #define int long long
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define mod 1000000007
#define MOD 998244353
#define rep(i, st, ed) for (int (i) = (st); (i) <= (ed);++(i))
#define pre(i, ed, st) for (int (i) = (ed); (i) >= (st);--(i))
// #define debug(x,y) cerr << (x) << " == " << (y) << endl;
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> inline T lowbit(T x) { return x & -x; }
template<typename S,typename T>void debug(S s, T t){cerr << s << " == " << t << endl;}
template<typename T>void debug(T t){cerr << t << endl;}
template<typename T>void debug(T t[],int st,int ed){for(int i = st; i <=ed;++i){cerr << t[i] << " ";}cerr << endl;}
template<typename T>void debug(const vector<T>&t){for(int i =0 ; i < t.size();++i)cerr << t[i] << " ";cerr << endl;}
// template<typename T> T qmi(T a, T b = mod - 2, T p = mod) { T res = 1; b %= (p - 1 == 0 ? p : p - 1); while (b) { if (b & 1) { res = (LL)res * a % p; }b >>= 1; a = (LL)a * a % p; }return res % mod; }
const int N = 5e4 + 10, M = 4 * N;
int h[N],e[M],ne[M],w[M],idx;
int d[N], cnt[N];
bool st[N];
int n;
void add(int a,int b, int c){
e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
}
bool spfa(){
memset(d,-0x3f,sizeof d);
stack<int>q;
d[0] = 0;
q.push(0);
while(q.size()){
int u = q.top();
q.pop();
st[u] = false;
for(int i =h[u];~i;i = ne[i]){
int j = e[i];
int dis = w[i];
if(d[j] < d[u] + dis){
d[j] = d[u] + dis;
cnt[j] = cnt[u] + 1;
if(cnt[j] >= 50001)return false;
if(!st[j]){
st[j] = true;
q.push(j);
}
}
}
}
return true;
}
void solve() {
cin >> n;
memset(h,-1,sizeof h);
while(n--){
int a,b,c;scanf("%d%d%d",&a,&b,&c);
add(a,b + 1,c);
}
for(int i = 1;i <= 50001;++i){
add(0,i,0);
}
for(int i = 1; i <= 50001;++i){
add(i - 1,i,0);
}
for(int i = 1; i <= 50001;++i){
add(i,i - 1,-1);
}
spfa();
cout << d[50001] << endl;
}
signed main() {
//int _; cin >> _;
//while (_--)
solve();
return 0;
}