#include using namespace std; #define lli long long int #define uli unsigned long long int #define INF 999999999999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(30) << S << endl #define ALL(a) a.begin(),a.end() #define Vec(K,L,N,S) vector K(N,S) #define DV(K,L,N,M,S) vector> K(N,vector(M,S)) #define TV(K,L,N,M,R,S) vector>> K(N,vector>(M,vector(R,S))) #define pint pair #define paf(L,R) pair #define mod 1000000007 #define MAX 5100000 #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) int main(){ lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T; cin >> N >> S; Vec(P,pint,N+1,pint(0,0)); map St,RSt; rep(i,1,N+1)cin >> P[i].first; cin >> M; Vec(Q,lli,M,0);//query rep(i,0,M)cin >> Q[i]; rep(i,1,N+1)P[i].first+=P[i-1].first; rep(i,1,N+1)if(S[i-1]=='E')P[i].second+=P[i-1].second+1;else P[i].second+=P[i-1].second; rep(i,0,N+2)St[i]=INF; rep(i,0,N)rep(j,i+1,N+1)chmin(St[P[j].second-P[i].second],P[j].first-P[i].first); St[0]=0; rep(i,0,N+2)if(St[i-1]!=INF)RSt[St[i]]=i; rep(i,0,M)Out(RSt[RSt.upper_bound(Q[i])->first]-1); }