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] for i in range(N): if S[i] == 'E': enemy.append(enemy[-1] + 1) else: enemy.append(enemy[-1]) hp = [0] for i in range(N): hp.append(hp[-1] + A[i]) min_hp = [INF for _ in range(N + 1)] for i in range(N): for j in range(i + 1, N + 1): min_hp[enemy[j] - enemy[i]] = min(hp[j] - hp[i], min_hp[enemy[j] - enemy[i]]) for k in range(Q): res = 0 for i in range(N): if min_hp[i] <= K[k]: res = max(i, res) print(res)