import sys input = sys.stdin.readline from heapq import heappop,heappush N=int(input()) X=[input().split() for i in range(2*N)] X.reverse() l=0 r=0 ANS=0 H=[] for s,x,y in X: x=int(x) y=int(y) if s==")": if y>=x: r+=1 ANS+=y else: ANS+=x heappush(H,(x-y)) l-=1 else: if x>=y: l+=1 ANS+=x else: ANS+=y heappush(H,(y-x)) r-=1 if l<0 or r<0: k=heappop(H) ANS-=k l+=1 r+=1 print(ANS)