# import sys # input = sys.stdin.readline def mp():return map(int,input().split()) def lmp():return list(map(int,input().split())) import math import bisect from copy import deepcopy as dc from itertools import accumulate from collections import Counter, defaultdict, deque def ceil(U,V):return (U+V-1)//V def modf1(N,MOD):return (N-1)%MOD+1 inf = int(1e30) mod = 998244353 def subseg_max(lst): ans_mn,ans_mx = int(1e30),-int(1e30) mn,mx = 0,0 for i in range(len(lst)): mn = min(mn+lst[i],0) mx = max(mx+lst[i],0) ans_mn = min(ans_mn,mn) ans_mx = max(ans_mx,mx) return ans_mx,ans_mn n =int(input()) s = input() a = lmp() for i in range(n): if s[i] == "B":a[i]*=-1 a,b = subseg_max(a) print(max(abs(a),abs(b)))