#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; ll ans = 0; for(int j = 0; j < N; ++j) { for(int k = j + 1; k <= N; ++k) { if(SK[k] - SK[j] > K) break; ans = max(ans, SE[k] - SE[j]); } } cout << ans << '\n'; } return 0; }