import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); ArrayList fruits = new ArrayList<>(); TreeMap compress = new TreeMap<>(); for (int i = 0; i < n; i++) { Fruit f = new Fruit(sc.nextInt(), sc.nextInt(), sc.nextInt()); if (f.enable()) { fruits.add(f); compress.put(f.right, null); } } Collections.sort(fruits); int idx = 1; for (int x : compress.keySet()) { compress.put(x, idx++); } long ans = 0; TreeMap maxes = new TreeMap<>(); maxes.put(0, 0L); for (Fruit f : fruits) { Integer position = compress.get(f.right); long next = maxes.floorEntry(position).getValue() + f.value; ans = Math.max(ans, next); maxes.put(position, next); while ((position = maxes.higherKey(position)) != null) { if (maxes.get(position) > next) { break; } maxes.remove(position); } } System.out.println(ans); } static class Fruit implements Comparable { int left; int right; int value; public Fruit(int t, int x, int value) { left = t + x; right = t - x; this.value = value; } public int compareTo(Fruit another) { if (left == another.left) { return right - another.right; } else { return left - another.left; } } public boolean enable() { return left >= 0 && right >= 0; } public String toString() { return left + ":" + right + ":" + value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }