# 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 n =int(input()) s = input() a = lmp() for i in range(n): if s[i] == "B":a[i]*=-1 a = [0] + list(accumulate(a)) mx = list(accumulate(a, func=max)) mn = list(accumulate(a, func=min)) print(mx[-1]-mn[-1])