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