#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) int main() { int n; cin >> n; string s; cin >> s; vector a(n),sum(n+1,0); vector b(n+1,0); for (int i = 0;i < n;++i) cin >> a[i]; for (int i = 0;i < n;++i) sum[i+1] = sum[i]+a[i]; for (int i = 0;i < n;++i) if (s[i] == 'E') b[i+1] = 1; for (int i = 0;i < n;++i) b[i+1] += b[i]; int q; cin >> q; for (int z = 0;z < q;++z) { ll k; cin >> k; int ans = 0; for (int i = 0;i < n;++i) { int ok = 0,ng = n-i+1; while (ng-ok > 1) { int mid = (ok+ng)/2; (sum[i+mid]-sum[i] <= k ? ok : ng) = mid; } ans = max(ans,b[i+ok]-b[i]); } cout << ans << "\n"; } }