N = int(input()) S = input().strip() A = list(map(int,input().split())) Q = int(input()) K = list(map(int,input().split())) BS = [0 for _ in range(N+1)] for i in range(1,N+1): if S[i-1]=="E": BS[i] = BS[i-1]+1 else: BS[i] = BS[i-1] BA = [0 for _ in range(N+1)] for i in range(1,N+1): BA[i] = BA[i-1]+A[i-1] for j in range(Q): k = K[j] cmax = 0 for i in range(N): high = N low = i while high-low>1: mid = (high+low)//2 if mid+1<=N and BA[mid+1]-BA[i]>k: high = mid else: low = mid ind = high cnt = BS[high]-BS[i] cmax = max(cmax,cnt) print(cmax)