#include "bits/stdc++.h" #define REP(i, n) for(int i = 0; i < int(n); i++) #define FOR(i,n,m) for(int i = int(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = 1e9 + 6; const ll LLINF = 1e18 + 1; int main() { int n; cin >> n; string s; cin >> s; vector a(n); vector sum(n + 1), enemy(n + 1); sum[0] = 0; enemy[0] = 0; REP(i, n) { cin >> a[i]; sum[i + 1] = sum[i] + a[i]; enemy[i + 1] = enemy[i]; if (s[i] == 'E') enemy[i + 1]++; } REP(i, n) { cout << sum[i] << " "; } cout << endl; REP(i, n) { cout << enemy[i] << " "; } cout << endl; int q; cin >> q; REP(i, q) { int k; cin >> k; ll ans = 0; REP(j, n) { ans = max(ans,enemy[upper_bound(sum.begin(), sum.end(), k + sum[j]) - sum.begin() - 1] - enemy[j]); } cout << ans << endl; } return 0; }