def main1(n,s,a): ans=-float('inf') """ |R-B|=max(R-B,B-R) """ b=[ai if si=='R' else -ai for ai,si in zip(a,s)] # bの連続部分列和の最大 sb=[0] for x in b:sb.append(sb[-1]+x) m=0 for x in sb[1:]: ans=max(ans,x-m) m=min(m,x) b=[-ai if si=='R' else ai for ai,si in zip(a,s)] # bの連続部分列和の最大 sb=[0] for x in b:sb.append(sb[-1]+x) m=0 for x in sb[1:]: ans=max(ans,x-m) m=min(m,x) return ans if __name__=='__main__': n=int(input()) s=list(input()) a=list(map(int,input().split())) print(main1(n,s,a))