#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int q; cin >> q; for (int h = 0; h < q; h++) { int k; cin >> k; int i0 = 0, i1 = 0; int r = 0, x = 0, y = 0; for (; i0 < n;) { while (i1 < n && x + a[i1] <= k) { x += a[i1]; y += s[i1] == 'E'; i1++; } r = max(r, y); x -= a[i0]; y -= s[i0] == 'E'; i0++; } cout << r << '\n'; } return 0; }