#include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr ll MOD = 1e9 + 7; constexpr int INF = 1 << 30; int N, Q, K; string S; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> S; vector A(N), SE(N+1), SK(N+1); for(int i = 0; i < N; ++i) cin >> A[i]; for(int i = 0; i < N; ++i) { SE[i+1] = SE[i] + (S[i] == 'E'); SK[i+1] = SK[i] + A[i]; } cin >> Q; for(int i = 0; i < Q; ++i) { cin >> K; if(K >= SK[N]) { cout << SE[N] << '\n'; continue; } ll ans = 0; int l = 0, r = 0; while(true) { while(r <= N && SK[r] - SK[l] <= K) ++r; if(r == N + 1) break; ans = max(ans, SE[r-1] - SE[l]); if(l == r) ++r; ++l; } cout << ans << '\n'; } return 0; }