from heapq import heappop,heappush n = int(input()) a = []; b = []; s = 0 for _ in range(n): c,x,y = map(int,input().split()); s += max(x,y) if xy: b.append((n-c,x-y)) def f(a): global s; h = [] for c,d in sorted(a): heappush(h,d) if len(h)>c: s -= heappop(h) f(a); f(b); print(s)