Problem:


Score : 400 points

Problem Statement

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.

Constraints

S is a string consisting of digits (0, ..., 9) and ?.

1 \leq |S| \leq 10^5

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of integers satisfying the condition, modulo 10^9+7.

Sample Input 1

??2??5

Sample Output 1

768

For example, 482305, 002865, and 972665 satisfy the condition.

Sample Input 2

?44

Sample Output 2

1

Only 044 satisfies the condition.

Sample Input 3

7?4

Sample Output 3

0

We may not be able to produce an integer satisfying the condition.

Sample Input 4

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

153716888



Sample input:
??2??5


Sample output:
768

Submission status: Runtime Error

Solution code:
port sys
 
 
def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    ls = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                ls[i][int(s[-i-1])] += 1
        else:
            mult = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        ls[i][(k * mult + j) % 13] += ls[i-1][j]
            else:
                st = int(s[-i-1])
                for j in range(13):
                    ls[i][(st * mult + j) % 13] += ls[i-1][j]
        for j in range(13):
            ls[i][j] = ls[i][j] % mod
    print(ls[-1][5])
 
 
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

S = str(input())
N = len(S)
M = 13
#c = [0]*(N)
#for i in range(N):
#    c[i] = (10**i)%M
#    c[i] = pow(10,i,M)
#print(c)
#c.reverse()
#print(c)
"""
dp = [[0]*M for _ in range(N+1)]
i = int(0)
for j in range(M):
    dp[0][j] = 1
for s in S:
    if s == "?":
        for l in range(10):
            m = l * c[i] % M
            dp[i+1][(M - m) % M] += dp[i][j]
    else:
        m = int(s) * c[i] % M
        dp[i][(M - m) % M] +=dp[i][j]
    i +=1
"""
dp = [[0]*M for _ in range(N)]
c = (10**(N-1))%M
if S[0] == "?":
    for l in range(10):
        m = l * c%M
        dp[0][m] += 1
else:
    m = int(S[0]) * c%M
    dp[0][m] = 1
#S = S[1:]
i = int(1)
for s in S:
    c = (10 ** (N - 1-i)) % M
    if s == "?":
        for j in range(M):
            for l in range(10):
                m = l*c%M
                dp[i][j] += dp[i-1][(M+j-m)%M]
    else:
        for j in range(M):
            m = int(s)*c%M
            dp[i][j] = dp[i-1][(M+j-m)%M]
    i +=1

"""
dp = [[0]*M for _ in range(N)]
if S[0] == "?":
    for l in range(10):
        m = l * c[0]%M
        dp[0][m] += 1
else:
    m = int(S[0]) * c[0]%M
    dp[0][m] = 1

for i in range(1,N):
    if S[i] == "?":
        for j in range(M):
            for l in range(10):
                m = l*c[i]%M
                dp[i][j] += dp[i-1][(M+j-m)%M]
    else:
        for j in range(M):
            m = int(S[i])*c[i]%M
            dp[i][j] = dp[i-1][(M+j-m)%M]
"""
#print(dp)
print(dp[-1][5]%mod)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
flag = [-1] * (N+1)
answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i
    for j in range(i_num, N+1, i_num):
        if j == i_num:
            continue
        else:
            if flag[j] == 1:
                counter += 1
    if counter // 2 == A[i_num - 1]:
        flag[i_num] = 0
    else:
        flag[i_num] = 1
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i
    for j in range(i_num, N+1, i_num):
        if j in answer_list:
            counter += 1
    if counter // 2 == A[i_num - 1]:
        continue
    else:
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))

Submission status: Runtime Error

Solution code:
def main():
    sts=input()
    n= len(sts)
    mod = 10**9+7
    s = []
    for c in sts:
        s.append(c)

    dp = [[0 for _ in range(13)]for _ in range(n)]

    ss = s[0]
    if ss == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        ss = int(ss)
        dp[0][ss] = 1

    for i in range(1,n):
        ss = s[i]
        if ss == "?":
            for k in range(10):
                for j in range(13):
                    dp[i][(j * 10 +k) % 13] += dp[i-1][j]
        else:
            for j in range(13):
                dp[i][(j * 10 +int(ss)) % 13] += dp[i-1][j]
        for j in range(13):
            dp[j][i]= mod


    print(dp[n-1][5])

