import collections N=int(input()) S=input() *A,=map(int,input().split()) cs = [0] for i in range(N): if S[i] == "B": A[i] = -A[i] cs.append(cs[-1] + A[i]) print(abs(max(cs) - min(cs)))