#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; vector a(n); REP (i, n) cin >> a[i]; int q; cin >> q; while (q--) { long long k; cin >> k; long long acc = 0; int ret = 0; int cnt = 0; for (int i = 0, j = 0; i < n; i++) { j = max(j, i); while (j < n && acc + a[j] <= k) { acc += a[j]; if (s[j] == 'E') ++cnt; ++j; } ret = max(ret, cnt); if (i < j) { acc -= a[i]; if (s[i] == 'E') --cnt; } } cout << ret << endl; } return 0; }