Problem: Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.  Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.  Since the answer can be enormous, print the count modulo 10^9+7.

Submission attempts (in order):
S = "?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???"
INF = 10 ** 9 + 7
mod = [1,10,9,12,3,4]
dp = [[0 for _ in range(13)] for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            for y in range(13):
                dp[_][(x * mod[_ % 6] + y) % 13] += dp[_ - 1][y] % INF
    else:
        for y in range(13):
            dp[_][(int(S_li[_]) * mod[_ % 6] + y) % 13] += dp[_ - 1][y] % INF
print(dp[-1][5] % INF)

import numpy as np
S = input()
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 * (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 * (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)

import numpy as np
S = "3900"
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 ** (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 ** (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)
print(dp[-1])

import numpy as np
S = input()
INF = 10 ** 9 + 7
dp = [np.array([0 for _ in range(13)]) for l in range(len(S))]
S_li = [_ for _ in S]
S_li = S_li[::-1]
if S_li[0] == '?':
    dp[0][0:10] = [1,1,1,1,1,1,1,1,1,1]
else:
    dp[0][int(S_li[0])] = 1
for _ in range(1,len(S)):
    if S_li[_] == '?':
        for x in range(10):
            mod = (x * (10 ** (_ % 6))) % 13
            add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
            dp[_] += np.array(add)
    else:
        s = int(S_li[_])
        mod = (s * (10 ** (_ % 6))) % 13
        add = list(dp[_ - 1][(13 - mod):13]) + list(dp[_ - 1][0:(13 - mod)])
        dp[_] += np.array(add)
print(dp[-1][5] % INF)
print(dp[-1])

MOD = 1000000007;
 
s = [int(x) if x!="?" else -1 for x in input()]
#print(s)
n=len(s)
 
r=[0]*13
 
c=s[0]
if (c!=-1):
    r[c]=1
else:
    for i in range(10):r[i]=1
for i in range(1,n):
    dp=[0]*26
    for j in range(13):dp[j*10%13]+=(r[j]%MOD)
    dp[13:26]=dp[0:13]
    c=s[i]
    r=[0]*13
    if (c==-1):
        w=sum(dp[4:14])
        for j in range(13):
            r[j]+=w
            w=w+dp[j+1]-dp[4+j]
    else:
        for j in range(13):
            r[j]+=dp[13-c+j]
print (r[5]%MOD)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted