using System; namespace yukicode { class No935 { static void Main(string[] args) { int targetNum = 0; int attackNum = 0; int retOne = 0; int retStart = 0; int retEnd = 0; int output = 0; int power = 0; string input; string sort; input = Console.ReadLine(); targetNum = int.Parse(input); sort = Console.ReadLine(); input = Console.ReadLine(); string[] str1 = input.Split(" "); int[] hp = new int[targetNum]; for(int i=0; i < targetNum; i++) { hp[i] = int.Parse(str1[i]); } input = Console.ReadLine(); attackNum = int.Parse(input); input = Console.ReadLine(); string[] str2 = input.Split(" "); for (int i = 0; i < attackNum; i++) { power = int.Parse(str2[i]); retOne = AttackOne(sort, hp, power); if(1 == retOne) { retStart = AttackStart(sort, hp, power); retEnd = AttackEnd(sort, hp, power); if(retStart >= retEnd) { output = retStart; } else { output = retEnd; } } else { output = retOne; } Console.WriteLine(output); } return; } static private int AttackOne(string sort, int[] hp, int power) { int ret = 0; for(int i = 0; i < hp.Length; i++) { if('E' == sort[i]) { if(hp[i] <= power) { ret = 1; break; } } } return ret; } static private int AttackStart(string sort, int[] hp, int power) { int ret = 0; int tempMax = 0; int tempPower = 0; for(int i = 0; i < hp.Length; i++) { tempMax = 0; tempPower = power; for (int j = i; j < hp.Length; j++) { if (hp[j] <= tempPower) { tempPower = tempPower - hp[j]; if ('E' == sort[j]) { tempMax++; } } else { break; } } if(ret < tempMax) { ret = tempMax; } } return ret; } static private int AttackEnd(string sort, int[] hp, int power) { int ret = 0; int tempMax = 0; int tempPower = 0; for (int i = hp.Length -1; i >= 0; i--) { tempMax = 0; tempPower = power; for (int j = 0; j >= 0; j--) { if (hp[i] <= tempPower) { tempPower = tempPower - hp[i]; if ('E' == sort[i]) { tempMax++; } } else { break; } } if (ret < tempMax) { ret = tempMax; } } return ret; } } }