#include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll=long long; int main(){ int N; string S; cin >> N >> S; vector A(N); for(int i = 0; i < N; i++){ cin >> A[i]; if(S[i] == 'B')A[i] *= -1; } ll sum = 0, Ama = 0, Ami = 10E16; for(int i = 0; i < N; i++){ sum += A[i]; Ama = max(Ama, sum); Ami = min(Ami, sum); } if((Ama / abs(Ama)) * (Ami / abs(Ami)) >= 0)cout << max(abs(Ama), abs(Ami)) << endl; else cout << abs(Ama - Ami) << endl; return 0; }