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:
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input())):
    r = range(0, p * 10, p) if c == '?' else (p * int(c),)
    a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])

Submission status: Runtime Error

Solution code:
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = [x % 13 for x in range(0, p * 10, p)] if c == '?' else (p * int(c),)
    a = [sum(a[(i - j, i - j + 13)[i < j]] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])

Submission status: Runtime Error

Solution code:
import numpy as np

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

dp_ = [1] + [0] * 13
prev_dp = np.array(dp_)

for i in range(len(S)):
    new_dp = [0] * 13
    if S[i] == '?':
        for j in range(13):
            for k in range(10):
                new_dp[(j * 10 + k) % 13] += prev_dp[j] % MOD
    else:
        for j in range(13):
            new_dp[(j * 10 + k) % 13] += prev_dp[j] % MOD
    prev_dp = new_dp
    
print(new_dp[5] % MOD)

Submission status: Runtime Error

Solution code:
import numpy as np

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

dp_ = [1] + [0] * 13
prev_dp = np.array(dp)

for i in range(len(S)-1):
    new_dp = [0] * 13
    if S[i] == '?':
        for j in range(13):
            for k in range(10):
                new_dp[(j * 10 + k) % 13] += prev_dp[j] % MOD
    else:
        for j in range(13):
            new_dp[(j * 10 + k) % 13] += prev_dp[j] % MOD
    prev_dp = new_dp
    
print(new_dp[5])

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
dp = [[0 for i in range(13)] for j in range(N+1)]

MOD = 10**9 + 7
dp[0][0] = 1

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

print(dp[N][5])

Submission status: Runtime Error

Solution code:
s = list(input())

dp = [[0 for _ in range(13)] for _ in range(len(s))]
multi = 1
for i in range(10):
    if s[0] == '?':
        dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
for i in range(1,len(s)):
    if s[i] == '?':
        for j in range(13):
            if dp[i-1][j] != 0:
                for k in range(10):
                    rest = (j*10+k)%13
                    dp[i][rest] += dp[i-1][j]
    else:
        for j in range(13):
            if dp[i-1][j] != 0:
                rest = (j*10+int(s[i]))%13
                dp[i][rest] += dp[i-1][j]
print(dp[i][5]%(10**9+7))

Submission status: Runtime Error

Solution code:
s = list(input())

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

for i in range(10):
    if s[0] == '?':
        dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
for i in range(1,len(s)):
    if s[i] == '?':
        for j in range(13):
            for k in range(10):
                rest = (j*10+k)%13
                dp[i][rest] += dp[i-1][j]
    else:
        for j in range(13):
            rest = (j*10+int(s[i]))%13
            dp[i][rest] += dp[i-1][j]
print(dp[i][5]%(10**9+7))

Submission status: Runtime Error

Solution code:
INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                # dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            # dp[i + 1][(mul * k + j) % 13] %= INF
    mul *= 10

print(dp[len(S)][5] %= INF)

Submission status: Runtime Error

Solution code:
def main():
  s = ''.join(reversed(input()))
  multiplier = 1
  divisor = 10 ** 9 + 7
  list10 = list(range(10))
  list13 = list(range(13))
  p = [0 for i in list13]
  np = [0 for i in list13]
  rt = [i % 13 for i in range(100)]
  if s[0] != '?':
    p[int(s[0])] = 1
  else:
    for j in range(10):
      p[j] = 1
  for i in range(1, len(s)):
    multiplier = (10 * multiplier) % 13
    if s[i] != '?':
      r = int(s[i]) * multiplier
      for j in list13:
        np[(j + r) % 13] = p[j]
    else:
      for j in range(10):
        r = multiplier * j % 13
        for k in list13:
          np[re[k + r]] += p[k]
    for j in list13:
      p[j] = np[j] % divisor
      np[j] = 0
  print(p[5] % divisor)
main()

Submission status: Runtime Error

Solution code:
s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
np = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  for j in range(13):
    np[j] = 0
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print p[5] % divisor

Submission status: Runtime Error

Solution code:
#include<iostream>

