const maxn=200000;oo=100000000; var i,j,n,size,last,t:longint; h:array[1..maxn] of longint; a:array[0..maxn,1..2] of longint; b:array[0..maxn] of longint; ch:char; ans:int64; procedureswap(var x,y:longint); var t:longint; begin t:=x; x:=y; y:=t; end; proceduredown(x:longint); var y:longint; begin y:=2*x; while ((y<=size) and (h[x]>h[y])) or ((y+1<=size) and (h[x]>h[y+1])) do begin if (y+1<=size) and (h[y+1]<h[y]) then inc(y); swap(h[x],h[y]); x:=y; y:=2*x; end; end; procedureup(x:longint); begin while (x>1) and (h[x]<h[x>>1]) dobegin swap(h[x],h[x>>1]); x:=x>>1; end; end; procedurepop; begin h[1]:=h[size]; h[size]:=oo; dec(size); down(1); end; procedurepush(x:longint); var i:longint; begin inc(size); h[size]:=x; up(size); end; begin readln(n); for i:=1to n dobegin readln(ch,a[i,2]); if ch='c'then a[i,1]:=1else a[i,1]:=2; end; for i:=1to n-1dobegin if a[i,1]=1then push(a[i,2]) elsebegin t:=a[i,2]-1; while size>t do pop; end; end; ans:=0; for i:=1to size do inc(ans,h[i]); writeln(ans); end.