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); 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); } } br.close(); TreeSet set = new TreeSet<>(); for (int i = 0; i < n; i++) { set.add(i); } long ans = 0; while (!que1.isEmpty()) { Obj o = que1.poll(); Integer k = set.lower(o.c); if (k == null) { k = set.last(); ans += o.x; } else { ans += o.y; } set.remove(k); } set.clear(); 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) { k = set.first(); ans += o.y; } else { ans += o.x; } set.remove(k); } System.out.println(ans); } static class Obj { int c, x, y, v; } }