#include #define rep(i,n) for(int i=0;i pp; const int INF = 1e9; const int MOD = 1000000007; int main() { int n; cin >> n; string s; cin >> s; vector mon(n+1); vector a(n+1); rep(i,n) cin >> a[i+1]; rep(i,n) a[i+1] += a[i]; rep(i,n){ if(s[i] == 'E') mon[i+1] ++; } rep(i,n) mon[i+1] += mon[i]; map mp; for(int i=0;i<=n;i++){ for(int j=i+1;j<=n;j++){ int key = a[j] - a[i]; int value = mon[j] - mon[i]; mp[key] = max(mp[key],value); } } int before = -1; for(auto it = mp.begin();it !=mp.end();it++){ if(it->second < before) it->second = before; else before = it->second; } vector num = {pp(0,0)}; for(auto p:mp){ num.push_back(pp(p.first,p.second)); } int q; cin >> q; rep(i,q){ int k; cin >> k; int l = -1,r = num.size(); while(r - l > 1){ int m = (l + r)/2; if(num[m].first <= k) l = m; else r = m; } cout << num[l].second << endl; } return 0; }