#include <bits/stdc++.h>   using namespace std;   int n;   long long L[500005];   char ch[500005];   class segtree {    public:     long long seg[(1 << 19) * 2];     long long lazy[(1 << 19) * 2];     void lazy_evaluate(int k) {       if (k * 2 + 2 >= (1 << 19) * 2) return;       lazy[k * 2 + 2] += lazy[k];       lazy[k * 2 + 1] += lazy[k];       seg[k * 2 + 2] += lazy[k];       seg[k * 2 + 1] += lazy[k];       lazy[k] = 0;     }     long long update(int beg, int end, int idx, int lb, int ub, long long num) {       if (ub < beg || end < lb) {         return seg[idx];       }       if (beg <= lb && ub <= end) {         lazy[idx] += num;         seg[idx] += num;         return seg[idx];       }       if (lazy[idx]) {         lazy_evaluate(idx);       }       return seg[idx] =                  min(update(beg, end, idx * 2 + 1, lb, (lb + ub) / 2, num),                      update(beg, end, idx * 2 + 2, (lb + ub) / 2 + 1, ub, num));     }     long long query(int beg, int end, int idx, int lb, int ub) {       if (ub < beg || end < lb) {         return 1500000000000000000LL;       }       if (beg <= lb && ub <= end) {         return seg[idx];       }       if (lazy[idx]) {         lazy_evaluate(idx);       }       return min(query(beg, end, idx * 2 + 1, lb, (lb + ub) / 2),                  query(beg, end, idx * 2 + 2, (lb + ub) / 2 + 1, ub));     }   } kaede;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &L[i]);     scanf( %s , &ch);     long long cur = 0;     long long ans = 0;     bool ok = 0;     for (int i = 0; i < n; i++) {       if (ch[i] ==  L )         ans += L[i];       else if (ch[i] ==  W )         ans += L[i] * 3LL;       else         ans += L[i] * 5LL;     }     vector<long long> vec;     int lasw, lasg;     for (int i = 0; i < n; i++) {       if (ch[i] ==  G ) {         cur += L[i];         kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);         vec.push_back(L[i]);         lasg = i;         continue;       }       if (ch[i] ==  W ) {         cur += L[i];         lasw = i;         ok = 1;         kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);         vec.push_back(L[i]);         continue;       }       if (ch[i] ==  L ) {         if (cur >= L[i]) {           cur -= L[i];           kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);           vec.push_back(L[i]);           continue;         } else {           long long need = L[i] - cur;           if (ok) {             ans += 3LL * need;             vec[lasw] += need;           } else {             ans += 5LL * need;             vec[lasg] += need;           }           cur = 0;           vec.push_back(L[i]);           kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);           continue;         }       }     }     for (int i = n - 1; i >= 0; i--) {       if (ch[i] ==  L ) continue;       if (ch[i] ==  W ) continue;       long long mn = kaede.query(i, n - 1, 0, 0, (1 << 19) - 1);       if (2LL * vec[i] <= mn) {         kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -2LL * vec[i]);         ans -= 4LL * vec[i];       } else {         kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -mn);         ans -= 2LL * mn;       }     }     for (int i = n - 1; i >= 0; i--) {       if (ch[i] ==  L ) continue;       if (ch[i] ==  G ) continue;       long long mn = kaede.query(i, n - 1, 0, 0, (1 << 19) - 1);       if (2LL * vec[i] <= mn) {         kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -2LL * vec[i]);         ans -= 2LL * vec[i];       } else {         kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -mn);         ans -= 1LL * mn;       }     }     cout << ans << endl;   }