#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define fi first
#define se second
#define endl "\n"
#define YES return cout << "YES" << endl, void()
#define NO return cout << "NO" << endl, void()
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const double PI = acos(-1);
const double eqa = (1+sqrt(5.0))/2.0;
const int mod = 1000000007, inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int dx[] = {0, 1, 0, -1, -1, 1, 1, -1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
int gcd(int x, int y) {return y ? gcd(y, x % y) : x;}
int qmi(int a, int k, int p){int res = 1;while (k){if (k & 1) res = (LL)res * a % p;a = (LL)a * a % p;k >>= 1;}return res;}
int read(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-') f = -1; ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}return x * f;}
const int N = 200010;
void solve()
{
int n;
cin >> n;
vector<int> a(n + 1, 0);
for ( int i = 1; i <= n; i ++ ) cin >> a[i];
string s;
cin >> s;
s = ' ' + s;
vector<int> psa(n + 2, 0), ssa(n + 2, 0), psb(n + 2, 0), ssb(n + 2, 0);
for ( int i = 1; i <= n; i ++ ) {
if (s[i] == 'A') {
psa[i] = psa[i - 1] + a[i];
psb[i] = psb[i - 1];
}
else {
psb[i] = psb[i - 1] + a[i];
psa[i] = psa[i - 1];
}
// cout << psa[i] << " " << psb[i] << endl;
}
for ( int i = n; i >= 1; i -- ) {
if (s[i] == 'A') {
ssa[i] = ssa[i + 1] + a[i];
ssb[i] = ssb[i + 1];
} else {
ssb[i] = ssb[i + 1] + a[i];
ssa[i] = ssa[i + 1];
}
}
int mx = 0;
for ( int i = 1; i <= n; i ++ ) {
mx = max(mx, psa[i] - psb[i]);
}
for ( int i = n; i >= 1; i -- ) {
mx = max(mx, ssa[i] - ssb[i]);
}
cout << psb[n] + mx << endl;
}
signed main()
{
ios;
int t = 1;
// cin >> t;
while (t --)
{
solve();
}
return 0;
}
1144D - Equalize Them All | 298A - Snow Footprints |
1753B - Factorial Divisibility | 804A - Find Amir |
1541C - Great Graphs | 607B - Zuma |
30A - Accounting | 959C - Mahmoud and Ehab and the wrong algorithm |
1215A - Yellow Cards | 237B - Young Table |
1216D - Swords | 271D - Good Substrings |
573A - Bear and Poker | 10A - Power Consumption Calculation |
1244B - Rooms and Staircases | 777A - Shell Game |
1698D - Fixed Point Guessing | 415B - Mashmokh and Tokens |
26D - Tickets | 471B - MUH and Important Things |
982B - Bus of Characters | 1102B - Array K-Coloring |
818A - Diplomas and Certificates | 70A - Cookies |
798A - Mike and palindrome | 1690F - Shifting String |
366B - Dima and To-do List | 120B - Quiz League |
740A - Alyona and copybooks | 1491A - K-th Largest Value |