using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); var Q = int.Parse(Console.ReadLine()); var K = Console.ReadLine().Split().Select(int.Parse).ToArray(); var acum = new long[N + 1]; var count = new int[N + 1]; for (var i = 0; i < N; i++) { acum[i + 1] = acum[i] + A[i]; count[i + 1] = count[i] + (S[i] == 'E' ? 1 : 0); } for (var i = 0; i < Q; i++) { var ans = 0; for (var j = 0; j <= N; j++) { var ok = j; var ng = N + 1; while (ng - ok > 1) { var med = (ng + ok) / 2; if (acum[med] - acum[j] <= K[i]) ok = med; else ng = med; } ans = Math.Max(ans, count[ok] - count[j]); } Console.WriteLine(ans); } } } }