program atcoder
    implicit none
    integer(8) :: N,Q,k,i,j,ans,D,M,DM,qq
    integer(8),allocatable,dimension(:) :: a
    character(1000007) S
    read(*,*)N,S,Q
    allocate( a(Q) )
    read(*,*)(a(i),i=1,Q)
    do qq = 1,Q
        k = a(qq)
        ans = 0
        D = 0
        M = 0
        DM = 0
        do i = 1,k
            if(S(i:i)=='D')then
                D = D+1
            else if(S(i:i)=='M')then
                M = M+1
                DM = DM + D
            else if(S(i:i)=='C')then
                ans = ans + DM
            endif
        enddo
        do i = k+1,N
            if(S(i-K:i-K)=='D')then
                D = D-1
                DM = DM-M
            else if(S(i-K:i-K)=='M')then
                M = M-1
            end if
            if(S(i:i)=='D')then
                D = D + 1
            else if(S(i:i)=='M')then
                M = M+1
                DM = DM+D
            else if(S(i:i)=='C')then
                ans = ans + DM
            endif
        enddo
        write(*,'(I0)')ans
    end do
end program atcoder