using System;
 
namespace C
{
	internal class Program
	{
		private static MatrixDC[,] dc;
		
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var s = Console.ReadLine();
			var q = int.Parse(Console.ReadLine());
			var kInputs = Console.ReadLine().Split();
			var ks = new int[q];
			for (var i = 0; i < q; i++) { ks[i] = int.Parse(kInputs[i]); }
 
			var numD = 0;
			var numC = 0;
			var indexD = new int[1000000];
			var indexC = new int[1000000];
			for (var i = 0; i < n; i++)
			{
				switch (s[i])
				{
				case 'D':
					indexD[numD++] = i;
					break;
				case 'C':
					indexC[numC++] = i;
					break;
				}
			}
 
			dc = new MatrixDC[numD, numC];
			for (var i = 0; i < numD; i++)
			{
				for (var j = 0; j < numC; j++)
				{
					dc[i, j] = new MatrixDC();
					var tmp = dc[i, j].Distance = indexC[j] - indexD[i];
					if (tmp < 0) { dc[i, j].NumM = 0; }
				}
			}
 
			for (var i = 0; i < n; i++)
			{
				if (s[i] != 'M') { continue; }
 
				for (var j = 0; j < numD; j++)
				{
					if (i < indexD[j]) { continue; }
 
					for (var k = 0; k < numC; k++)
					{
						if (i > indexC[k]) { continue; }
 
						dc[j, k].NumM++;
					}
				}
			}
 
			foreach (var k in ks)
			{
				var result = 0;
				foreach (var cell in dc)
				{
					if (cell.Distance >= k) { continue; }
 
					result += cell.NumM;
				}
 
				Console.WriteLine(result);
			}
		}
	}
 
	class MatrixDC
	{
		public int Distance { get; set; }
		public int NumM { get; set; }
	}
}