#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { int n; cin >> n; string s; cin >> s; vector

v; ll a[n]; rep(i,n)cin >> a[i]; rep(i,n){ ll sum = 0; ll cnt = 0; srep(j,i,n){ sum += a[j]; if(s[j] == 'E')cnt++; v.push_back(P(sum, cnt)); } } sort(v.begin(), v.end()); int m = v.size(); srep(i,1,m){ if(v[i].second < v[i-1].second){ v[i].second = v[i-1].second; } } int q; cin >> q; rep(loop,q){ ll x; cin >> x; P p; p.first = x+1; p.second = 0; auto ite = lower_bound(v.begin(), v.end(), p); if(ite - v.begin() == 0){ cout << '0' << endl; }else{ cout << v[ite - v.begin() - 1].second << endl; } } return 0; }