#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back #define mod 1000000007 using ll = long long; using namespace std; ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} int main(){ ll N; cin >> N; string S; cin >> S; vector A(N); rep(i,N) cin >> A[i]; vector sums(N+1,0); rep(i,N) sums[i+1] = sums[i] + A[i]; vector esum(N+1,0); rep(i,N) esum[i+1] = esum[i] + ((S[i]=='E')?1:0); // rep(i,N+1) cout << esum[i] << " "; ll Q; cin >> Q; rep(q,Q){ ll K; cin >> K; ll ans=0; ll l,r; for(l=0,r=0; l<=N; l++){ while(r+1<=N && sums[r+1]-sums[l]<=K){ r++; } cout << l << " " << r << " " << esum[r]-esum[l] << endl; ans = max(ans,esum[r]-esum[l]); } cout << ans << endl; } return 0; }