#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> height;
map<int, int> mini;
long long best[500001];
long long maxi;
vector<pair<int, pair<int, int> > > vec;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b, h;
    scanf("%d %d %d", &a, &b, &h);
    int currMin = mini[b];
    height[b] += h;
    if (a <= currMin) mini[b] = a;
    if (currMin == 0) mini[b] = a;
  }
  map<int, int>::iterator itH = height.begin(), itM = mini.begin();
  while (itH != height.end()) {
    vec.push_back(make_pair(itM->first, make_pair(itM->second, itH->second)));
    itH++, itM++;
  }
  stack<int> stk;
  for (int i = vec.size() - 1; i >= 0; i--) {
    while (!stk.empty() && vec[stk.top()].second.first >= vec[i].first)
      stk.pop();
    if (!stk.empty()) best[i] = best[stk.top()];
    best[i] += vec[i].second.second;
    stk.push(i);
    maxi = max(maxi, best[i]);
  }
  printf("%I64d", maxi);
  return 0;
}
