#include #include using namespace std; using LL = long long; using P = pair; using Graph = vector>; const int INF = 1 << 29; const long long LINF = 1LL << 60; #define all(x) (x).begin(), (x).end() #define rep(i,n) for(int i = 0; i < (n); ++i) templatevoid chmin(T&a, T b){if(a > b) a = b;} templatevoid chmax(T&a, T b){if(a < b) a = b;} int main(){ int N; cin >> N; string S; cin >> S; vector a(N, 0); for(int i = 0; i < N; ++i) cin >> a[i]; vector R(N+1, 0), B(N+1, 0); for(int i = 0; i < N; ++i){ R[i+1] += R[i]; B[i+1] += B[i]; if(S[i] == 'R') R[i+1] += a[i]; else B[i+1] += a[i]; } LL ans = 0; for(int i = 1; i <= N; ++i){ for(int j = 0; j < N; ++j){ LL tmp = abs(R[i] - R[j] - B[i] + B[j]); ans = max(ans, tmp); } } cout << ans << endl; }