/** * author: shu8Cream * created: 19.03.2021 23:17:00 **/ #include using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair; using vi = vector; using vvi = vector; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; string s; cin >> n >> s; vector a(n),ra(n+1); rep(i,n) cin >> a[i]; ll ans = 0; rep(i,n) if(s[i]=='B') a[i] = -a[i]; rep(i,n) ra[i+1]=ra[i]+a[i]; ll m=1e18, M=-1e18; rep(i,n+1){ m=min(m,ra[i]); M=max(M,ra[i]); } cout << abs(M-m) << endl; }