main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int, input().split()))
l.sort()
count=0
for i in range(n-2):
	for j in range(i+1,n-1):
		k=j+1
		while k<n and l[k]<l[i]+l[j]: #whileでlist indexはみ出さないように注意
			count+=1
			k+=1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int, input().split()))
l.sort()
count=0
for i in range(n-2):
	for j in range(i+1,n-1):
		k=j+1
		while k<n and l[k]<l[i]+l[j]: #whileでlist indexはみ出さないように注意
			count+=1
			k+=1

Submission status: Runtime Error

Solution code:
import sys
def input():
    return sys.stdin.readline()

def main():
    S = input()
    S = S[::-1]

    dp = [[0] * 15 for _ in range(len(S) + 5)]
    MOD = 10**9 + 7

    dp[0][0] = 1

    for i in range(len(S)):
        for j in range(13):
            if S[i] != '?':
                k = int(S[i])
                dp[i+1][(j+k*10**i)%13] += dp[i][j]
                dp[i+1][(j+k*10**i)%13] %= MOD
            else:
                for k in range(10):
                    dp[i+1][(j+k*10**i)%13] += dp[i][j]
                    dp[i+1][(j+k*10**i)%13] %= MOD


    print(dp[len(S)][5])



main()

Submission status: Runtime Error

Solution code:
mouikkai

Submission status: Runtime Error

Solution code:
s = input()
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s):
    memo[i+1] = memo[i] * 10 % 13
    if si == '?':
        for n in range(10):
            for j in range(13):
                dp[i+1][(n + j * 10) % 13] += dp[i][j]
    else:
        for j in range(13):
                dp[i+1][(int(si) + j * 10) % 13] += dp[i][j]
    for k in range(13):
      dp[i+1][k] = dp[i+1][k] % mod
print(dp[len(s)][5])

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 1000000007
s = [int(x) if x!="?" else -1 for x in input()]
dp = np.full((len(s), 13), 0, dtype="int64")
 
if s[0] == -1:
    dp[0][0:10] = 1
else:
    dp[0][int(s[0])] = 1
 
table = [ s % 13 for s in range(130)]
for index in range(1, len(s)):
    if not s[index] == -1:
        value = int(s[index])
 
        for old_amari in range(13):
            new_amari = (table[old_amari * 10] + value) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (table[old_amari * 10] + value) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
 
    dp[index] = dp[index] % MOD
 
print(dp[len(s)-1][5])

Submission status: Runtime Error

Solution code:
MOD = 10**9 + 7

