#include <bits/stdc++.h>
using namespace std;
long long seg[400005];
long long a[100005];
long long b[100005];
long long c[100005];
vector<pair<pair<int, int>, int> > v;
long long getMax(int x, int l, int r, int ql, int qr) {
  if (l > r) return 0;
  if (r < ql || l > qr) {
    return 0;
  }
  if (l >= ql && r <= qr) {
    return seg[x];
  }
  int mid = (l + r) / 2;
  long long lval = getMax(2 * x + 1, l, mid, ql, qr);
  long long rval = getMax(2 * x + 2, mid + 1, r, ql, qr);
  return max(lval, rval);
}
void update(int x, int l, int r, int ind, long long val) {
  if (l > r) return;
  if (ind > r || ind < l) return;
  if (l == r) {
    if (l == ind) {
      seg[x] = max(seg[x], val);
    }
    return;
  }
  int mid = (l + r) / 2;
  if (ind <= mid) {
    update(2 * x + 1, l, mid, ind, val);
  } else {
    update(2 * x + 2, mid + 1, r, ind, val);
  }
  seg[x] = max(seg[x], val);
}
int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  long long x, y, z;
  for (int i = (0); i < (n); ++i) {
    scanf("%lld", &x), scanf("%lld", &y), scanf("%lld", &z);
    v.push_back(make_pair(pair<int, int>(y, x), z));
  }
  sort(v.begin(), v.end());
  for (int i = (0); i < (n); ++i) {
    a[i] = (long long)v[i].first.second;
    b[i] = (long long)v[i].first.first;
    c[i] = (long long)v[i].second;
    ans = max(ans, c[i]);
  }
  sort(v.begin(), v.end());
  for (int i = (0); i < (n); ++i) {
    int l = 0;
    int h = i;
    int val = a[i] + 1;
    while (l < h) {
      int md = (l + h) / 2;
      if (b[md] < val) {
        l = md + 1;
      } else {
        h = md;
      }
    }
    long long mx = getMax(0, 0, n - 1, l, i - 1);
    update(0, 0, n - 1, i, mx + c[i]);
    ans = max(ans, mx + c[i]);
  }
  cout << ans << endl;
}
