from itertools import accumulate from math import inf N=int(input()) S=input() A=list(map(int,input().split())) L=[0]*(N+1) for i in range(N): if S[i]=="R": L[i+1]=A[i] else: L[i+1]=-A[i] LA=list(accumulate(L)) class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __init__(self,V,OP,E): #初期値(配列),演算,単位元で初期化 self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<>i) def get(self,p): #1点取得 assert 0<=p and p>=1 r>>=1 return self.op(sml,smr) def all_prod(self): #全区間取得 return self.d[1] def MIN(x,y): return min(x,y) def MAX(x,y): return max(x,y) seg_min=segtree(LA,MIN,inf) seg_max=segtree(LA,MAX,-inf) ans_min=0 ans_max=0 for i in range(1,N+1): ans_min=min(ans_min,LA[i]-seg_max.prod(0,i)) ans_max=max(ans_max,LA[i]-seg_min.prod(0,i)) print(max(-ans_min,ans_max))