import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); TreeMap> cakes = new TreeMap<>(); TreeMap compress = new TreeMap<>(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if (!cakes.containsKey(a)) { cakes.put(a, new TreeMap<>()); } if (!cakes.get(a).containsKey(-b) || cakes.get(a).get(-b) < c) { cakes.get(a).put(-b, c); compress.put(b, 0); } } int size = 1; for (int x : compress.keySet()) { compress.put(x, size); size++; } long max = 0; BinaryIndexedTree bit = new BinaryIndexedTree(size); for (TreeMap one : cakes.values()) { for (int x : one.keySet()) { int idx = compress.get(-x); long next = bit.getMax(idx - 1) + one.get(x); max = Math.max(max, next); bit.set(idx, next); } } System.out.println(max); } } class BinaryIndexedTree { int size; long[] tree; public BinaryIndexedTree(int size) { this.size = size; tree = new long[size]; } public void set(int idx, long value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] = Math.max(tree[idx], value); idx += mask; } mask <<= 1; } } public long getMax(int x) { int mask = 1; long ans = 0; while (x > 0) { if ((x & mask) != 0) { ans = Math.max(ans, tree[x]); x -= mask; } mask <<= 1; } return ans; } }