from heapq import heappush, heappop n = int(input()) assert 1 <= n <= 10**5 n *= 2 C = [] L = [] R = [] for _ in range(n): c, l, r = input().split() assert 1 <= int(l) <= 10**9 assert 1 <= int(r) <= 10**9 C.append(c) L.append(int(l)) R.append(int(r)) assert C.count("(") == C.count(")") == n // 2 ans = 0 lc = 0 rc = 0 hq = [] for c, l, r in zip(C[::-1], L[::-1], R[::-1]): if c == "(": lc += 1 ans += l if r > l: heappush(hq, r - l) else: rc += 1 ans += r if l > r: heappush(hq, l - r) if min(lc, rc) < len(hq): heappop(hq) ans += sum(hq) print(ans)