def main():
    s = open(0).read()[:-1][::-1]
    n = len(s)

    prev = [0] * n
    if s[0] == '?':
        for j in range(10):
            prev[j] = 1
    else:
        prev[int(s[0])] = 1

    mod13 = [1, 10, 9, 12, 3, 4]
    for i, cur_s in enumerate(s[1:], start=1):
        next = [0] * n
        if cur_s == '?':
            for j in range(10):
                remain = j * mod13[i % 6] % 13
                for k in range(13):
                    next[(k + remain) % 13] += prev[k]
        else:
            remain = int(cur_s) * mod13[i % 6] % 13
            for k in range(13):
                next[(k + remain) % 13] += prev[k]
        prev = [cur_next % MOD for cur_next in next]

    ans = prev[5] % MOD
    print(ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 1000000007
s = (list(input()))
s = s[::-1]
dp = np.full((len(s), 13), 0)

if s[0] == "?":
    dp[0][0:10] = 1
else:
    dp[0][int(s[0])] = 1

for index in range(1, len(s)):
    if not s[index] == "?":
        value = int(s[index])
        for old_amari in range(13):
            new_amari = (value * pow(10, index) + old_amari) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (value * pow(10, index) + old_amari) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
    dp = dp % MOD

print(dp[len(s)-1][5])import numpy as np
MOD = 1000000007
s = (list(input()))
s = s[::-1]
dp = np.full((len(s), 13), 0)

if s[0] == "?":
    dp[0][0:10] = 1
else:
    dp[0][int(s[0])] = 1

for index in range(1, len(s)):
    if not s[index] == "?":
        value = int(s[index])
        for old_amari in range(13):
            new_amari = (value * pow(10, index) + old_amari) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (value * pow(10, index) + old_amari) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
    dp = dp % MOD

print(dp[len(s)-1][5])

Submission status: Runtime Error

Solution code:
S = input()
#S = "?" * 100000
S = S[::-1]
N = 13
mod = 10 ** 9 + 7
dp = [0] * 26
dp[13] = 1
digit = 1
for c in len(S):
    dp[:13] = [0] * N
    if S[c] == '?':
        for k in range(10):
            for j in range(N):
                dp[(k * digit + j) % N] += dp[j + 13]
                dp[(k * digit + j) % N] %= mod
    else:
        k = int(S[c])
        for j in range(N):
            #index = (k * digit + j) % N
            dp[(k * digit + j) % N] += dp[j + 13]
            dp[(k * digit + j) % N] %= mod

    digit *= 10
    digit %= N
    #print(dp)
    dp[13:26] = dp[:13]
    #print(dp)
print(dp[5])

Submission status: Runtime Error

Solution code:
S = input()
#S = "?" * 100000
S = S[::-1]
N = 13
mod = 10 ** 9 + 7
dp = [0] * 26
dp[13] = 1
digit = 1
for c in len(S):
    dp[:13] = [0] * N
    if S[c] == '?':
        for k in range(10):
            for j in range(N):
                dp[(k * digit + j) % N] += dp[j + 13]
                dp[(k * digit + j) % N] %= mod
    else:
        k = int(S[c])
        for j in range(N):
            #index = (k * digit + j) % N
            dp[(k * digit + j) % N] += dp[j + 13]
            dp[(k * digit + j) % N] %= mod

    digit *= 10
    digit %= N
    print(dp)
    dp[13:26] = dp[:13]
    #print(dp)
print(dp[5])

Submission status: Runtime Error

Solution code:
def main():
    MOD = 7 + 10**9
    S = list(input())
    N = len(S)
    dp = [[0]*13 for _ in range(N)]
    if S[N-1] == '?':
        for m in range(10):
            dp[0][m] = 1
    else:
        tm = int(S[N-1])%13
        dp[0][tm] = 1
    for i in range(1,N):
        if S[N-1-i] == '?':
            for j in range(13):
                for k in range(10):
                    dp[i][j] += [dp[i-1][(j-(k*10**i)%13)%13]%MOD
        else:
            m = (int(S[N-1-i])*10**i) % 13
            for l in range(13):
                dp[i][l] += dp[i-1][(l-m)%13]
    print(dp[N-1][5]%MOD)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    MOD = 7 + 10**9
    S = list(input())
    N = len(S)
    dp = [[0]*13 for _ in range(N)]
    if S[N-1] == '?':
        for m in range(10):
            dp[0][m] = 1
    else:
        tm = int(S[N-1])%13
        dp[0][tm] = 1
    for i in range(1,N):
        if S[N-1-i] == '?':
            for k in range(10):
                dp[i][j] += sum([dp[i-1][(j-(k*10**i)%13)%13]%MOD for j in range(13)])
        else:
            m = (int(S[N-1-i])*10**i) % 13
            for l in range(13):
                dp[i][l] += dp[i-1][(l-m)%13]
    print(dp[N-1][5]%MOD)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:


(AC)
s=input()
l=len(s)
mod = pow(10,9)+7

dp = [[0 for _ in range(13)] for _ in range(l+1)]
dp[0][0] = 1
keta = 1

for i in range(1,l+1):
	num = s[-i]
	if num == '?':
		for j in range(10):
			for k in range(13):
				dp[i][(j * keta + k) % 13] += dp[i-1][k] % mod
	else:
		num = int(num)
		for k in range(13):
			dp[i][(num * keta + k) % 13] += dp[i-1][k] % mod
	keta = keta*10  % 13
print(dp[l][5] % mod)

Submission status: Runtime Error

Solution code:
s=input()
l=len(s)

dp = [[0 for i in range(13)] for j in range(l+1)]
dp[0][0] = 1
#dp[i][j]=i桁目までを13で割った時、
#そのあまりがjになる場合の数

for i in range(1,l+1):
	num = s[-i]
	print('num=',num)
	if num == '?':
		for j in range(10):
			tmp = int(j) * pow(10,i-1)
			tmp %= 13
			for k in range(13):
				index = (tmp + k) % 13
				dp[i][index] += dp[i-1][k]
	else:
		tmp = int(num) * pow(10,i-1)
		tmp %= 13
		for k in range(13):
			index = (tmp + k) % 13
			dp[i][index] += dp[i-1][k]
	print(dp)
print(dp[l][5] % (pow(10,9)+7))

Submission status: Runtime Error

Solution code:
r = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
d = [1] + [0] * 12

for c in input():
    if c == '?':
        d = [sum(d[j] for j in k) % M for k in r]
    else:
        d = [d[(int(c) - k) * 9 % 13] for k in range(13)]
    #print(d)
print(d[5])

Submission status: Runtime Error

Solution code:
S = input()

MOD = 10**9+7

dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]


dp[0][0] = 1



for index in range(1, len(S) + 1):
    s = S[len(S) - index ]
    if s == '?':
	for i in range(10):
	    for pre_index in range(13):
                next_i = (i   +  pre_index * 10 ) % 13
                dp[index][next_i] += dp[index - 1][pre_index] % MOD
    else:
        i = int(s)
        for pre_index in range(13):
            next_i = (i +  pre_index * 10 ) % 13
            dp[index][next_i] += dp[index - 1][pre_index] % MOD




print(dp[len(S)][5] % MOD)

Submission status: Runtime Error

Solution code:
 = input()

MOD = 10**9+7

dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]


dp[0][0] = 1

for index in range(1, len(S) + 1):
    s = S[len(S) - index ]
    mul = (10 ** (index - 1)) % 13
    if s == '?':
        for pre_index in range(13):
            for i in range(10):
                next_i = (i * mul  +  pre_index ) % 13
                dp[index][next_i] += dp[index - 1][pre_index] 
    else:
	i = int(s)
        for pre_index in range(13):
            next_i = (i * mul +  pre_index ) % 13
            dp[index][next_i] += dp[index - 1][pre_index] 

    for i in range(13):
        dp[index][i] %= MOD



print(dp[len(S)][5])

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)

dp = [[0 for i in range(n)] for j in range(13)]


if s[0] == '?':
    for i in range(10):
        dp[i][0] = 1

else:
    dp[s][0] = 1


mod_change_table = [(i * 10)%13 for i in range(13)]


for x in range(1, len(s)):
    for y in range(13):
        if s[x] == '?':
            for j in range(10):
                dp[(mod_change_table[y]+j)%13][x] += dp[y][x-1]
        else:
            dp[(mod_change_table[y]+int(s[x]))%13][x] += dp[y][x-1]


print(dp[5][n-1])

Submission status: Runtime Error

Solution code:
import numpy as np
S = input()

MOD = 10 ** 9 + 7
mod_change_table = [(i * 10) % 13 for i in range(13)]
dp = np.array([[0] * 13] * (len(S)))
if S[0] == '?':
    dp[0][:10] = 1
else:
    dp[0][int(S[0])] = 1

for i in range(1, len(S)):
    for j in range(13):
        if S[i] == '?':
            for k in range(10):
                dp[i][(mod_change_table[j] + k) % 13] += dp[i - 1][j]
        else:
            dp[i][(mod_change_table[j] + c) % 13] += dp[i - 1][j]
    dp[i] %= MOD
print(dp[len(S) - 1][5])

Submission status: Runtime Error

