#include <bits/stdc++.h>
long long aib[100009 + 1];
int a[100009 + 1], b[100009 + 1], c[100009 + 1];
int ind[100009 + 1], v[100009 + 1];
inline int caut(int a, int n) {
  int rez = 0;
  for (int pas = 1 << 16; pas; pas >>= 1)
    if ((rez + pas <= n) && (v[rez + pas] < a)) rez += pas;
  return rez;
}
bool cmp(const int &p, const int &q) {
  if (b[p] != b[q])
    return b[p] > b[q];
  else
    return a[p] > a[q];
}
inline long long query(int p) {
  long long ans = 0;
  while (p > 0) {
    ans = std::max(ans, aib[p]);
    p -= p & (-p);
  }
  return ans;
}
inline void update(int p, long long val, int n) {
  while (p <= n) {
    aib[p] = std::max(aib[p], val);
    p += p & (-p);
  }
}
int main() {
  int n;
  fscanf(stdin, "%d", &n);
  for (int i = 1; i <= n; i++) {
    fscanf(stdin, "%d%d%d", &a[i], &b[i], &c[i]);
    v[i] = a[i];
    ind[i] = i;
  }
  std::sort(v + 1, v + n + 1);
  std::sort(ind + 1, ind + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long u = c[ind[i]] + query(caut(b[ind[i]], n));
    ans = std::max(ans, u);
    update(caut(a[ind[i]], n) + 1, u, n);
  }
  fprintf(stdout, "%I64d\n", ans);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
