#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; const ll INF=1e18+7; int main(){ int n; string s; cin>>n>>s; vector A(n+1); A[0]=0; rep(i,n){ ll x; cin>>x; if(s[i]=='R') A[i+1]=x; else A[i+1]=-x; } ll ma=-INF,mi=INF,tmp=0; rep(i,n+1){ tmp+=A[i]; ma=max(ma,tmp); mi=min(mi,tmp); } cout<