Solution code:
def main():
  s = input()
  divisor = 10 ** 9 + 7
  lut = [i % 13 for i in range(133)]
  m = [i * 10 % 13 for i in range(10)]
  dp = [[0] * 13 for _ in range(len(s) + 1)]
  dp[0][0] = 1
  list10 = list(range(10))
  list13 = list(range(13))
  for i in range(len(s)):
    dpi = dp[i]
    dpi1 = dp[i + 1]
    if s[i] == '?':
      for j in list10:
        for k in list13:
          dpi1[lut[m[k] + j]] += dpi[k]
    else:
      t = int(s[i])
      for k in list13:
        dpi1[lut[m[k] + t]] += dpi[k]
    for k in range(13):
      dpi1[k] %= divisor
  print(dp[len(s)][5])
main()

Submission status: Runtime Error

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)


# def debug(var, name="hoge"):
#     print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
#     return


def main():
    MOD = 10**9 + 7
    S = list(input()[:-1])
    # print(S)
    L = len(S)
    modsum = 0
    # 余り
    memo_prev = [0 for _ in range(13)]
    memo_prev[0] = 1
    memo = [0 for _ in range(13)]

    for i in range(L):
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            for m in range(13):
                cur = (10*m+int(S[i]))%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
                    memo[cur] %= MOD
        memo_prev = memo.copy()


    print(memo[5])
    # print(memo)








if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

S = input()
MOD = 10 ** 9 + 7

dp = [0] * 13
dp[0] = 1

for s in S:
    prev = [x for x in dp]
    dp = [0] * 13
    if s == '?':
        add = range(10)
    else:
        add = [int(s)]
    for i in range(13):
        for a in add:
            dp[(10*i+a)%13] += prev[i]
    dp = [x%MOD for x in dp]
print(dp[5])

Submission status: Runtime Error

Solution code:
import numpy as np

S = input()
MOD = 10 ** 9 + 7

dp = [0] * 13
dp[0] = 1

for s in S:
    prev = [x for x in dp]
    dp = [0] * 13
    if s == '?':
        add = range(10)
    else:
        add = [int(s)]
    for i in range(13):
        for a in add:
            dp[(10*i+a)%13] += prev[i]
        dp[i] %= MOD
print(dp[5])

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()[::-1]

dp = np.zeros((len(s),13))

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

L1 = range(1, len(s))

mod = 1
for i in L1:
    if s[i] == "?":
        mod = (mod*10)%13
        mod_list = ((mod*i)%13 for i in range(10))
        for j in mod_list:
            dp[i, :] += np.roll(dp[i - 1, :], j)
        dp[i, :] %= (10**9+7)
    else:
        mod = (mod*10)%13
        dp[i, :] += np.roll(dp[i - 1, :], (mod * int(s[i]))%13)

print(int(dp[-1][5])%(10**9+7), aaa)

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()[::-1]

dp = np.zeros((len(s),13), dtype="uint64")

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

L1 = range(1, len(s))

for i in L1:
    if s[i] == "?":
        mod = pow(10, i, 13)
        mod_list = ((mod*i)%13 for i in range(10))
        for j in mod_list:
            dp[i, :] += np.roll(dp[i - 1, :], j)
        dp[i, :] %= (10**9+7)
    else:
        mod = (pow(10, i, 13)*int(s[i]))%13
        dp[i, :] += np.roll(dp[i - 1, :], mod)

print(int(dp[-1][5])%(10**9+7))

Submission status: Runtime Error

Solution code:
s = input()

DIV = 13
MOD = 10**9+7
dp = [[0 for x in range(DIV)] for y in range(len(s))]

tmp = s[-1]
if tmp == '?':
    for j in range(10):
        dp[0][j%DIV] += 1
else:
    dp[0][int(tmp)%DIV] += 1

for i in range(1, len(s)):
    tmp = s[len(s)-i-1]
    if tmp == '?':
        for j in range(10):
            for k in range(DIV):
                dp[i][(j*10**i+k)%DIV] += dp[i-1][k]
    else:
        for k in range(DIV):
            dp[i][(int(tmp)*10**i+k)%DIV] += dp[i-1][k]

    for k in range(DIV):
        dp[-1][i] %= MOD

print(dp[-1][5])

Submission status: Runtime Error

Solution code:
MOD = 10**9 + 7
memo = None


