from bisect import bisect_right, bisect_left from collections import defaultdict INF = 10**18 N = int(input()) S = input() A = list(map(int, input().split())) Q = int(input()) K = list(map(int, input().split())) enemy = [0] hp = [0] for i in range(N): if S[i] == 'E': enemy.append(enemy[-1] + 1) else: enemy.append(enemy[-1]) hp.append(hp[-1] + A[i]) D = defaultdict(int) for i in range(N): for j in range(i, N): D[hp[j + 1] - hp[i]] = max(D[hp[j + 1] - hp[i]], enemy[j + 1] - enemy[i]) D = [list(d) for d in D.items()] D.sort() tmp = 0 for i in range(len(D)): tmp = max(D[i][1], tmp) D[i][1] = tmp for i in range(Q): x = bisect_left(D, [K[i], INF]) print(D[x - 1][1] if x > 0 else 0)