#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; string S; cin >> S; vector E(N); rep(i,N) E[i] = (S[i] == 'E'); vector E_sum(N + 1, 0); rep(i,N) E_sum[i + 1] += E_sum[i] + E[i]; vector A(N); rep(i,N) cin >> A[i]; vector A_sum(N + 1, 0); rep(i,N) A_sum[i + 1] += A_sum[i] + A[i]; E_sum.push_back(E_sum.back()); A_sum.push_back(ll(1e18)); int Q; cin >> Q; rep(_,Q) { ll K; cin >> K; int ans = 0; rep(i,N) { int x = upper_bound(A_sum.begin(), A_sum.end(), A_sum[i] + K) - A_sum.begin() - 1; ans = max(ans, E_sum[x] - E_sum[i]); } cout << ans << "\n"; } }