#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int main(){ int N; cin >> N; string S; cin >> S; vector v; rep(i,N){ ll a; cin >> a; v.push_back(a); } vector memo(N+1, 10000000000000LL); rep(i,N){ ll base = 0; ll cnt = 0; REP(j,i,N){ if(S[j] == 'E') cnt++; base += v[j]; memo[cnt] = min(memo[cnt], base); } } reverse(ALLOF(v)); reverse(ALLOF(S)); rep(i,N){ ll base = 0; ll cnt = 0; REP(j,i,N){ if(S[j] == 'E') cnt++; base += v[j]; memo[cnt] = min(memo[cnt], base); } } int Q; cin >> Q; rep(i,Q){ ll k; cin >> k; int ret = 0; rep(j,memo.size()){ if(memo[j] <= k) ret = max(ret, j); } cout << ret << endl; } return 0; }