#include #include using namespace std; using namespace atcoder; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; //using mint = modint1000000007; //using mint = modint998244353; int main(){ int N; cin >> N; string S; cin >> S; vector v1,v2; rep(i,N){ ll a; cin >> a; if(S[i] == 'R'){ v1.push_back(a); v2.push_back(-a); }else{ v1.push_back(-a); v2.push_back(a); } } ll ret = -1e18; { ll mx = v1[0]; ret = max(ret, mx); REP(i,1,N){ mx = max(v1[i], mx+v1[i]); ret = max(ret, mx); } } { ll mx = v2[0]; ret = max(ret, mx); REP(i,1,N){ mx = max(v2[i], mx+v2[i]); ret = max(ret, mx); } } cout << ret << endl; return 0; }