def binary_search_int(ok, ng, test): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test(mid): ok = mid else: ng = mid return ok ############################################################## import sys input = sys.stdin.readline N=int(input()) S=input().rstrip() A=list(map(int, input().split())) Q=int(input()) K=list(map(int, input().split())) SS=[0] for s in S: SS.append(SS[-1]+(s=="E")) SA=[0] for a in A: SA.append(SA[-1]+a) for k in K: res=0 for i in range(N): def test(x): return SA[x]-SA[i]<=k r=binary_search_int(i+1,N+1,test) res=max(SS[r]-SS[i],res) print(res)