N=int(input()) S=input() A=list(map(int, input().split())) cumsum = [0] for i, s in enumerate(list(S)): if s == "B": A[i] = -A[i] cumsum.append(cumsum[-1] + A[i]) x = -float('inf') for i in range(0, len(cumsum)-1): for k in range(i+1, len(cumsum)): a = abs(cumsum[k] - cumsum[i]) x = max(a, x) print(x)