#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline void relax_min(T &a, U b) {
  a = min(a, b);
}
template <class T, class U>
inline void relax_max(T &a, U b) {
  a = max(a, b);
}
template <typename T>
inline bool updmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool updmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &a) {
  out << a.first << ' ' << a.second;
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &a) {
  for (decltype(0)((i)) = (0); ((i)) < ((((int)(a).size()))); ++((i)))
    in >> a[i];
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &a) {
  for (decltype(0)((i)) = (0); ((i)) < ((((int)(a).size()))); ++((i)))
    out << a[i] << ' ';
  return out;
}
int next_int() {
  int(tmp);
  scanf("%d", &(tmp));
  return tmp;
}
long long next_ll() {
  long long(tmp);
  scanf("%lld", &(tmp));
  return tmp;
}
long long modPow(long long a, long long b, long long MOD) {
  long long ret = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      ret = ((((((long long)(ret) * (long long)(a))) % ((MOD))) + ((MOD))) %
             ((MOD)));
    a = ((((((long long)(a) * (long long)(a))) % ((MOD))) + ((MOD))) % ((MOD)));
  }
  return ret;
}
const long long EXACTLY_ONE_HUNDRED = 100;
const long long EXACTLY_ONE_THOUSAND = 1000;
const long long EXACTLY_ONE_MILLION = 1000 * 1000;
const long long EXACTLY_ONE_BILLION =
    EXACTLY_ONE_THOUSAND * EXACTLY_ONE_MILLION;
const int MAXN1 = (int)(EXACTLY_ONE_HUNDRED * EXACTLY_ONE_THOUSAND) + 3;
const int MAXN2 = (int)(2 * EXACTLY_ONE_HUNDRED * EXACTLY_ONE_THOUSAND) + 3;
const int MAXN3 = (int)(3 * EXACTLY_ONE_HUNDRED * EXACTLY_ONE_THOUSAND) + 3;
const int MAXN4 = (int)(4 * EXACTLY_ONE_HUNDRED * EXACTLY_ONE_THOUSAND) + 3;
const int MAXN5 = (int)(5 * EXACTLY_ONE_HUNDRED * EXACTLY_ONE_THOUSAND) + 3;
const int MAXN = MAXN3;
const int INF = (int)EXACTLY_ONE_BILLION + 7;
const int INF2 = 1 << 30;
const long long INFLL = 4LL * EXACTLY_ONE_BILLION * EXACTLY_ONE_BILLION + 7;
const long long INFLL2 = 1LL << 60;
const long double Pi = acos(-1.0);
const long double EPS = 1e-7;
const int MOD = (int)EXACTLY_ONE_BILLION + 7;
int gen_rand() { return (rand() << 15) + rand(); }
struct node {
  int x, y;
  long long h, maxa;
  node *left, *right;
  node(int val, long long height)
      : x(val), h(height), maxa(height), y(gen_rand()), left(0), right(0) {}
};
typedef pair<node *, node *> pnn;
long long get_maxa(node *treap) { return (treap ? treap->maxa : 0); }
void update(node *treap) {
  if (!treap) return;
  treap->maxa =
      max(max(get_maxa(treap->left), get_maxa(treap->right)), treap->h);
}
node *merge(node *treap1, node *treap2) {
  if (treap1 == 0) return treap2;
  if (treap2 == 0) return treap1;
  if (treap1->y > treap2->y) {
    treap1->right = merge(treap1->right, treap2);
    update(treap1);
    return treap1;
  } else {
    treap2->left = merge(treap1, treap2->left);
    update(treap2);
    return treap2;
  }
}
pnn split(node *treap, int key) {
  if (treap == 0) return pnn(0, 0);
  if (key < treap->x) {
    pnn temp = split(treap->left, key);
    treap->left = temp.second;
    update(treap);
    return pnn(temp.first, treap);
  } else {
    pnn temp = split(treap->right, key);
    treap->right = temp.first;
    update(treap);
    return pnn(treap, temp.second);
  }
}
node *insert(node *treap, int key, long long h) {
  pnn fir = split(treap, key);
  pnn sec = split(fir.first, key - 1);
  node *ins = new node(key, h);
  return merge(merge(sec.first, ins), fir.second);
}
long long get_max(node *treap, int a) {
  pnn fir = split(treap, a);
  long long ans = get_maxa(fir.first);
  merge(fir.first, fir.second);
  return ans;
}
bool cmp(pair<pair<int, int>, long long> a, pair<pair<int, int>, long long> b) {
  if (a.first.first > b.first.first) return true;
  if (a.first.first < b.first.first) return false;
  return (a.first.second > b.first.second);
}
int main() {
  node *treap = NULL;
  int(n);
  scanf("%d", &(n));
  vector<pair<pair<int, int>, long long>> arr;
  for (decltype(0)((i)) = (0); ((i)) < ((n)); ++((i))) {
    int(a), (b);
    scanf("%d%d", &((a)), &((b)));
    long long(h);
    scanf("%lld", &(h));
    arr.emplace_back(pair<int, int>(b, a), h);
  }
  sort((arr).begin(), (arr).end(), cmp);
  long long cur_h = 0;
  int cur_a = INF;
  for (decltype(0)(i) = (0); (i) < (n); ++(i)) {
    cur_h += arr[i].second;
    updmin(cur_a, arr[i].first.second);
    if (i < n - 1 && arr[i].first.first == arr[i + 1].first.first) {
      continue;
    } else {
      long long H = get_max(treap, arr[i].first.first - 1);
      treap = insert(treap, cur_a, cur_h + H);
      cur_a = INF;
      cur_h = 0;
    }
  }
  printf("%lld\n", (get_maxa(treap)));
  return 0;
}
