import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random input = sys.stdin.readline n = int(input()) a = [list(map(int,input().split())) for i in range(n)] p = [] q = [] ans = 0 t = 0 for c,x,y in a: if c == 0: ans += x t += 1 continue if c == n: ans += y t += 1 continue if x > y: p.append((x-y,c)) ans += y elif x < y: q.append((y-x,c)) ans += x else: ans += x t += 1 t += len(q) h = [] p.sort(key=lambda z:z[1],reverse=True) for i in range(t,n): while p and p[-1][1] <= i: heapq.heappush(h,-p[-1][0]) p.pop() if h: ans -= heapq.heappop(h) q.sort(key=lambda z:z[1]) h = [] for i in reversed(range(t)): while q and q[-1][-1] > i: heapq.heappush(h,-q[-1][0]) q.pop() if h: ans -= heapq.heappop(h) print(ans)