int main(){
  std::string s;
  std::cin >> s;
  long long mod = 1000000007;

  int T[6][10];
  int r=1;
  for(int i=0; i<6; ++i){
    for(int j=0; j<10; ++j){
      T[i][j] = (j*r)%13;
    }
    r*=10;
  }

  long long _dp1[13], _dp2[13];
  long long *dp = _dp1, *dp_new = _dp2, *dp_swap;
  dp[0]=1;
  for(int i=1; i<13; ++i) dp[i]=0;

  int k = s.size()-1;
  for(int i=0; i<s.size(); ++i, --k){
    for(int j=0; j<13; ++j) dp_new[j]=0;

    if(s[i]=='?'){
      for(int r=0; r<10; ++r){
        int m = T[k%6][r];
        for(int n=0; n<13; ++n) dp_new[(n+m)%13] += dp[n];
      }
    }else{
      int m = T[k%6][(int)(s[i]-'0')];
      for(int n=0; n<13; ++n) dp_new[(n+m)%13] = dp[n];
    }

    dp_swap = dp_new; dp_new = dp; dp = dp_swap;
    for(int j=0; j<13; ++j) dp[j]%=mod;
  }

  std::cout << dp[5] << std::endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
S = input()

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

print(dp[-1][5] % MOD)

Submission status: Runtime Error

Solution code:
s = input().strip()

DIV = 10**9 + 7
new = list(range(13))
old = None

if s[-1] == '?':
    old = [int(t < 10) for t in range(13)]
else:
    old = [int(t == int(c)) for t in range(13)]

digit = 10
for i, c in enumerate(reversed(s[:-1])):
    for j in range(13):
        new[j] = 0
    if c == '?':
        for m in range(10):
            for mod, cnt in enumerate(old):
                shifted = (mod + m * digit) % 13
                new[shifted] += cnt
    else:
        c = int(c)
        for mod, cnt in enumerate(old):
            shifted = (mod + c * digit) % 13
            new[shifted] += cnt
    for j in range(13):
        new[j] %= DIV
    new, old = old, new
    digit = (digit * 10) % 13

print(old[5])

Submission status: Runtime Error

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

S = input()
amari = [1, 10, 9, 12, 3, 4]
kurai = 0
hatena = []
base = 0
for i in range(len(S)):
	#print(S[len(S) - 1 - i])
	if S[len(S) - 1 - i] == '?':
		hatena.append(kurai)
	else:
		base += (int(S[len(S) - 1 - i])*amari[i % 6])
		base = base % 13
	kurai += 1

#print(base, hatena)
count13 = [0]*13
count13[base]+=1
for kurai in hatena:
	countnow = [0]*13
	for num in range(10):
		x = num * amari[kurai % 6]
		for i in range(13):
			y = (i + x) % 13
			countnow[y] += count13[i]
	for i in range(13):
		countnow[i] = countnow[i] % 1000000007
	count13 = copy.deepcopy(countnow)

print(count13[5])

Submission status: Runtime Error

Solution code:
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

S = input()
amari = [1, 10, 9, 12, 3, 4]
kurai = 0
hatena = []
base = 0
for i in range(len(S)):
	#print(S[len(S) - 1 - i])
	if S[len(S) - 1 - i] == '?':
		hatena.append(kurai)
	else:
		base += (int(S[len(S) - 1 - i])*amari[i % 6])
		base = base % 13
	kurai += 1

#print(base, hatena)
count13 = [0]*13
count13[base]+=1
for kurai in hatena:
	countnow = [0]*13
	for num in range(10):
		x = num * amari[kurai % 6]
		for i in range(13):
			y = (i + x) % 13
			countnow[y] += count13[i]
	for i in range(13):
		countnow[i] = countnow[i] % 1000000007
	count13 = copy.deepcopy(countnow)

print(count13[5])

Submission status: Runtime Error

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13
l=len(t)
for n,c in enumerate(t):
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mulmod+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(i*mulmod+int(c))%13
            e[k]+=d[int(c)]
            e[k]%=mod
    d=e
    mul*=10
    mulmod=mul%13
print(d[5])

Submission status: Runtime Error

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13
l=len(t)
for n,c in enumerate(t):
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mulmod+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(i*mulmod+int(c)%13
            e[k]+=d[int(c)]
            e[k]%=mod
    d=e
    mul*=10
    mulmod=mul%13
print(d[5])

Submission status: Runtime Error

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13
l=len(t)
for n,c in enumerate(t):
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mulmod+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(i*mulmod+int(c)%13
            e[k]+=d[j]
            e[k]%=mod
    d=e
    mul*=10
    mulmod=mul%13
print(d[5])

Submission status: Runtime Error

Solution code:
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=list(input())
t.reverse()
zero=[0]*13
for c in t:
    e=zero[:]

    for i in (range(10) if c=="?" else[int(c)]):
        for j in range(13):
            #e[(i*mul+j)%13]+=d[j]
            k=(i*mul+j)%13
            e[k]+=d[j]
            e[k]%=1000000007
    d,e=e.d
    mul*=10
    #mulmod=mul%13
print(d[5])

Submission status: Runtime Error

Solution code:
INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for j in range(13):
            for k in range(10):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= INF
    mul *= 10

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

Submission status: Runtime Error

Solution code:
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = (0, p * 10) if c == '?' else (int(c), int(c) + 1)
    a = [sum(a[(i - j) % 13] for j in range(*r, p)) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])

Submission status: Runtime Error

Solution code:
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = range(0, p * 10, p) if c == '?' else (p * int(c),)
    if c != '?':
      a = [a[i - p * int(c)] for i in range(13)]
    else:
      a = [sum(a[(i - j) % 13] for j in range(0, p * 10, p)) % M for i in range(13)] 
    p = p * 10 % 13
print(a[5])

Submission status: Runtime Error

Solution code:
s=input()
mod=10**9+7
ans=0
dp = [[0]*15 for i in range(15)]
dp[0][0]=1
for i in range(len(s)):
    keta = len(s)-i-1
    if s[i]=='?':
        for num in range(10):
            amari = num*10**keta
            amari%=13
            for j in range(13):
                dp[i+1][(j+amari)%13]+=dp[i][j]
    else:
        amari = int(s[i])*10**keta
        amari%=13
        for j in range(13):
            dp[i+1][(j+amari)%13]+=dp[i][j]

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict
S = input()

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

c = {}
for i in range(len(S)):
    if S[len(S) - i - 1] != "?":
        continue
    tc = defaultdict(lambda: 0)
    for j in range(0, 10):
        t = j * 10 ** i
        tc[t % 13] += 1
    c[i] = tc

dp = [{SS: 1}]
for k, v in c.items():
    tdp = defaultdict(lambda: 0)
    for r, c in v.items():
        for _r, _v in dp[-1].items():
            tdp[(_r + r) % 13] += _v * c
    dp.append(tdp)

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

Submission status: Runtime Error

Solution code:
d=[0]*13
d[0]=1
mul=1
t=reversed(input())
for c in reversed(input()):
    e=[0]*13
    """
    if c=="?":
        for i in range(10):
            for j in range(13):
                e[(i*mul+j)%13]+=d[j]
                e[(i*mul+j)%13]%=(10**9+7)
    else:
        for j in range(13):
            e[(int(c)*mul+j)%13]+=d[j]
            e[(int(c)*mul+j)%13]%=(10**9+7)
    """
    for i in (range(10) if c=="?" else[int(c)]):
        for j in range(13):
            e[(i*mul+j)%13]+=d[j]
            
    d=[e%(10**9+7)for e in e]
    mul*=10
print(d[5])

Submission status: Runtime Error

Solution code:
d=[0]*13
d[0]=1
mul=1
for c in reversed(input()):
    e=[0]*13
    """
    if c=="?":
        for i in range(10):
            for j in range(13):
                e[(i*mul+j)%13]+=d[j]
                e[(i*mul+j)%13]%=(10**9+7)
    else:
        for j in range(13):
            e[(int(c)*mul+j)%13]+=d[j]
            e[(int(c)*mul+j)%13]%=(10**9+7)
    """
    for j in (range(10) if c=="?" else[int(c)]):
        for i in range(13):
            e[(int(c)*mul+j)%13]+=d[j]
            e[(int(c)*mul+j)%13]%=(10**9+7)    
    d=e[:]
    mul*=10
print(d[5])

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def conv(c):
    if c == "?":
        yield from [str(i) for i in range(0, 10)]
    else:
        yield from [c]


def calc(s, res):
    if not s:
        yield res
    else:
        c = s[0]
        for j in conv(c):
            yield from calc(s[1:], res + j)


def main():
    s = input().strip()
    cnt = 0
    for i in calc(s, ""):
        if int(i) % 13 == 5:
            cnt += 1
    print(cnt % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

d=[0]*13
d[0]=1
mul=1
for c in reversed(input()):
    e=[0]*13
    if c=="?":
        for i in range(10):
            for j in range(13):
                e[(i*mul+j)%13]+=d[j]
                e[(i*mul+j)%13]%=(10**9+7)
    else:
        for j in range(13):
            e[(i*mul+j)%13]+=d[j]
            e[(i*mul+j)%13]%=(10**9+7)
    d=e
    mul*=10
print(d[5])

Submission status: Runtime Error

Solution code:
S = input()
Qmarks = S.count("?")

could = 0

for i in range(int( "9"*Qmarks )+1):
    x = S
    num_for_replace = "0"*( Qmarks - len(str(i)) ) + str(i)

    for n in num_for_replace:
        x = x.replace("?", n, 1)

    if int(x) % 13 == 5:
        could += 1

print(could)

#time over

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# import numpy as np

S = input().rstrip()

MOD = 10 ** 9 + 7
n = len(S)

# dp = np.zeros((100005, 13), dtype=np.uint64)

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

dp[0][0] = 1

for i in range(n):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
    
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) %13] += dp[i][ki]
            
    for j in range(13):
        dp[i+1][j] %= MOD
        
    res = dp[n][5]
    
print(res)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# import numpy as np

S = input().rstrip()

MOD = 10 ** 9 + 7
n = len(S)

# dp = np.zeros((100005, 13), dtype=np.uint64)

dp = [[0]*100005]*13

dp[0][0] = 1

for i in range(n):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
    
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) %13] += dp[i][ki]
            
    for j in range(13):
        dp[i+1][j] %= MOD
        
    res = dp[n][5]
    
