import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.PriorityQueue; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); PriorityQueue que1 = new PriorityQueue<>((o1, o2) -> o1.v - o2.v); PriorityQueue que2 = new PriorityQueue<>((o1, o2) -> o2.v - o1.v); TreeSet set = new TreeSet<>(); for (int i = 0; i < n; i++) { String[] sa = br.readLine().split(" "); Obj o = new Obj(); o.c = Integer.parseInt(sa[0]); o.x = Integer.parseInt(sa[1]); o.y = Integer.parseInt(sa[2]); o.v = o.x - o.y; if (o.v < 0) { que1.add(o); } else { que2.add(o); } set.add(i); } br.close(); long ans = 0; while (!que1.isEmpty()) { Obj o = que1.poll(); Integer k = set.lower(o.c); if (k == null) { set.pollLast(); ans += o.x; } else { set.remove(k); ans += o.y; } } set = new TreeSet<>(); for (int i = n - que2.size(); i < n; i++) { set.add(i); } while (!que2.isEmpty()) { Obj o = que2.poll(); Integer k = set.ceiling(o.c); if (k == null) { set.pollFirst(); ans += o.y; } else { set.remove(k); ans += o.x; } } System.out.println(ans); } static class Obj { int c, x, y, v; } }