import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n = ni() c, x, y = zip(*[na() for i in range(n)]) z = [[] for i in range(n+1)] for i in range(n): z[c[i]].append(i) from heapq import * hq = [] for i in range(n): heappush(hq, (x[i] - y[i], i)) f = [0] * n ans = sum(x) # print(hq, ans) for i in range(n): for j in z[i]: f[j] = 1 while hq and f[hq[0][1]]: heappop(hq) # print(f) if hq and hq[0][0] <= 0: v, j = heappop(hq) # print(v, j) ans -= v print(ans)