print(res)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# import numpy as np

S = input().rstrip()

MOD = 10 ** 9 + 7
n = len(S)

# dp = np.zeros((100005, 13), dtype=np.uint64)

list1 = [[0]*100005]*13

dp[0][0] = 1

for i in range(n):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
    
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) %13] += dp[i][ki]
            
    for j in range(13):
        dp[i+1][j] %= MOD
        
    res = dp[n][5]
    
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
S = input()
  
dp = np.zeros((100005, 13), dtype=np.uint64)

dp[0][0] = 1

for i in range(n):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
    # print(c)
    
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) %13] += dp[i][ki]
            
    for j in range(13):
        dp[i+1][j] %= MOD
        
    res = dp[n][5]
    
print(res)

Submission status: Runtime Error

Solution code:
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    N = len(S)
    dp = [[0 for _ in range(13)] for _ in range(len(S))]
    if S[N-1] != '?':
        dp[0][int(S[N-1])] = 1
    else:
        dp[0] = [1,1,1,1,1,1,1,1,1,1,0,0,0]
    for i in range(1, len(S)):
        ii = len(S) - i - 1
        for j in range(13):
            if S[ii] == '?':
                for ll in range(10):
                    kk = (ll * 10 ** i) % 13
                    dp[i][j] += dp[i-1][(13 + j - kk)%13]
                    dp[i][j] %= MOD
            else:
                x = int(S[ii])
                m = x * 10 ** i % 13
                dp[i][j] = dp[i-1][(13+k-m)%13]
                dp[i][j] %= MOD
    print(dp[len(S)-1][5])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()

