#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN = 50005;
const int INF = 0x3f3f3f3f;
struct Edge //边
{
int node, len;
Edge* next;
}edge[MAXN * 10];
Edge* head[MAXN];
int totalE; //总边数
int vis[MAXN], dist[MAXN];
//增加边
void addEdge(int a, int b, int c)
{
edge[totalE].node = b;
edge[totalE].len = c;
edge[totalE].next = head[a];
head[a] = edge + totalE++;
}
//SPFA算法
void SPFA(int n)
{
queue<int> q;
vis[n] = 1;
dist[n] = 0;
q.push(n);
while (!q.empty())
{
int now = q.front();
q.pop();
vis[now] = 0;
for (Edge* p = head[now]; p != NULL; p = p->next)
{
int next = p->node;
if (dist[next] < dist[now] + p->len)
{
dist[next] = dist[now] + p->len;
if (!vis[next])
{
vis[next] = 1;
q.push(next);
}
}
}
}
}
int main()
{
int n;
while (cin >> n)
{
totalE = 0;
fill(head, head + MAXN, (Edge*)NULL);
fill(dist, dist + MAXN, -INF);
memset(vis, 0, sizeof(vis));
int a, b, c;
int maxR = 0; //最右结点
for (int i = 0; i < n; i++)
{
cin >> a >> b >> c;
maxR = max(maxR, b);
addEdge(a - 1, b, c);
}
for (int i = 1; i <= maxR; i++)
{
addEdge(i - 1, i, 0);
addEdge(i, i - 1, -1);
}
SPFA(0);
cout << dist[maxR] << endl;
}
return 0;
}