#include using namespace std; template int SumDigit(T N) { int res = 0; while(N > 0) { res += (N % 10); N /= 10; } return res; } int main(){ int N, Q; string S; cin >> N >> S; vector HP(N); vector sum(N+1, 0); vector ene(N+1, 0); for (int i = 0; i < N; i++) { cin >> HP[i]; sum[i+1] = sum[i] + HP[i]; ene[i+1] = ene[i]; if (S[i] == 'E') ene[i+1]++; } cin >> Q; for (int i = 0; i < Q; i++) { long long K; cin >> K; if (sum[N] <= K) { cout << ene[N] << endl; continue; } int ans = 0; for (int j = 0; j <= N; j++) { long long k = K + sum[j]; int m = lower_bound(sum.begin(), sum.end(), k) - sum.begin(); int res = ene[m]-ene[j]; if (k < sum[m] && m > 0) res = ene[m-1] - ene[j]; ans = max(ans, res); } cout << ans << endl; } return 0; }