mod = 10**9+7
N = len(S)
ans = 0

memo = {}
for i in range(1000):
    s = str(i).zfill(3)
    memo[s] = [0 for _ in [0]*13]
    memo[s][i%13] = 1

def rep_Q_count(s):
    memo[s] = [0 for _ in [0]*13]
    for q in range(10):
        s2 = s.replace("?",str(q),1)
        for i,n in enumerate(memo[s2]):
            memo[s][i] += n

for i in range(100):
    s = str(i).zfill(2)
    rep_Q_count(s+"?")
    rep_Q_count(s[0]+"?"+s[1])
    rep_Q_count("?"+s)
for i in range(10):
    s = str(i)
    rep_Q_count(s+"??")
    rep_Q_count("?"+s+"?")
    rep_Q_count("??"+s)
rep_Q_count("???")

s0 = S[N-3:N]
dp = memo[s0][:]
for i in range(1,(N-1)//3+1):
    s = S[max(0,N-(i+1)*3):N-i*3].zfill(3)
    j = i%2
    tmp = memo[s]
    dp2 = [0]*13
    for k,n in enumerate(tmp):
        for l,m in enumerate(dp):
            dp2[(l+k*((-1)**j))%13] += n*m
    dp = dp2
    for i in range(13):
        dp[i] %= mod
print(dp[5])

Submission status: Runtime Error

Solution code:
S = input()

mod = 10**9+7
N = len(S)
ans = 0

memo = {}
for i in range(1000):
    s = str(i).zfill(3)
    memo[s] = [0 for _ in [0]*13]
    memo[s][i%13] = 1

def rep_Q_count(s):
    memo[s] = [0 for _ in [0]*13]
    for q in range(10):
        s2 = s.replace("?",str(q),1)
        for i,n in enumerate(memo[s2]):
            memo[s][i] += n

for i in range(100):
    s = str(i).zfill(2)
    rep_Q_count(s+"?")
    rep_Q_count(s[0]+"?"+s[1])
    rep_Q_count("?"+s)
for i in range(10):
    s = str(i)
    rep_Q_count(s+"??")
    rep_Q_count("?"+s+"?")
    rep_Q_count("??"+s)
rep_Q_count("???")

s0 = S[N-3:N]
dp = memo[s0][:]
for i in range(1,(N-1)//3+1):
    s = S[max(0,N-(i+1)*3):N-i*3]
    j = i%2
    tmp = memo[s]
    dp2 = [0]*13
    for k,n in enumerate(tmp):
        for l,m in enumerate(dp):
            dp2[(l+k*((-1)**j))%13] += n*m
    dp = dp2
    for i in range(13):
        dp[i] %= mod
print(dp[5])

Submission status: Runtime Error

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math
import time

#t1=time.time()
#input = sys.stdin.readline
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


S = input().strip()
# S = str('?'*(10**5))
N = 13

dp =[0]*N
dp[0]=1

mul = 1
reversed_S = S[::-1]
for c in reversed_S:
    nextDP = [0]*N
    if c == '?':
        # print('test')
        # print(mul)
        for k in range(10):
            for j in range(N):
                nextDP[(mul*k+j)%N] += dp[j]
                nextDP[(mul*k+j)%N] %= MOD
    else:
        k = int(c)
        for j in range(N):
            nextDP[(mul*k+j)%N] += dp[j]
            nextDP[(mul*k+j)%N] %= MOD

    mul *= 10
    mul %= N
    dp = nextDP[:]
print(dp[5])
#print(time.time()-t1)

Submission status: Runtime Error

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math
import time

t1=time.time()
input = sys.stdin.readline
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


S = str(input())
# S = str('?'*(10**5))
N = 13

dp =[0]*N
dp[0]=1

mul = 1
reversed_S = reversed(S)
for c in reversed_S:
    nextDP = [0]*N
    if c == '?':
        # print('test')
        # print(mul)
        for k in range(10):
            for j in range(N):
                nextDP[(mul*k+j)%N] += dp[j]
                nextDP[(mul*k+j)%N] %= MOD
    else:
        k = int(c)
        for j in range(N):
            nextDP[(mul*k+j)%N] += dp[j]
            nextDP[(mul*k+j)%N] %= MOD

    mul *= 10
    mul %= N
    dp = nextDP[:]
print(dp[5])
#print(time.time()-t1)

Submission status: Runtime Error

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math
import time

t1=time.time()
input = sys.stdin.readline
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


#S = str(input())
S = str('?'*(10**5))
N = 13

dp =[0]*N
dp[0]=1

mul = 1
reversed_S = reversed(S)
for c in reversed_S:
    nextDP = [0]*N
    if c == '?':
        # print('test')
        # print(mul)
        for k in range(10):
            for j in range(N):
                nextDP[(mul*k+j)%N] += dp[j]
                nextDP[(mul*k+j)%N] %= MOD
    else:
        k = int(c)
        for j in range(N):
            nextDP[(mul*k+j)%N] += dp[j]
            nextDP[(mul*k+j)%N] %= MOD

    mul *= 10
    mul %= N
    dp = nextDP[:]
print(dp[5])
#print(time.time()-t1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = int(1e9 + 7)
N = int(1e5)
M = 13

s = input()
dp = np.zeros(N,M)
dp[0,0] = 1
m = list(range(M))
t = list(range(10))

for i in range(len(s)):
    for j in m:
        for k in t:
            if s[i] == "?" or s[i] == str(k):
                dp[i+1,(j*10 +k) % M] += dp[i,j]
                dp[i+1,(j*10 +k) % M] %= MOD


print(dp[len(s),5])

Submission status: Runtime Error

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()[::-1]
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

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

print(dp[N][5])

Submission status: Runtime Error

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

MOD = 10**9 + 7
def main():
    S = input()
    N = len(S)-1

    if S[0] == '?':
        dp = [1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        dp[int(S[i])] = 1

    for i in range(1,N):
        dppre = dp
        dp = [0] * 13

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

    print(dp[5])
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

MOD = 10**9 + 7
def main():
    S = input()
    N = len(S)-1

    if S[0] == '?':
            dp = [1,1,1,1,1,1,1,1,1,1,0,0,0]
        else:
            dp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
            dp[int(S[i])] = 1

    for i in range(1,N):
        dppre = dp
        dp = [0] * 13

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

    print(dp[5])
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import copy
def getAns(nums):
    now = 0
    for i in nums:
        if i == '?':
            ans = 0
            for i2 in range(10):
                newnums = copy.deepcopy(nums)
                numslist = list(newnums)
                numslist[now] = str(i2)
                ans = ans + getAns(''.join(numslist))
            return ans
        now = now + 1
    if int(nums)%13 == 5:
        return 1
    else:
        return 0


nums = input()
noansw = ['8','4','2','6']
print(str(getAns(nums)%(10**9 + 7)))

Submission status: Runtime Error

Solution code:
d=[1]+[0]*12
for c in input():
	e=[0]*13
	for k in([c],range(10))[c>'9']:
		for j in range(13):t=(j*10+k)%13;e[t]+=d[j];e[t]%=10**9+7
	d=e
print(d[5])

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()
mod = 10**9+7

dp = np.zeros((len(s)+1, 13))
dp[0][0] = 1

for i in range(len(s)):
  c = -1 if s[i] == '?' else int(s[i])
  for j in range(10):
    if (c != -1 and c != j):
      continue
    for k in range(13):
      dp[i+1][(k * 10 + j) % 13] += dp[i][k]
      dp[i+1][(k * 10 + j) % 13] %= mod
		
  for j in range(13):
    dp[i+1][j] %= mod    
  
print(int(dp[len(s)][5]))

Submission status: Runtime Error

Solution code:
s = input()
dp = [[0 for i in range(13)] for i in range(len(s))]
if s[-1] != "?":
    dp[0][int(s[-1]) % 13] += 1
else:
    for k in range(10):
        dp[0][k % 13] += 1

for i in range(1,len(s)):
    for r in range(13):
        if s[-(i+1)] == "?":
            for k in range(10): 
                dp[i][(k * (10**i) % 13 + r) % 13] += dp[i-1][r]
                
        else:
            dp[i][(int(s[-(i+1)]) * (10**i) % 13 + r) % 13] += dp[i-1][r]
    for r in range(13)    
        dp[i][r]  %= 10**9 + 7
print(dp[len(s)-1][5]%(10**9+7))

Submission status: Runtime Error

Solution code:
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		int mod = 13;
		int mod_num = 1_000_000_007;

		int[][] mod_table = new int[N][10];
		for (int j=0;j<10;j++) {
			mod_table[0][j] = j;
		}
		for (int i=0;i<N-1;i++) {
			for (int j=0;j<10;j++) {
				mod_table[i+1][j]=mod_table[i][j]*10%mod;
			}
		}

		int[] dp = new int[13];
		dp[0] = 1;
		for (int i=N-1;i>=0;i--) {
			int[] next_dp = new int[13];
			if (S.charAt(i) == '?') {
				for (int l=0;l<10;l++) {
					int k = l;
					for (int j=0;j<mod;j++) {
						next_dp[(mod_table[N-i-1][k] + j)%mod] += dp[j];
						next_dp[(mod_table[N-i-1][k] + j)%mod] %= mod_num;
					}
				}
			} else {
				int k = (int)S.charAt(i) - 48;
				for (int j=0;j<mod;j++) {
					next_dp[(mod_table[N-i-1][k] + j)%mod] += dp[j];
					next_dp[(mod_table[N-i-1][k] + j)%mod] %= mod_num;
				}
			}
			dp = next_dp;
		}
		// System.out.println(N);
		System.out.println(Arrays.toString(dp[6]));
		// System.out.println(Arrays.deepToString(mod_table));
	}
}

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from copy import deepcopy
s = input()
cnt = 0
mod_13_cnt = np.array([0]*13)
hatena = [0,1,2,3,4,5,6,7,8,9]
#定数部分を評価
s_teisu = int(s.replace("?","0")) %13
mod_13_cnt[s_teisu]+=1
fn = lambda x : x %(10**9+7)
for i,s_i in enumerate(s[::-1]):
     mod_13_cnt = np.array(list(map(fn,mod_13_cnt)))
     ph = np.array([0]*13)
     if s_i!="?":
         continue
     for j in hatena:
         add_v = j*10**i%13
         ph += np.roll(mod_13_cnt,add_v)
     mod_13_cnt = ph
print(mod_13_cnt[5]%(10**9+7))