n = int(input()) s = input() a = list(map(int, input().split())) q = int(input()) query = list(map(int, input().split())) ruiseki = [0] * (n+1) for i in range(n): ruiseki[i+1] = ruiseki[i] + (1 if s[i] == "E" else 0) # ダブリング log_size = n.bit_length() double = [[0] * n for i in range(log_size)] INF = 10**18 for i in range(n): double[0][i] = a[i] for k in range(1, log_size): for i in range(n): if i+2**(k-1) < n: double[k][i] = double[k-1][i+2**(k-1)] + double[k-1][i] else: double[k][i] = INF for qi in range(q): ans = 0 for ni in range(n): ans_tmp = 0 ans_num = 0 k = log_size - 1 i = ni while True: if k < 0 or i == n: break if ans_num + double[k][i] <= query[qi]: ans_num += double[k][i] i += 2**k ans_tmp += 2**k k -= 1 ans_tmp = ruiseki[i] - ruiseki[ni] ans = max(ans, ans_tmp) print(ans)