import itertools N = int(input()) S = input() A = list(map(int, input().split())) for i in range(N): if S[i]=='B': A[i]*=-1 AC = list(itertools.accumulate(A)) + [0] mi = min(AC) ma = max(AC) print(abs(mi-ma))