from bisect import bisect from itertools import accumulate N = int(input()) S = input() A = [0] + list(map(int, input().split())) Q = int(input()) K = list(map(int, input().split())) AA = list(accumulate(A)) SA = [0] * (N + 2) for i, s in enumerate(S): if s == "E": SA[i + 1] = SA[i] + 1 else: SA[i + 1] = SA[i] for k in K: ans = 0 for i in range(N): aa = AA[i] sa = SA[i] x = bisect(AA, k + aa) - 1 ans = max(ans, SA[x] - sa) print(ans)