#include <bits/stdc++.h>
using namespace std;
int a, b, h, n, i;
long long x, ans;
pair<pair<int, int>, int> p[100005];
map<long long, long long> f;
void update(int index, long long value) {
  while (index < 1e9) {
    f[index] = max(f[index], value);
    index += (-index & index);
  }
}
long long read(int index) {
  long long ans = 0;
  while (index > 0) {
    ans = max(ans, f[index]);
    index -= (-index & index);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d%d%d", &p[i].first.second, &p[i].first.first, &p[i].second);
  sort(p, p + n);
  reverse(p, p + n);
  for (i = 0; i < n; i++) {
    x = read(p[i].first.first) + p[i].second;
    update(p[i].first.second + 1, x);
    ans = max(ans, x);
  }
  printf("%lld", ans);
}
