Buggy python submission (verdict: Runtime Error):
def solve(N, S, k):
    k -= 1

    # i-th of these counts the thing in [ max(0, i-k), i ).
    D_counts  = [0]
    M_counts  = [0]
    DM_counts = [0]

    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)
    for i in range(k, N):
        if S[i-k] == 'D':
            D -= 1
            DM -= M
        elif S[i-k] == 'M':
            M -= 1

        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
            
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)

    ans = 0
    for i, c in enumerate(S):
        if c == 'C':
            ans += DM_counts[i]
    return ans

def main():
    N = int(input())
    S = input()
    Q = int(input())
    ks = list(map(int, input().split()))
    for k in ks:
        print(solve(N, S, k))

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Fixed submission:
import numpy as np
from numba import njit

N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def func(ch):
    if ch == 'D':
        return 1
    if ch == 'M':
        return 2
    if ch == 'C':
        return 3
    return 0
    
S_arr = np.array([func(ch) for ch in S], dtype = np.int32)

@njit("i8(i8, i4[:], i8)", cache = True)
def solve(N, S_arr, k):
    ans = 0
    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM
    for i in range(k, N):
        if S_arr[i-k] == 1:
            D -= 1
            DM -= M
        elif S_arr[i-k] == 2:
            M -= 1

        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM

    return ans

for k in ks:
    print(solve(N, S_arr, k))

Buggy python submission (verdict: Time Limit Exceeded):
from numba import njit

N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

@njit
def solve(N, S, k):
    k -= 1

    # i-th of these counts the thing in [ max(0, i-k), i ).
    D_counts  = [0]
    M_counts  = [0]
    DM_counts = [0]

    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)
    for i in range(k, N):
        if S[i-k] == 'D':
            D -= 1
            DM -= M
        elif S[i-k] == 'M':
            M -= 1

        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
            
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)

    ans = 0
    for i, c in enumerate(S):
        if c == 'C':
            ans += DM_counts[i]
    return ans

for k in ks:
    print(solve(N, S, k))
    

Fixed submission:
import numpy as np
from numba import njit

N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def func(ch):
    if ch == 'D':
        return 1
    if ch == 'M':
        return 2
    if ch == 'C':
        return 3
    return 0
    
S_arr = np.array([func(ch) for ch in S], dtype = np.int32)

@njit("i8(i8, i4[:], i8)", cache = True)
def solve(N, S_arr, k):
    ans = 0
    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM
    for i in range(k, N):
        if S_arr[i-k] == 1:
            D -= 1
            DM -= M
        elif S_arr[i-k] == 2:
            M -= 1

        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM

    return ans

for k in ks:
    print(solve(N, S_arr, k))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def solve(N, S, k):
    k -= 1
    
    # i-th of these counts the thing in [ max(0, i-k), i ).
    D_counts  = [0]
    M_counts  = [0]
    DM_counts = [0]

    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)
    for i in range(k, N):
        if S[i-k] == 'D':
            D -= 1
            DM -= M
        elif S[i-k] == 'M':
            M -= 1

        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
            
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)

    ans = 0
    for i, c in enumerate(S):
        if c == 'C':
            ans += DM_counts[i]
    return ans

for k in ks:
    print(solve(N, S, k))
    

Fixed submission:
import numpy as np
from numba import njit

N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def func(ch):
    if ch == 'D':
        return 1
    if ch == 'M':
        return 2
    if ch == 'C':
        return 3
    return 0
    
S_arr = np.array([func(ch) for ch in S], dtype = np.int32)

@njit("i8(i8, i4[:], i8)", cache = True)
def solve(N, S_arr, k):
    ans = 0
    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM
    for i in range(k, N):
        if S_arr[i-k] == 1:
            D -= 1
            DM -= M
        elif S_arr[i-k] == 2:
            M -= 1

        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM

    return ans

for k in ks:
    print(solve(N, S_arr, k))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def solve(N, S, k):
    k -= 1
    
    # i-th of these counts the thing in [ max(0, i-k), i ).
    D_counts  = [0]
    M_counts  = [0]
    DM_counts = [0]

    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)
    for i in range(k, N):
        if S[i-k] == 'D':
            D -= 1
            DM -= M
        elif S[i-k] == 'M':
            M -= 1

        if S[i] == 'D':
            D += 1
        elif S[i] == 'M':
            DM += D
            M += 1
            
        D_counts.append(D)
        M_counts.append(M)
        DM_counts.append(DM)

    ans = 0
    for i, c in enumerate(S):
        if c == 'C':
            ans += DM_counts[i]
    return ans

for k in ks:
    print(solve(N, S, k))
    

Fixed submission:
import numpy as np
from numba import njit

N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def func(ch):
    if ch == 'D':
        return 1
    if ch == 'M':
        return 2
    if ch == 'C':
        return 3
    return 0
    
S_arr = np.array([func(ch) for ch in S], dtype = np.int32)

@njit("i8(i8, i4[:], i8)", cache = True)
def solve(N, S_arr, k):
    ans = 0
    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM
    for i in range(k, N):
        if S_arr[i-k] == 1:
            D -= 1
            DM -= M
        elif S_arr[i-k] == 2:
            M -= 1

        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM

    return ans

for k in ks:
    print(solve(N, S_arr, k))