def rec(S, k, total):
    if k == len(S)//3:
        # print(total)
        fixed_total = total + 5 if k % 2 == 0 else total - 5
        memo[k][total % 13] = int((fixed_total) % 13 == 0)
        return int((fixed_total) % 13 == 0)

    if memo[k][total % 13] is not None:
        return memo[k][total % 13]

    s = S[k*3:k*3+3]
    d1 = [str(i) for i in range(10)] if s[0] == '?' else [s[0]]
    d2 = [str(i) for i in range(10)] if s[1] == '?' else [s[1]]
    d3 = [str(i) for i in range(10)] if s[2] == '?' else [s[2]]
    ret = 0

    for i1 in d1:
        for i2 in d2:
            for i3 in d3:
                num = int(i1 + i2 + i3)
                if k % 2 == 0:
                    ret += rec(S, k+1, total + num)
                else:
                    ret += rec(S, k+1, total - num)

    memo[k][total % 13] = ret
    return ret

S = input()

if len(S) % 3 == 1:
    S = '00' + S
elif len(S) % 3 == 2:
    S = '0' + S

L = (len(S) // 3) + 1
memo = [[None for i in range(14)] for j in range(L)]
print(rec(S, 0, 0) % MOD)

Submission status: Runtime Error

Solution code:
MOD = 10**9 + 7
memo = None


def rec(S, k, total):
    if k == len(S)//3:
        # print(total)
        fixed_total = total + 5 if k % 2 == 0 else total - 5
        memo[k][total % 13] = int((fixed_total) % 13 == 0)
        return int((fixed_total) % 13 == 0)

    if memo[k][total % 13] is not None:
        return memo[k][total % 13]

    s = S[k*3:k*3+3]
    d1 = [str(i) for i in range(10)] if s[0] == '?' else [s[0]]
    d2 = [str(i) for i in range(10)] if s[1] == '?' else [s[1]]
    d3 = [str(i) for i in range(10)] if s[2] == '?' else [s[2]]
    ret = 0

    for i1 in d1:
        for i2 in d2:
            for i3 in d3:
                num = int(i1 + i2 + i3)
                if k % 2 == 0:
                    ret += rec(S, k+1, total + num)
                    ret %= MOD
                else:
                    ret += rec(S, k+1, total - num)
                    ret %= MOD

    memo[k][total % 13] = ret
    return ret

S = input()

if len(S) % 3 == 1:
    S = '00' + S
elif len(S) % 3 == 2:
    S = '0' + S

L = (len(S) // 3) + 1
memo = [[None for i in range(13)] for j in range(L)]
print(rec(S, 0, 0))

Submission status: Runtime Error

Solution code:
mod=10**9+7
r=[[(j-k)*9%13 for j in range(10)] for k in range(13)]
dp=[1]+[0]*12
for c in input():
  dp = [sum(dp[j] for j in k)%mod for k in r] if c>'9' else [dp[(int(c)-k)*9%13] for k in range(13)]
print(d[5])

Submission status: Runtime Error

Solution code:
s=list(input())
n=len(s)
mod=10**9 + 7
dp=[[0]*(n) for i in range(13)]

if s[n-1]=='?':
    for i in range(10):
        dp[0][i]+=1
else:
    dp[0][s[n-1]]+=1

for i in range(n-1):
    if s[n-2-i]=='?':
        for j in range(13):
            if dp[i][j]>0:
                for k in range(10):
                    dp[i+1][(j+(10**i)*k)%13]+=1
                    dp[i+1][(j+(10**i)*k)%13]%=mod
    else:
        for j in range(13):
            if dp[i][j]>0:
                dp[i+1][j+(10**i)*s[n-2-i]]+=1
                dp[i+1][j+(10**i)*s[n-2-i]]%=mod
print(dp[n-1][5]%mod)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    MOD=10**9+7

    S = input()
    S = S[::-1]
    N = len(S)
    dp=np.zeros((N+1,13),dtype=np.int)
    dp[0,0]=1

    for i in range(N):
        if S[i]=="?":
            for s in range(10):
                A = [(s*(10**i)+j)%13 for j in range(13)]
                dp[i+1,A] += dp[i,:]
                dp[i+1,A] %= MOD
        else:
            s=int(S[i])
            A = [(s*(10**i)+j)%13 for j in range(13)]
            dp[i+1,A] += dp[i,j]
            dp[i+1,A] %= MOD

    res = dp[N,5]
    print(res)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import numba

@numba.jit  # ここだけ追加
def main():
    MOD=10**9+7

    S = input()
    S = S[::-1]
    N = len(S)
    dp=np.zeros((N+1,13),dtype=np.int32)
    dp[0,0]=1

    for i in range(N):
        if S[i]=="?":
            for s in range(10):
                for j in range(13):
                    dp[i+1][(s*(10**i)+j) % 13] += dp[i][j]
                    dp[i+1][(s*(10**i)+j) % 13] %= MOD
        else:
            s=int(S[i])
            for j in range(13):
                dp[i+1][(s*(10**i)+j) % 13] += dp[i][j]
                dp[i+1][(s*(10**i)+j) % 13] %= MOD

    res = dp[N,5]
    print(res%MOD)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
        """"ここに今までのコード"""
    MOD=10**9+7

    S = input()
    S = S[::-1]
    N = len(S)
    dp=np.zeros((N+1,13),dtype=np.int)
    dp[0,0]=1

    for i in range(N):
        if S[i]=="?":
            for s in range(10):
                for j in range(13):
                    dp[i+1][(s*(10**i)+j) % 13] += dp[i][j]
                    dp[i+1][(s*(10**i)+j) % 13] %= MOD
        else:
            s=int(S[i])
            for j in range(13):
                dp[i+1][(s*(10**i)+j) % 13] += dp[i][j]
                dp[i+1][(s*(10**i)+j) % 13] %= MOD

    res = dp[N,5]
    print(res%MOD)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
MOD=10**9+7

S = input()
S = S[::-1]
N = len(S)
dp=[[0]*N+1]*13
dp[0][0]=1

for i in range(N):
    if S[i]=="?":
        for s in range(10):
            for j in range(13):
                dp[i+1][(s*(10**i)+j) % 13] += dp[i][j]
    else:
        s=int(S[i])
        for j in range(13):
            dp[i+1][(s*(10**i)+j) % 13] += dp[i][j]
    for j in range(13):
        dp[i+1][j] %= MOD

res = dp[N][5]
print(res%MOD)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
ans=0
def bfs(st,numQ):
    global ans
    if numQ==n:
        if int(st)%13==5:
            ans=(ans+1)%1000000007
    else:
        if st[numQ]=="?":
            for i in range(10):
                bfs(st[:numQ]+str(i)+st[numQ+1:],numQ+1)
        else:
            bfs(st,numQ+1)
bfs(s,0)
print(ans)

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7

s = str(input())
sl = list(s)
si = list(map(int,s))

cur = [0] * 13

if s[0] != "?":
    cur[si[0]] = 1
else:
    for j in range(10):
        cur[j] = 1

for i in range(1,len(s)):
    pre = cur[:]
    cur = [0] * 13
    if s[i] != "?":
        for j in range(13):
            q = (j * 10 + si[i]) % 13
            cur[q] += pre[j] % MOD
    else:
        for j in range(13):
            for k in range(10):
                p = (j * 10 + k) % 13
                cur[p] += pre[j] % MOD

print(cur[5] % MOD)

Submission status: Runtime Error

Solution code:
#D問題
mod = 1000000007
S = str(input())


dp = [[0 for i in range(13)] for j in range(N+1)]
dp[0][0] = 1
for i,s in enumerate(S):
    if s == "?":
        for j in range(10):
            for k in range(13):
                ind = (10*k+j)%13
                dp[i+1][ind] += dp[i][k]
    else:
        j = int(s)
        for k in range(13):
            ind = (10*k+j)%13
            dp[i+1][ind] += dp[i][k]
            
    for k in range(13):
        dp[i+1][k]%=mod
            
print(dp[N][5]%mod)

Submission status: Runtime Error

Solution code:
#D問題
mod = 1000000007
S = str(input())
N = len(S)

dp = [[0 for i in range(13)] for j in range(N+1)]
dp[0][0] = 1
for i in range(N):
    if S[i] == "?":
        for j in range(10):
            for k in range(13):
                ind = (10*k+j)%13
                dp[i+1][ind] += dp[i][k]
    else:
        s = int(S[i])
        for k in range(13):
            ind = (10*k+j)%13
            dp[i+1][ind] += dp[i][k]
            
print(dp[N][5]%mod)

Submission status: Runtime Error

Solution code:
#D問題
mod = 1000000007
S = str(input())
N = len(S)

dp = [[0 for i in range(13)] for j in range(N+1)]
dp[0][0] = 1
for i in range(N):
    if S[i] == "?":
        for j in range(10):
            for k in range(13):
                mod13 = (10*k+j)%13
                dp[i+1][mod13] += dp[i][k]
    else:
        s = int(S[i])
        for k in range(13):
            mod13 = (10*k+j)%13
            dp[i+1][mod13] += dp[i][k]
            
print(dp[N][5]%mod)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

S = input()

table = [[0] * 13 for i in range(len(S))]

if S[len(S)-1] == '?':
    for i in range(10):
        table[0][i] = 1
else:
    table[0][int(S[len(S)-1])] = 1

for i in range(len(S)-1):    
    if S[len(S)-i-2] =='?':
        for j in range(10):
            mod = (10**(i+1)) * j % 13
            for k in range(13):
                table[i+1][(k+mod) % 13] += table[i][k] % (10**9 + 7)
    else:
        num = int(S[len(S)-i-2])
        mod = (10**(i+1)) * num % 13
        for k in range(13):
            table[i+1][(k+mod) % 13] += table[i][k] % (10**9 + 7)
            
print(table[len(S)-1][5]%(10**9+7))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

table = [[0] * 13 for i in range(len(S))]

if S[len(S)-1] == '?':
    for i in range(10):
        table[0][i] = 1
else:
    table[0][int(S[len(S)-1])] = 1

for i in range(len(S)-1):    
    if S[len(S)-i-2] =='?':
        for j in range(10):
            mod = (10**(i+1)) * j % 13
            for k in range(13):
                table[i+1][(k+mod) % 13] += table[i][k] % (10**9 + 7)
    else:
        num = int(S[len(S)-i-2])
        mod = (10**(i+1)) * num % 13
        for k in range(13):
            table[i+1][(k+mod) % 13] += table[i][k] % (10**9 + 7)
            
print(table[len(S)-1][5]%(10**9+7))S = input()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

S = input()

table = [[0] * 13 for i in range(len(S))]

if S[len(S)-1] == '?':
    for i in range(10):
        table[0][i] = 1
else:
    table[0][int(S[len(S)-1])] = 1

for i in range(len(S)-1):    
    if S[len(S)-i-2] =='?':
        for j in range(10):
            mod = (10**(i+1)) * j % 13
            for k in range(13):
                table[i+1][(k+mod) % 13] += table[i][k] #% (10**9 + 7)
    else:
        num = int(S[len(S)-i-2])
        mod = (10**(i+1)) * num % 13
        for k in range(13):
            table[i+1][(k+mod) % 13] += table[i][k] #% (10**9 + 7)
            
print(table[len(S)-1][5]%(10**9+7))

Submission status: Runtime Error

Solution code:
S = list(input())
N = len(S)
dp = [[0] * 13 for _ in range(N+1)]
MOD = 10**9 + 7
s = S[0]
if s=='?':
    for k in range(10):
        dp[0][k] = 1
else:
    dp[0][s] = 1
 

for i in range(1,N):
    s = S[i]
    for j in range(13):
        if s=='?':
            for k in range(10):
                tmp = (j*10 + k)%13
                dp[i][tmp] += dp[i-1][j]
                dp[i][tmp] %= MOD
        else:
            tmp = (j*10 + int(s))%13
            dp[i][tmp] += dp[i-1][j]
            dp[i][tmp] %= MOD
            
print(dp[N-1][5])