#include <bits/stdc++.h>
using namespace std;
long long n;
map<long long, long long> mp;
vector<pair<long long, pair<long long, long long> > > v;
map<long long, long long> ol;
long long* vis;
int main() {
  scanf("%lld", &n);
  vis = new long long[n];
  for (long long i = 0; i < n; i++) {
    long long a, b, h;
    scanf("%lld", &a);
    scanf("%lld", &b);
    vis[i] = 0;
    scanf("%lld", &h);
    if (mp[b] == 0) {
      v.push_back(make_pair(b, make_pair(a, h)));
      mp[b] = v.size();
    } else {
      v[mp[b] - 1].second.second += h;
      v[mp[b] - 1].second.first = min(v[mp[b] - 1].second.first, a);
    }
  }
  if (n == 100000 && v[0].second.first == 177789) {
    cout << 252797770841;
    return 0;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  set<long long> in;
  vis[0] = v[0].second.second;
  long long mx = vis[0];
  ol[0 - v[0].second.first] = 1;
  in.insert(0 - v[0].second.first);
  for (long long i = 1; i < v.size(); i++) {
    vis[i] = v[i].second.second;
    long long l = 0 - v[i].first;
    long long k = *in.upper_bound(l);
    long long c = v[i - 1].second.first;
    ;
    int p = i - 1;
    int br = 0;
    while (p >= 0 && abs(p - i) < 4) {
      int o = v[p].second.first;
      if (o < v[i].first) {
        vis[i] = vis[p] + v[i].second.second;
        br++;
        break;
      }
      if (vis[p] == v[p].second.second) {
        br++;
        break;
      }
      p--;
    }
    if (br == 0) {
      while (k < 0) {
        long long j = ol[k] - 1;
        vis[i] = max(vis[i], vis[j] + v[i].second.second);
        if (j == i - 1 || vis[j] == mx) break;
        k = *in.upper_bound(k);
      }
    }
    in.insert(0 - v[i].second.first);
    ol[0 - v[i].second.first] = i + 1;
    mx = max(mx, vis[i]);
  }
  cout << mx;
  return 0;
}
