#include <bits/stdc++.h>
using namespace std;
long long Max(long long a, long long b) { return a < b ? b : a; }
struct Node {
  int a, b, h;
  Node(int _a = 0, int _b = 0, int _h = 0) : a(_a), b(_b), h(_h) {}
} node[100010], ring[100010];
bool cmp(Node n1, Node n2) { return n1.b > n2.b; }
int n, m;
long long dp[100010];
int ha[100010];
struct TreeNode {
  int l, r;
  long long ma;
  int mid() { return l + r >> 1; }
} tree[100010 << 2];
void build(int l, int r, int rt) {
  tree[rt].l = l, tree[rt].r = r, tree[rt].ma = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
}
long long setv[100010 << 2];
void pushdown(int rt) {
  if (setv[rt]) {
    setv[rt << 1] = setv[rt << 1 | 1] = setv[rt];
    setv[rt] = 0;
  }
}
void maintain(int rt) {
  if (tree[rt].r > tree[rt].l)
    tree[rt].ma = Max(tree[rt << 1].ma, tree[rt << 1 | 1].ma);
  tree[rt].ma = Max(tree[rt].ma, setv[rt]);
}
void update(long long c, int L, int R, int rt) {
  if (tree[rt].l >= L && tree[rt].r <= R) {
    if (c >= tree[rt].ma) setv[rt] = c;
  } else {
    pushdown(rt);
    int mid = tree[rt].mid();
    if (L <= mid)
      update(c, L, R, rt << 1);
    else
      maintain(rt << 1);
    if (R >= mid + 1)
      update(c, L, R, rt << 1 | 1);
    else
      maintain(rt << 1 | 1);
  }
  maintain(rt);
}
long long ma;
void query(int L, int R, int rt) {
  if (setv[rt] > 0)
    ma = Max(ma, setv[rt]);
  else if (tree[rt].l >= L && tree[rt].r <= R)
    ma = Max(ma, tree[rt].ma);
  else {
    int mid = tree[rt].mid();
    if (L <= mid) query(L, R, rt << 1);
    if (R >= mid + 1) query(L, R, rt << 1 | 1);
  }
}
int main() {
  while (~scanf("%d", &n)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++)
      scanf("%d%d%d", &node[i].a, &node[i].b, &node[i].h);
    sort(node + 1, node + n + 1, cmp);
    m = 0;
    ring[++m] = node[1];
    for (int i = 2; i <= n; i++) {
      if (node[i].b == node[i - 1].b)
        ring[m].a = min(ring[m].a, node[i].a), ring[m].h += node[i].h;
      else
        ring[++m] = node[i];
    }
    for (int i = 1; i <= m; i++) ha[i] = ring[i].a;
    sort(ha + 1, ha + m + 1);
    int M = unique(ha + 1, ha + 1 + m) - (ha + 1);
    build(1, M, 1);
    for (int i = 1; i <= m; i++) {
      int t = lower_bound(ha + 1, ha + 1 + M, ring[i].b) - (ha + 1);
      ma = 0;
      if (t <= M && t >= 1) query(1, t, 1);
      dp[i] = ma + ring[i].h;
      t = lower_bound(ha + 1, ha + 1 + M, ring[i].a) - ha;
      update(dp[i], t, t, 1);
    }
    long long ans = 0;
    for (int i = 1; i <= m; i++) ans = Max(ans, dp[i]);
    printf("%lld\n", ans);
  }
  return 0;
}
