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-----
??2??5

-----Sample Output-----
768

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

Difficulty: interview

Starter code:

Solutions:
def main():
  S = str(input())
 
  ans = [0] * 13
  ans[0] = 1
  MOD = 10**9 + 7

  for i in S:
      dp = [0] * 13
      for j in range(13):
          dp[(j * 10) % 13] = ans[j] % MOD
      dp += dp
      if i == '?':
          for j in range(13):
              ans[j] = sum(dp[j+4:j+14])
      else:
          for j in range(13):
              ans[j] = dp[j + 13 - int(i)]

  print(ans[5] % MOD)

def __starting_point():
    main()
__starting_point()

MOD = 1000000007

s = [-1 if x == '?' else int(x) for x in input()]
n = len(s) + 1

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

r = [[(j-i)*4%13 for i in range(10)]for j in range(13)]

for i, x in enumerate(s):
    next_dp = [0] * 13
    if x == -1:
        next_dp = [sum(dp[i] for i in j) for j in r]
    else:
        next_dp = [dp[j[x]] for j in r]
    dp = [k % MOD for k in next_dp]

print(dp[5])

import numpy as np
from numpy.fft import rfft, irfft
from itertools import cycle

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

mat = []
for i in range(6):
    w = np.zeros(13)
    for j in range(10):
        w[(10 ** i * j) % 13] += 1
    mat.append(rfft(w))

ress = [[(10 ** i * j) % 13 for j in range(10)] for i in range(6)]


state = np.zeros(13)
state[0] = 1
state = rfft(state)

res = 5
for keta, s in zip(cycle(list(range(6))), reversed(S)):
    if s == "?":
        state = state * mat[keta]
    else:
        res -= ress[keta][int(s)]

    if state[0] >= 2 ** 50:
        state = np.round(irfft(state, 13))
        state = rfft(np.remainder(state, mod))


state = irfft(state, 13)
print((int(np.round(state[res % 13])) % mod))


import sys
#input = sys.stdin.buffer.readline

def main():
    s = str(input())
    l = len(s)
    ans = [0 for _ in range(13)]
    MOD = 10**9+7
    ans[0] = 1
    
    for st in s:
        dp = [0 for _ in range(13)]
        for i in range(13):
            dp[(10*i)%13] = ans[i]%MOD
        dp += dp
        if st != "?":
            for i in range(13):
                num = int(st)
                ans[i] = dp[i+13-num]
        else:
            for i in range(13):
                ans[i] = sum(dp[i+4:i+14])
    
    print(ans[5]%MOD)

def __starting_point():
    main()
__starting_point()

mod1,mod2=10**9+7,998244353
mod=mod1
dp=[0]*13
dp[0]=1
for i in input():
    if i=="?":
        dp=[sum(dp[4*(j-k)%13]for k in range(10))%mod for j in range(13)]
    else:
        x=int(i)
        dp=[dp[4*(j-x)%13]for j in range(13)]
    
    #print(dp)
print(dp[5])

S = [int(x) if x != "?" else -1 for x in input()]
mod = int(1e9+7)
r = [0]*13
if S[0] != -1:
    r[S[0]] = 1
else:
    for i in range(10):
        r[i] = 1
for i in range(1, len(S)):
    dp = [0] * 26
    for j in range(13):
        dp[j * 10 % 13] += (r[j] % mod)

    dp[13:26] = dp[0:13]
    r = [0]*13
    if S[i] == -1:
        s = sum(dp[4:14])
        for j in range(13):
            r[j] += s
            s += dp[j+1] - dp[4+j]
    else:
        for j in range(13):
            r[j] += dp[13 - S[i] + j]
print(r[5] % mod)

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


import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

def __starting_point():
    main()
__starting_point()

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

# solution

modulous=10**9+7
r=[[(j-i)*4%13 for i in range(10)]for j in range(13)]
d=[1]+[0]*12
for c in input():
  if c>"9":
    d=[(sum(d[i] for i in j))%modulous for j in r]
  else:
    d=[d[((j-int(c))*4%13)] for j in range(13)]
    
print(d[5])

def main():
    M=10**9+7
    r=tuple(tuple((j-k)*9%13 for j in range(10))for k in range(13))
    d=[1]+[0]*12
    for c in input():
      if c>'9':
        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[5])
main()

# 解説を参考に作成
# #11254823を参考


def solve():
    S = input()
    mod = 10 ** 9 + 7

    '''
    桁数毎・余りの数字ごとのdpを作成するにあたり、mapを作る.
    たとえば新しい数字Yは前の数字Xの右側に新たに桁を作って
        Y = X(前の数字) * 10 + i(0 <= i <= 9)
    と表せる.
    この Y の余りは、
        Y % 13 = ((X % 13) * 10 + i) % 13
    と表せるので、10 * 13 のマップであらかじめ計算しておくことができる.
    このマップを以下で作っている.
        modmap[新しい桁の数字i][新しい余り(Y % 13 = k)] = 前の数字の時の余り(X % 13 = j)
    '''
    modmap = []
    for i in range(10):
        modmap.append([0] * 13)
        for j in range(13):
            k = (j * 10 + i) % 13
            modmap[i][k] = j

    # なぜ最初を1にするのか？
    # → Sの先頭に 0 を固定でつけても結果は変化しない. また付けた場合の最初の計算では余り0となる.
    # → どんなパターンでも共通の初期状態として使用できる.
    dp = [1] + [0] * 12
    for s in S:
        if s == '?':
            dp = [sum(dp[l] for l in modlist) % mod for modlist in zip(*modmap)]
        else:
            modlist = modmap[int(s)]
            dp = [dp[modlist[l]] % mod for l in range(13)]

    print((dp[5]))


def __starting_point():
    solve()

__starting_point()

import numpy as np

MOD = 1000000007
S = input()[::-1]

a = 10 ** np.arange(6) % 13
b = np.tile(np.arange(10),(6, 1))
c = a * b.T % 13
c = c.T
f = np.zeros((6, 13, 13), dtype=np.int64)
for i in range(6):
    f[i, 0, c[i]] = 1
    for j in range(12):
        f[i, j + 1] = np.roll(f[i, j], 1)

prev = np.zeros(13, dtype=np.int64)
prev[0] = 1
digit = 0

for i, c in enumerate(S):
    k = i % 6
    if c == '?':
        cur = np.dot(prev, f[k]) % MOD
        prev, cur = cur, prev
    else:
        digit += a[k] * (ord(c) - ord('0'))

m = (5 - digit) % 13
print(prev[m])

import numpy as np
MOD = 10 ** 9 + 7

S = [int(x) if x != "?" else -1 for x in input()]
N = len(S)

# 現在考えてる一つ前の桁数で、余りが i になる整数の個数
r = [0]*13

# まず一つ目の値が１の位とする
s = S[0]
if s != -1:
  r[s] = 1
else:
  for i in range(10):
    r[i] = 1

# 桁を進めながら個数をカウント
for i in range(1, N):
    # dp[j]
    # 現在考えている桁(i)を除く、余りが j となる整数の個数
    dp = [0]*26
    # 桁が一つ上がるので、一つ前の余りが 10 倍になる
    for j in range(13):
      dp[j*10%13] += r[j] % MOD
    # アクセスを高速にするため２倍の長さとる (dp[i] == dp[i + 13])
    dp[13:26] = dp[0:13]
    r = [0]*13
    s = S[i]
    if s == -1:
      w = sum(dp[4:14])
      for j in range(13):
        r[j] += w
        w += dp[j+1] -dp[j+4]
    else:
      for j in range(13):
        r[j] += dp[13-s+j]
print(r[5]%MOD)        

S = str(input())

ans = [0] * 13
ans[0] = 1
MOD = 10**9 + 7

for i in S:
    dp = [0] * 13
    for j in range(13):
        dp[(j * 10) % 13] = ans[j] % MOD
    dp += dp
    if i == '?':
        for j in range(13):
            ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13):
            ans[j] = dp[j + 13 - int(i)]

print(ans[5] % MOD)

MOD=10**9+7
S=input()
N=len(S)
if N==1:
  if S=='?' or int(S)==5:
    print(1)
  else:
    print(0)
  return

if S[0]=='?':
  x=[1]*10+[0]*3
else:
  x=[0]*13
  x[int(S[0])]=1

for i in range(1, N):
  if S[i]=='?':
    tmp=sum(x)
    x=[
      tmp-x[4]-x[8]-x[12],
      tmp-x[3]-x[8]-x[12],
      tmp-x[3]-x[7]-x[12],
      tmp-x[3]-x[7]-x[11],
      tmp-x[2]-x[7]-x[11],
      tmp-x[2]-x[6]-x[11],
      tmp-x[2]-x[6]-x[10],
      tmp-x[1]-x[6]-x[10],
      tmp-x[1]-x[5]-x[10],
      tmp-x[1]-x[5]-x[9],
      tmp-x[0]-x[5]-x[9],
      tmp-x[0]-x[4]-x[9],
      tmp-x[0]-x[4]-x[8]
    ]
  elif S[i]=='0':
    x=[x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9]]
  elif S[i]=='1':
    x=[x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5]]
  elif S[i]=='2':
    x=[x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1]]
  elif S[i]=='3':
    x=[x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10]]
  elif S[i]=='4':
    x=[x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6]]
  elif S[i]=='5':
    x=[x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2]]
  elif S[i]=='6':
    x=[x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11]]
  elif S[i]=='7':
    x=[x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7]]
  elif S[i]=='8':
    x=[x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3]]
  elif S[i]=='9':
    x=[x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12]]
    
  x=[x[j]%MOD for j in range(13)]

print(x[5])

m=10**9+7
s=input()
d=[1]+[0]*12
for i in range(len(s)):
 if s[i]== "?":d=[sum(d[(j-k)*4%13]for k in range(10))%m for j in range(13)]
 else:d=[d[(j-int(s[i]))*4%13]%m for j in range(13)]
print(d[5])

s = input()
q = s.count("?")
ans = [0] * 13
ans[0] = 1

for v in s:
    dp = [0] * 13
    for j in range(13):
        dp[(j * 10) % 13] = ans[j] % 1000000007
    dp += dp
    for j in range(13):
        if v == '?':
            ans[j] = sum(dp[j+4:j+14])
        else:
            ans[j] = dp[j - int(v)]

print((ans[5] % 1000000007))



s = input()
n = len(s)
dp1 =[0 for _ in range(13)]
dp1[0]=1


move = [[] for _ in range(13)]

for i in range(10):
    for j in range(13):
        move[(10*j+i)%13].append(j)



for i in range(n):
    dp2 =[0 for _ in range(13)]
    if s[i]=="?":
        si = list(range(10))
        for mod,ex in enumerate(move):
            dp2[mod] += sum([dp1[x] for x in ex])
    else:
        si = int(s[i])
        for j in range(13):
            dp2[(10*j+si)%13]+=dp1[j]
    dp1 = [x%(10**9+7) for x in dp2] 


print((dp1[5]))


S = str(input())
ans = [0] * 13
ans[0] = 1
MOD = 10**9 + 7
for i in S:
    dp = [0] * 13
    for j in range(13):
        dp[(j * 10) % 13] = ans[j] % MOD
    dp += dp
    if i == '?':
        for j in range(13):
            ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13):
            ans[j] = dp[j + 13 - int(i)]
print(ans[5] % MOD)

MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

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))


import numpy as np


def main():
    n = 13
    mod = 1000000007
    r = 5
    in_str = input()

    amari_l = amari_list(n)
    amari_m = amari_matrix(n, amari_l)

    ans_list = initial(in_str[-1:], n)

    for i, s in enumerate(reversed(in_str)):
        if i == 0:
            continue
        if s == "?":
            ans_list = np.dot(ans_list, amari_m[i % len(amari_m)]) % mod
        else:
            t = int(s) * amari_l[i % len(amari_l)] % n
            ans_list = np.roll(ans_list, t)

    print((int(ans_list[r] % mod)))


def initial(s, n):
    if s == "?":
        return np.array([1 if i < 10 else 0 for i in range(n)], dtype='int64')
    else:
        return np.array([1 if i == int(s) else 0 for i in range(n)], dtype='int64')


def shift(n, r):
    return np.array([[1 if (i - j + r) % n == 0 else 0 for j in range(n)] for i in range(n)])


def amari_list(n):
    ret = []
    for i in range(n + 1):
        r = 10**i % n
        if r in ret:
            return ret
        else:
            ret.append(r)


def amari_matrix(n, amari_list):
    ret = np.zeros((len(amari_list), n, n))
    for i, j in enumerate(amari_list):
        tmp = np.zeros((n, n))
        for k in range(10):
            tmp += shift(n, j * k % n)
        ret[i] = tmp
    return ret


def __starting_point():
    main()

__starting_point()

import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_tuple = tuple([i % 13 for i in range(12 ** 2 + 1)])
    tuple10 = tuple(range(10))
    tuple13 = tuple(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in tuple10:
                m = mod13_tuple[(d * mul)]
                for pm in tuple13:
                    dp[mod13_tuple[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_tuple[(si * mul)]
            for pm in tuple13:
                dp[mod13_tuple[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in tuple13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_tuple[(mul * 10)]
    print(dp_[5])

main()

S = [int(x) if x != "?" else -1 for x in input()]
g = 10 ** 9 + 7
x = 1
DP = [[0] * 13 for _ in range(2)]
DP[0][0] = 1
for i in range(len(S)):
    for j in range(13):
        DP[1][j] = DP[0][j] % g
        DP[0][j] = 0
    for j in range(13):
        if S[i] == -1:
            s = (j*10)%13
            e = (s+10)%13
        else:
            s = (j*10+S[i])%13
            e = (s+1)%13
        DP[0][s] += DP[1][j]
        if s > e:
            DP[0][0] += DP[1][j]
        DP[0][e] -= DP[1][j]
    w = 0
    for j in range(13):
        w += DP[0][j]
        DP[0][j] = w

print((DP[0][5] % g))


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(dp[5])

S=input()
A=[1,0,0,0,0,0,0,0,0,0,0,0,0]
a=10**9+7
for i in range(len(S)):
  B=A[:]
  if S[i]=="?":
    A[0]=(B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3])%a
    A[1]=(B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7])%a
    A[2]=(B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11])%a
    A[3]=(B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2])%a
    A[4]=(B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6])%a
    A[5]=(B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10])%a
    A[6]=(B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1])%a
    A[7]=(B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5])%a
    A[8]=(B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9])%a
    A[9]=(B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0])%a
    A[10]=(B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4])%a
    A[11]=(B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8])%a
    A[12]=(B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12])%a
  else:
    s=int(S[i])
    for i in range(13):
      A[i]=B[(i*4+9*s)%13]
print((A[5]))
    
        
   


M=10**9+7
r=[[(j-i)*4%13 for i in range(10)]for j in range(13)]
d=[1]+[0]*12
for c in input():
  if c>"9":
    d=[(sum(d[i] for i in j))%M for j in r]
  else:
    d=[d[((j-int(c))*4%13)] for j in range(13)]
    
print(d[5])

s = input()

frommap = []
for d in range(10):
    frommap.append([0] * 13)
    for m in range(13):
        m2 = (m * 10 + d) % 13
        frommap[d][m2] = m
transmap = list(zip(*frommap))

dp = [1] + [0] * 12
for c in s:
    if c == '?':
        dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in transmap]
    else:
        dp = [dp[f] for f in frommap[int(c)]]

print(dp[5])

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

cur = [0] * 13
cur[0] = 1
r = 1
base = 0
for i in range(len(S)):
    s = S[-(i+1)]
    if s == '?':
        prev = cur
        cur = [sum(prev)] * 13
        for m in range(13):
            for d in range(10,13):
                cur[(m + r*d) % 13] -= prev[m]
        for m in range(13):
            cur[m] %= MOD
    else:
        base = (base + r*int(s)) % 13

    r = (10 * r) % 13

print(cur[(5-base) % 13])

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[rt[k + r]] += p[k]
    for j in list13:
      p[j] = np[j] % divisor
      np[j] = 0
  print(p[5] % divisor)
main()

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

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)

s = input()
ans,mod = [0]*13,10**9+7
if s[0]=="?": ans = [1]*10+[0]*3
else: ans[int(s[0])] = 1
for i in s[1:]:
    dp = [0]*13
    for j in range(13): dp[j*10%13] = ans[j]%mod
    dp+=dp
    if i=="?":
        for j in range(13): ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13): ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)

M = 10**9+7
r = tuple(tuple((j-i) * 4 % 13 for i in range(10)) for j in range(13))
d = [1] + [0] * 12
for c in input():
    if c > "9":
        d = [(sum(d[i] for i in j)) % M for j in r]
    else:
        d = [d[((j - int(c)) * 4 % 13)] for j in range(13)]
print(d[5])

import sys
 
s= sys.stdin.readline().strip()
#
MOD=10**9+7
mmap= []
for i in range(6):
    b = 10**i % 13
    mmap.append( [ [ (b*i+j)%13 for i in range(1,10) ] for j in range(13) ] )
#
dp= [ 0 ] * 13
dp[0] = 1
j= 0
for c in reversed(s):
    tmp = dp.copy()
    #
    if c=="0": pass
    elif c=="?":
        bset = mmap[j]
        for m,num in enumerate(tmp):
            if num==0: continue
            for idx in bset[m]: dp[idx]+=num
        #
        for i in range(13): dp[i]%=MOD
    else:
        b= mmap[j][0][int(c)-1]
        for m in range(13):
            idx= (m+b)%13
            dp[idx]= tmp[m]
    #
    if j==5: j=0
    else: j+=1
#
print((dp[5]))


import numpy as np
s = input()

A = []
for i in range(6):
    m = [-(j*10**i%13)%13 for j in range(10)]
    tmp = []
    for j in m:
        tmp.append([[1 if (k-l)%13==j else 0 for k in range(13)] for l in range(13)])
    tmp.append([[1 if (k-l)%13 in m else 0 for k in range(13)] for l in range(13)])
    A.append(tmp)
A = np.array(A)

dp = np.zeros(13, dtype=int)
dp[0] = 1
m = 1
for ind, i in enumerate(reversed(s)):
    i = int(i) if i!='?' else 10
    tmp = np.dot(A[ind%6, i, :, :], dp)
    dp = tmp%(10**9+7)
print((dp[5]))


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

    s = input()
    r = [0] * 13
    r[0] = 1
    p = 1
    for c in reversed(s):
        if c == '?':
            tank = []
            for x in range(10):
                x = x * p % 13
                tank.append(r[13 - x:] + r[:13 - x])
            r = list(map(sum, list(zip(*tank))))
            *r, = [x % MOD for x in r]


        else:
            x = int(c)
            x = x * p % 13
            r = r[13 - x:] + r[:13 - x]
        p = p * 10 % 13

    print((r[5]))


def __starting_point():
    main()

__starting_point()

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():
    if c>'9':
      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[5])
main()

#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

S = input()
ans = [0]*13
ans[0]=1
 
for c in S:
    dp=[0]*13
    for i in range(13):
        #dpはansを一桁ずらしたもの
        dp[(i*10)%13]=ans[i]%MOD
    #0~12と13~25と同じものを増設
    dp+=dp
 
    if c=='?':
        for i in range(13):
            #添字を13から26まで増やしたから、ここでこう楽な計算ができる。
            ans[i]=sum(dp[i+4:i+14])
    else:
        for i in range(13):
            ans[i]=dp[i+13-int(c)]

print(ans[5]%MOD)

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


s = input()

mod = 10**9+7
n = len(s)
res = [1] + [0] * 12
for ss in s:
    dp = [0] * 13
    for i in range(13):
        dp[(10*i)%13] = res[i]
    dp += dp

    if ss == '?':
        for i in range(13):
            res[i] = sum(dp[i+4:i+14])
    else:
        for i in range(13):
            res[i] = dp[i+13-int(ss)]
    res = [v%mod for v in res]
print((res[5]))


r = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
d = [1] + [0] * 12
M = 10 ** 9 + 7
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])

MOD = 10**9 + 7
S = input()
 
cur = [0] * 13
cur[0] = 1
r = 1
base = 0
for i in range(len(S)):
    s = S[-(i+1)]
    if s == '?':
        prev = cur
        cur = [sum(prev)] * 13
        for m in range(13):
            for d in range(10,13):
                cur[(m + r*d) % 13] -= prev[m]
        for m in range(13):
            cur[m] %= MOD
    else:
        base = (base + r*int(s)) % 13
 
    r = (10 * r) % 13
 
print(cur[(5-base) % 13])

from itertools import accumulate

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

    Ss = input()

    dp = [0] * 13
    dp[0] = 1
    for d, Sd in enumerate(Ss):
        dp2 = [0] * 26
        for mod13 in range(13):
            if Sd != '?':
                x = int(Sd)
                mod13n = (10*mod13 + x) % 13
                dp2[mod13n] += dp[mod13]
                dp2[mod13n+1] -= dp[mod13]
            else:
                mod13n = (10*mod13 + 0) % 13
                dp2[mod13n] += dp[mod13]
                dp2[mod13n+10] -= dp[mod13]
        dp2 = list(accumulate(dp2))
        dp = [(a+b) % MOD for a, b in zip(dp2[:13], dp2[13:])]

    print((dp[5]))


solve()


import numpy as np
 
s = input()
p = np.array([0]*13)
p[0] = 1
 
amari = [[0]*13 for _ in range(13)]
for j in range(10):
  for i in range(13):
    amari[i][(i*10+j)%13] += 1
M = np.array(amari)
 
for si in range(len(s)):
  a = np.array([0]*13)
  if s[si] == '?':
    a = np.dot(p,M)
  else:
    c = int(s[si])
    for i in range(13):
      a[(i*10+c)%13] += p[i]
  p = np.mod(a,1000000007)
print(p[5])

S=input()
import numpy as np
M=13
MOD=10**9+7
dp=np.zeros(M, dtype=np.int64)
dp[0]=1
idx = np.zeros(M, dtype=np.int8)
window = np.ones(10, dtype=np.int8)
for i in range(M):
  idx[i * 10 % M] = i
for s in S:
  if s=='?':
    tdp=dp[idx]
    ndp = np.concatenate([tdp[4:], tdp])
    dp = np.convolve(ndp, window, mode='valid') % MOD
  else:
    dp=np.roll(dp[idx],int(s))
print((dp[5]%MOD))



from copy import copy

MOD = 10**9 + 7
s = input()
count = [0 for _ in range(13)]
count[0] = 1
for i in range(len(s)):
    new = [0 for _ in range(13)]
    for m in range(13):
        new[(m * 10) % 13] = count[m]
    count = new
    if s[i] != "?":
        div = int(s[i])
        count = count[-div:] +  count[:-div]
    else:
        new = [0 for _ in range(13)]
        pre = sum(count[:3])
        SUM = sum(count) % MOD
        for j in range(13):
            pre += count[(j+3) % 13]
            pre -= count[j % 13]
            new[j] = (SUM - pre) % MOD
        count = new
print(count[5])

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


def dot(A, x):
  return [sum([x[t]*A[s][t] for t in range(13)]) for s in range(13)]

S=input()
N=len(S)
if N==1:
  if S=='?' or int(S)==5:
    print(1)
  else:
    print(0)
  return

MOD=10**9+7

if S[0]=='?':
  x=[1]*10+[0]*3
else:
  x=[0]*13
  x[int(S[0])]=1
  
P=[
  [
    [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
    [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
    [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
  ],
  [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
    [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
    [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
    [0,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0, 0, 1, 0, 0],
    [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
    [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
  ]
]

for i in range(1, N):
  if S[i]=='?':
    tmp=sum(x)
    x=[
      tmp-x[4]-x[8]-x[12],
      tmp-x[3]-x[8]-x[12],
      tmp-x[3]-x[7]-x[12],
      tmp-x[3]-x[7]-x[11],
      tmp-x[2]-x[7]-x[11],
      tmp-x[2]-x[6]-x[11],
      tmp-x[2]-x[6]-x[10],
      tmp-x[1]-x[6]-x[10],
      tmp-x[1]-x[5]-x[10],
      tmp-x[1]-x[5]-x[9],
      tmp-x[0]-x[5]-x[9],
      tmp-x[0]-x[4]-x[9],
      tmp-x[0]-x[4]-x[8]
    ]
  elif S[i]=='0':
    x=[x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9]]
  elif S[i]=='1':
    x=[x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5]]
  elif S[i]=='2':
    x=[x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1]]
  elif S[i]=='3':
    x=[x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10]]
  elif S[i]=='4':
    x=[x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6]]
  elif S[i]=='5':
    x=[x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2]]
  elif S[i]=='6':
    x=[x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11]]
  elif S[i]=='7':
    x=[x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7]]
  elif S[i]=='8':
    x=[x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3]]
  elif S[i]=='9':
    x=[x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12]]
    
  x=[x[j]%MOD for j in range(13)]
    
print(x[5])

#abc135d
s=input()
mod=10**9+7
res=[0]*13
res[0]=1
for i in s:
 dp=[0]*13
 for j in range(13):
  dp[(j*10)%13]=res[j]%mod
 dp+=dp
 if i=='?':
  for k in range(13):
   res[k]=sum(dp[k+4:k+14])
 else:
  for k in range(13):
   res[k]=dp[k+13-int(i)]
print(res[5]%mod)


import numpy as np
from numpy.fft import rfft, irfft

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

mat = []
for i in range(6):
    w = np.zeros(13)
    for j in range(10):
        w[(10 ** i * j) % 13] += 1
    mat.append(rfft(w))

ress = [[(10 ** i * j) % 13 for j in range(10)] for i in range(6)]


state = np.zeros(13)
state[0] = 1
state = rfft(state)

keta = 0
res = 5
for s in reversed(S):
    if s == "?":
        state = state * mat[keta % 6]
    else:
        res -= ress[keta % 6][int(s)]

    if state[0] >= 2 ** 50:
        state = np.round(irfft(state, 13))
        state = rfft(np.remainder(state, mod))

    keta += 1

state = irfft(state, 13)
print((int(np.round(np.real(state[res % 13]))) % mod))


def main():
    s = input()
    mod = 10 ** 9 + 7
    table1 = [0] * 13
    table2 = [0] * 13
    table1[0] = 1
    pre = [[((10 * i + j) % 13) for j in range(10)] for i in range(13)]

    for l in s:
        for i in range(13):
            q = table1[i] % mod
            if q == 0:
                continue
            if l == '?':
                for k in pre[i]:
                    table2[k] += q
            else:
                k = (10 * i + int(l)) % 13
                table2[k] += q

        table1 = table2
        table2 = [0] * 13

    print((table1[5] % mod))


def __starting_point():
    main()

__starting_point()

import numpy as np
from numpy.fft import rfft, irfft
from itertools import cycle

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

mat = []
for i in range(6):
    w = np.zeros(13)
    for j in range(10):
        w[(10 ** i * j) % 13] += 1
    mat.append(rfft(w))

ress = [[(10 ** i * j) % 13 for j in range(10)] for i in range(6)]


state = np.zeros(13)
state[0] = 1
state = rfft(state)

res = 5
for keta, s in zip(cycle(list(range(6))), S[::-1]):
    if s == "?":
        state = state * mat[keta]
        if state[0] >= 2 ** 50:
            state = np.round(irfft(state, 13))
            state = rfft(np.remainder(state, mod))
    else:
        res -= ress[keta][int(s)]


state = irfft(state, 13)
print((int(np.round(state[res % 13])) % mod))


s = input()

frommap = []
for d in range(10):
    frommap.append([0] * 13)
    for m in range(13):
        m2 = (m * 10 + d) % 13
        frommap[d][m2] = m

dp = [1] + [0] * 12
for c in s:
    if c == '?':
        dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)]
    else:
        dp = [dp[f] for f in frommap[int(c)]]

print(dp[5])

modarr61=[76924, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923]
modarr51=[7693, 7692, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692]
modarr52=[7693, 7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692]
modarr53=[7693, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7693, 7693, 7693]
modarr54=[7693, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692, 7692]
modarr55=[7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692, 7693]
modarr56=[7693, 7693, 7693, 7693, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692]
modarr41=[770, 769, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769]
modarr42=[769, 769, 769, 769, 770, 769, 769, 770, 769, 769, 770, 769, 769]
modarr43=[770, 769, 769, 769, 769, 769, 769, 769, 769, 769, 769, 770, 770]
modarr44=[772, 768, 768, 771, 769, 768, 770, 770, 768, 769, 771, 768, 768]
modarr45=[769, 770, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769]
modarr46=[770, 769, 769, 770, 769, 769, 770, 769, 769, 769, 769, 769, 769]
modarr47=[769, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769, 770]
modarr48=[772, 769, 768, 768, 771, 770, 768, 768, 770, 771, 768, 768, 769]
modarr49=[769, 769, 769, 769, 769, 769, 769, 769, 769, 769, 770, 770, 770]
modarr410=[770, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769, 769]
modarr411=[770, 769, 769, 769, 769, 769, 769, 770, 769, 769, 770, 769, 769]
modarr412=[769, 770, 770, 770, 769, 769, 769, 769, 769, 769, 769, 769, 769]
modarr413=[772, 771, 770, 769, 768, 768, 768, 768, 768, 768, 769, 770, 771]
modarr414=[769, 769, 769, 770, 769, 769, 770, 769, 769, 770, 769, 769, 769]
modarr415=[770, 770, 770, 769, 769, 769, 769, 769, 769, 769, 769, 769, 769]
modarr31=[77, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr32=[77, 77, 77, 77, 76, 78, 77, 76, 77, 78, 76, 77, 77]
modarr33=[79, 76, 76, 78, 77, 76, 77, 78, 76, 76, 79, 76, 76]
modarr34=[77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 76, 77, 77]
modarr35=[79, 76, 76, 76, 79, 77, 76, 76, 78, 78, 76, 76, 77]
modarr36=[76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr37=[77, 76, 77, 77, 77, 76, 77, 77, 77, 76, 77, 78, 78]
modarr38=[77, 77, 77, 76, 78, 77, 76, 77, 78, 76, 77, 77, 77]
modarr39=[79, 77, 76, 76, 78, 78, 76, 76, 77, 79, 76, 76, 76]
modarr310=[77, 77, 77, 77, 77, 77, 77, 77, 77, 76, 77, 77, 77]
modarr311=[77, 77, 77, 77, 76, 77, 77, 77, 77, 77, 77, 77, 77]
modarr312=[77, 76, 76, 76, 77, 77, 77, 78, 77, 77, 78, 77, 77]
modarr313=[79, 79, 78, 77, 76, 76, 76, 76, 76, 76, 76, 77, 78]
modarr314=[79, 76, 76, 79, 76, 76, 78, 77, 76, 77, 78, 76, 76]
modarr315=[76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr316=[77, 77, 77, 78, 77, 77, 78, 77, 77, 77, 76, 76, 76]
modarr317=[77, 77, 77, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr318=[77, 78, 78, 77, 76, 77, 77, 77, 76, 77, 77, 77, 76]
modarr319=[79, 78, 77, 76, 76, 76, 76, 76, 76, 76, 77, 78, 79]
modarr320=[77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 76]
modarr21=[8, 7, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8]
modarr22=[7, 7, 8, 8, 8, 7, 8, 8, 8, 7, 8, 8, 8]
modarr23=[10, 7, 7, 7, 9, 8, 7, 7, 8, 9, 7, 7, 7]
modarr24=[7, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8, 8]
modarr25=[8, 7, 8, 8, 8, 7, 8, 8, 8, 7, 7, 8, 8]
modarr26=[8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]
modarr27=[7, 8, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8]
modarr28=[10, 7, 7, 9, 7, 7, 8, 8, 7, 7, 9, 7, 7]
modarr29=[7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7]
modarr210=[8, 8, 8, 7, 7, 8, 8, 8, 7, 8, 8, 8, 7]
modarr211=[7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8]
modarr212=[10, 9, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 9]
modarr213=[8, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8, 7]
modarr214=[7, 8, 8, 8, 7, 8, 8, 8, 7, 8, 8, 8, 7]
modarr215=[8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7]
modarr11=[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1]
modarr12=[1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]
modarr13=[1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
modarr14=[1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0]
modarr15=[1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1]
modarr16=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

def makemod(n):
  if n==100000:
    return modarr11
  elif n==10000:
    return modarr12
  elif n==1000:
    return modarr13
  elif n==100:
    return modarr14
  elif n==10:
    return modarr15
  elif n==1:
    return modarr16
  elif n==110000:
    return modarr21
  elif n==101000:
    return modarr22
  elif n==100100:
    return modarr23
  elif n==100010:
    return modarr24
  elif n==100001:
    return modarr25
  elif n==11000:
    return modarr26
  elif n==10100:
    return modarr27
  elif n==10010:
    return modarr28
  elif n==10001:
    return modarr29
  elif n==1100:
    return modarr210
  elif n==1010:
    return modarr211
  elif n==1001:
    return modarr212
  elif n==110:
    return modarr213
  elif n==101:
    return modarr214
  elif n==11:
    return modarr215
  elif n==111000:
    return modarr31
  elif n==110100:
    return modarr32
  elif n==110010:
    return modarr33
  elif n==110001:
    return modarr34
  elif n==101100:
    return modarr35
  elif n==101010:
    return modarr36
  elif n==101001:
    return modarr37
  elif n==100110:
    return modarr38
  elif n==100101:
    return modarr39
  elif n==100011:
    return modarr310
  elif n==11100:
    return modarr311
  elif n==11010:
    return modarr312
  elif n==11001:
    return modarr313
  elif n==10110:
    return modarr314
  elif n==10101:
    return modarr315
  elif n==10011:
    return modarr316
  elif n==1110:
    return modarr317
  elif n==1101:
    return modarr318
  elif n==1011:
    return modarr319
  elif n==111:
    return modarr320
  elif n==111100:
    return modarr41
  elif n==111010:
    return modarr42
  elif n==111001:
    return modarr43
  elif n==110110:
    return modarr44
  elif n==110101:
    return modarr45
  elif n==110011:
    return modarr46
  elif n==101110:
    return modarr47
  elif n==101101:
    return modarr48
  elif n==101011:
    return modarr49
  elif n==100111:
    return modarr410
  elif n==11110:
    return modarr411
  elif n==11101:
    return modarr412
  elif n==11011:
    return modarr413
  elif n==10111:
    return modarr414
  elif n==1111:
    return modarr415
  elif n==111110:
    return modarr51
  elif n==111101:
    return modarr52
  elif n==111011:
    return modarr53
  elif n==110111:
    return modarr54
  elif n==101111:
    return modarr55
  elif n==11111:
    return modarr56

s=input()
l=len(s)
if l%6!=0:
  s='0'*(6-l%6)+s
  l+=(6-l%6)
mod=10**9+7
cnt=0
dp=[[0]*13 for _ in range(l//6+1)]
for i in range(l-1,-1,-6):
  num=0
  qpos=0
  for j in range(6):
    if s[i-j]=='?':
      qpos+=1*(10**j)
    else:
      num+=int(s[i-j])*(10**j)
  if qpos==0:
    tmod=[0]*13
    tmod[num%13]=1
  elif qpos==111111:
    tmod=modarr61
  else:
    tpos=num%13
    tmod=makemod(qpos)
    tmod=tmod[-tpos:]+tmod[:-tpos]
  if cnt==0:
    dp[1]=tmod
  else:
    for k in range(13):
      for l in range(13):
        dp[cnt+1][(k+l)%13]+=(tmod[k]*dp[cnt][l])%mod
  cnt+=1
print(dp[cnt][5]%mod)

import numpy as np


def main():
    S = {i:s for i, s in enumerate(input()[::-1])}
    MOD = 10**9 + 7
    
    DP_table = np.zeros(13).astype(np.int64)
    
    # 初期化
    digit = S[0]
    if digit == '?':
        for i in range(10):
            DP_table[i] = 1
    else:
        DP_table[int(digit)] = 1
        
    transition_matrixes = {}
    for multiplier in range(13):
        for digit in range(10):
            transition_matrix = np.zeros((13, 13)).astype(np.int64)
            for k in range(13):
                transition_matrix[(digit * multiplier + k) % 13, k] = 1
            transition_matrixes[(multiplier, digit)] = transition_matrix

    transition_matrixes2 = {}
    for multiplier in range(13):
        transition_matrixes2[multiplier] = np.zeros((13, 13)).astype(np.int64)
        for digit in range(10):
            transition_matrixes2[multiplier] += transition_matrixes[(multiplier, digit)]
            
    # DP
    multiplier = 1
    for i in range(1, len(S)):
        multiplier = multiplier * 10 % 13
        digit = S[i]
        if digit == '?':
            transition_matrix = transition_matrixes2[multiplier]
        else:
            transition_matrix = transition_matrixes[(multiplier, int(digit))]
        
        DP_table = np.dot(transition_matrix, DP_table)
        DP_table %= MOD

    print((int(DP_table[5])))

    
def __starting_point():
    main()

__starting_point()

# ABC135D - Digits Parade
# digit DP
def main():
    S = input().rstrip()
    ans, MOD = [0] * 13, 10 ** 9 + 7
    ans[0] = 1
    for c in S:
        dp = [0] * 13
        for i in range(13):
            dp[(i * 10) % 13] = ans[i] % MOD
        dp += dp
        if c == "?":
            for i in range(13):
                ans[i] = sum(dp[i + 4 : i + 14])
        else:
            x = int(c)
            for i in range(13):
                ans[i] = dp[i + 13 - x]
    print(ans[5] % MOD)


def __starting_point():
    main()
__starting_point()

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

from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    mod=10**9+7
    s=readline().strip()
    n=len(s)

    convert=[[0]*13 for i in range(13)]
    for a in range(13):
        for b in range(10):
            convert[a][(10*a+b)%13]=1

    convert=np.array(convert,dtype=np.int64)
    dp=np.zeros(13,dtype=np.int64)
    dp[0]=1
    for i in range(n):
        if s[i]=="?":
            tmp=np.dot(dp,convert)
        else:
            x=int(s[i])
            tmp=np.zeros(13,dtype=np.int64)
            for j in range(13):
                tmp[(j*10+x)%13]=dp[j]
        tmp%=mod
        dp=tmp

    print(dp[5])
    
def __starting_point():
    main()
__starting_point()

def solve(S):
    N = len(S)
    MOD = 1_000_000_007
    dp = [0] * 13
    dp[0] = 1
    for i in range(N):
        tmp = [0] * 13
        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):
                tmp[(j + k * 10) % 13] += dp[k]
        for j in range(13):
            dp[j] = tmp[j] % MOD
    return dp[5]


print((solve(input())))


import numpy as np
MOD=10**9+7

S=[int(x) if x != "?" else -1 for x in input()]
N=len(S)

#現在考えてる1つ前の桁数で, 余りがiになる整数の個数
r=[0]*13

#まず1つ目の値が1の位とする
s=S[0]
if s != -1:
  r[s] = 1
else:
  for i in range(10):
    r[i] = 1

#桁を進めながら個数をカウント
for i in range(1,N):
  #dp[j]
  #現在考えている桁(i)を除く, 余りがjとなる整数の個数
  dp = [0]*26
  #桁が1つ上がるので, 1つ前のあまりが10倍になる
  for j in range(13):
    dp[j*10%13] += r[j] % MOD
  #アクセスを高速にするため2倍の長さをとる(dp[i]==di[i+13])
  dp[13:26] = dp[0:13]
  r=[0]*13
  s=S[i]
  if s == -1:
    w=sum(dp[4:14])
    for j in range(13):
      r[j] += w
      w += dp[j+1] -dp[j+4]
  else:
    for j in range(13):
      r[j] += dp[13-s+j]
print(r[5]%MOD)

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():
        if c > '9':
            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[5]))
main()


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

M=10**9+7
r=tuple(tuple((j-i)*4%13 for i in range(10))for j in range(13))
d=[1]+[0]*12
for c in input():
  if c>"9":
    d=[(sum(d[i] for i in j))%M for j in r]
  else:
    d=[d[((j-int(c))*4%13)] for j in range(13)]
    
print(d[5])

MOD = 10 ** 9 + 7


def main(s):
    reminder = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
    dp = [1] + [0] * 12
    for char in s:
        if char == "?":
            dp = [sum(dp[j] for j in k) % MOD for k in reminder]
        else:
            dp = [dp[(int(char) - k) * 9 % 13] for k in range(13)]

    return dp[5]


S = input()
print(main(S))

MOD = 10**9 + 7

def solve(s, p=13):
    a = [0] * p
    a[0] = 1
    for c in s:
        b = [0] * p
        for i in range(p):
            b[(i*10)%p] = a[i] % MOD
        b += b
        if c == "?":
            for i in range(p):
                a[i] = sum(b[i+4:i+p+1])
        else:
            for i in range(p):
                a[i] = b[i+p-int(c)]
    return a[5] % MOD

s = input()
print(solve(s))

s = str(input())
mod = 10**9 + 7
n = len(s)

if s[0] == "?":
  ans = [1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
  ans = [0,0,0,0,0,0,0,0,0,0,0,0,0]
  ans[int(s[0])] = 1


for i in s[1:]:
  dp = [0]*13
  for j in range(13):
    dp[j*10%13] = ans[j] % mod
  dp += dp
  if i == "?":
    for j in range(13):
      ans[j] = sum(dp[j+4:j+14])
  else:
    for j in range(13):
      ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)


# dp[i][k] := 先頭i桁を13で割った余りがkとなるものの個数 or
# dp[i][k] := 先頭i桁（残りはすべて0）を13で割った余りがkとなるものの個数
# どちらが良いか?
# 後者で。
# 先頭からでも下位からでもアルゴリズムは同じはず。下位からのほうが添え字が見やすい。
# →尺取っぽくやるのは下位の桁を追加したときだ。上位から決めないとダメじゃね?
# →前者じゃないとダメか。

# 配るDP
# 桁dがあれば：dp[i+1][k+ (d * 10 ** a)% 13] = dp[i][k]
# 桁が?ならば：10通りあるから10回配る? dp[i+1][k+ (d * 10 ** a)% 13] = dp[i][k]
# 10^5 * 10 * 13は無理じゃない?
# 全体-残り3つとして、+-しながら管理　（これができるのは1の桁の場合だけ）

s = input()
l = len(s)
dp = [[0 for _ in range(13)] for _ in range(l+1)]
dp[0][0] = 1
temp = [0] * 13
summ = 1
mod = 10 ** 9 + 7

for i in range(0, l):
    if s[i] != '?':
        for k in range(13):
            dp[i+1][(k*10+int(s[i])) % 13] = dp[i][k]
    else:
        # ?の場合
        for k in range(13):
            temp[(k*10) % 13] = dp[i][k]
        
        excluded = temp[1] + temp[2] + temp[3]
        for k in range(13):
            dp[i+1][k] = (summ - excluded) % mod
            excluded -= temp[(k+1)%13]
            excluded += temp[(k+4)%13]

        summ *= 10
        summ %= mod

print((dp[l][5]))
# print(dp)            




s = input()

frommap = []
for d in range(10):
    frommap.append([0] * 13)
    for m in range(13):
        m2 = (m * 10 + d) % 13
        frommap[d][m2] = m

dp = [1] + [0] * 12
for c in s:
    if c == '?':
        dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)]
    else:
        f = frommap[int(c)]
        dp = [dp[f[m]] for m in range(13)]

print(dp[5])

S=input()
a=[0]*13
a[0]= 1

for c in S:
  dp=[0]*13
  for i in range(13):
    dp[(i*10)%13]=a[i]%(10**9+7)
  dp+=dp

  if c=='?':
    for i in range(13):
      a[i]=sum(dp[i+4:i+14])
  else:
    for i in range(13):
      a[i]=dp[i+13-int(c)]

print((a[5]%(10**9+7)))


def dot(A, x):
  return [sum([x[t]*A[s][t] for t in range(13)]) for s in range(13)]

MOD=10**9+7

S=input()
N=len(S)
if N==1:
  if S=='?' or int(S)==5:
    print(1)
  else:
    print(0)
  return

if S[0]=='?':
  x=[1]*10+[0]*3
else:
  x=[0]*13
  x[int(S[0])]=1

for i in range(1, N):
  if S[i]=='?':
    tmp=sum(x)
    x=[
      tmp-x[4]-x[8]-x[12],
      tmp-x[3]-x[8]-x[12],
      tmp-x[3]-x[7]-x[12],
      tmp-x[3]-x[7]-x[11],
      tmp-x[2]-x[7]-x[11],
      tmp-x[2]-x[6]-x[11],
      tmp-x[2]-x[6]-x[10],
      tmp-x[1]-x[6]-x[10],
      tmp-x[1]-x[5]-x[10],
      tmp-x[1]-x[5]-x[9],
      tmp-x[0]-x[5]-x[9],
      tmp-x[0]-x[4]-x[9],
      tmp-x[0]-x[4]-x[8]
    ]
  elif S[i]=='0':
    x=[x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9]]
  elif S[i]=='1':
    x=[x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5]]
  elif S[i]=='2':
    x=[x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10], x[1]]
  elif S[i]=='3':
    x=[x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6], x[10]]
  elif S[i]=='4':
    x=[x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2], x[6]]
  elif S[i]=='5':
    x=[x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11], x[2]]
  elif S[i]=='6':
    x=[x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7], x[11]]
  elif S[i]=='7':
    x=[x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3], x[7]]
  elif S[i]=='8':
    x=[x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12], x[3]]
  elif S[i]=='9':
    x=[x[3], x[7], x[11], x[2], x[6], x[10], x[1], x[5], x[9], x[0], x[4], x[8], x[12]]
    
  x=[x[j]%MOD for j in range(13)]
    
print(x[5])

MOD = 10**9 + 7

def main():
    s = [int(in_i) if in_i != '?' else -1 for in_i in list(open(0).read())[:-1]]
    n = len(s)

    cnt = [0] * 13
    if s[0] == -1:
        for j in range(10):
           cnt[j] = 1
    else:
        cnt[s[0]] = 1

    for cur_s in s[1:]:
        dp = [0] * 26
        for i in range(13):
            dp[i*10%13] = cnt[i] % MOD
        dp[13:] = dp[:13]

        if cur_s == -1:
            for i in range(13):
                cnt[i] = sum(dp[i+4:i+14])
        else:
            for i in range(13):
                cnt[i] = dp[i+13-cur_s]

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

def __starting_point():
    main()

__starting_point()

# -*- coding: utf-8 -*-

R10 = list(range(10))
R13 = list(range(13))

S = input()
R = [[(M-N)*4 % 13 for N in R10] for M in R13]
AM = 10**9+7

MOD =[1]+[0]*12

for D in S:
    if D == '?':
        MOD = [sum([MOD[N] for N in M])%AM for M in R]
    else:
        C = int(D)
        MOD = [MOD[M[C]] for M in R]
    #end if
#end for

print((MOD[5]))


import numpy as np

s = input()
p = np.array([0]*13)
p[0] = 1

amari = [[0]*13 for _ in range(13)]
for j in range(10):
  for i in range(13):
    amari[i][(i*10+j)%13] += 1
M = np.array(amari)

for si in range(len(s)):
  a = np.array([0]*13)
  if s[si] == '?':
    a = np.dot(p,M)
  else:
    c = int(s[si])
    for i in range(13):
      a[(i*10+c)%13] += p[i]
  p = np.mod(a,1000000007)
print(p[5])

def main():
    S = [int(i) if i != '?' else -1 for i in input()]
    s = len(S)
    mod = 10 ** 9 + 7
    dp = [[0] * 13 for _ in range(s)]

    table = [[0] * 10 for _ in range(13)]
    for i in range(13):
        for j in range(10):
            table[i][j] = (i * 10 + j) % 13

    table2 = [[] for _ in range(13)]
    for i in range(13):
        for j in range(10):
            table2[table[i][j]].append(i)
    t = set(range(13))
    table2 = [t - set(i) for i in table2]

    if S[0] == -1:
        for i in range(10):
            dp[0][i] += 1
    else:
        dp[0][S[0] % 13] += 1

    for i in range(1, s):
        if S[i] == -1:
            temp = sum(dp[i - 1])
            for j in range(13):
                dp[i][j] = temp
                for k in table2[j]:
                    dp[i][j] -= dp[i - 1][k]
                dp[i][j] %= mod
        else:
            for j in range(13):
                dp[i][table[j][S[i]]] = dp[i - 1][j]

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


def __starting_point():
    main()
__starting_point()

import numpy as np


def solve(s):
    MOD = 10 ** 9 + 7
    dp = np.zeros(13, dtype=np.int64)
    dp[0] = 1
    idx = np.zeros(13, dtype=np.int8)
    for i in range(13):
        idx[i * 10 % 13] = i
    window = np.ones(10, dtype=np.int8)
    for c in s:
        if c == '?':
            tdp = dp[idx]
            ndp = np.concatenate([tdp[4:], tdp])
            dp = np.convolve(ndp, window, mode='valid') % MOD
        else:
            dp = np.roll(dp[idx], int(c))
    return dp[5]


s = input()
print((solve(s)))


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


MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

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))


#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

S = input()
ans = [1]+[0]*12
 
for c in S:
    dp=[0]*13
    for i in range(13):
        #dpはansを一桁ずらしたもの
        dp[(i*10)%13]=ans[i]%MOD
    #0~12と13~25と同じものを増設
    dp+=dp
 
    if c=='?':
        for i in range(13):
            #添字を13から26まで増やしたから、ここでこう楽な計算ができる。
            ans[i]=sum(dp[i+4:i+14])
    else:
        for i in range(13):
            ans[i]=dp[i+13-int(c)]

print(ans[5]%MOD)

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

import sys
input = sys.stdin.readline

S=list(input().rstrip('\n'))

kake10 = [0,10,7,4,1,11,8,5,2,12,9,6,3]
now = {0:1,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0}
for i in S:
  now = {kake10[x]:now[x] for x in range(13)}
  if i=='?':
    now2 = {x:sum(now[(x+y)%13] for y in range(4,14))%1000000007 for x in range(13)}
    now = now2
  else:
    a = int(i)
    now = {(x+a)%13:now[x] for x in range(13)}
print(now[5])

M=10**9+7
#リストに入力（文字列）
text=input()
lst=list(text)
lst.reverse()
digit=len(lst)

######六桁ごとに区切って、?の数とその他の数字を数える
######たとえば文字列のリストが「9?????81????」だったら
######[[17,0],[8,1],[0,2],[0,2],[0,2],[0,2]]になる
six=[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
for i in range(digit):
  if(lst[i]=="?"):
    six[i%6][1]=six[i%6][1]+1
  else:
    six[i%6][0]=(six[i%6][0]+int(lst[i]))%13

    
######数字部分の余りから5を引く    
rem=-(six[0][0]-3*six[1][0]-4*six[2][0]
      -1*six[3][0]+3*six[4][0]+4*six[5][0]-5)%13

######漸化式を6個用意
def mat1(ls):
  val_ls=[0]*13
  for i in range(13):
    val_ls[i]=(ls[i]+ls[(i-1)%13]+ls[(i-2)%13]
               +ls[(i-3)%13]+ls[(i-4)%13]+ls[(i-5)%13]
               +ls[(i-6)%13]+ls[(i-7)%13]+ls[(i-8)%13]
               +ls[(i-9)%13])%M
  return val_ls
def mat10(ls):
  val_ls=[0]*13
  for i in range(13):
    val_ls[i]=(ls[i]+ls[(i+3)%13]+ls[(i+6)%13]
               +ls[(i+9)%13]+ls[(i+12)%13]+ls[(i+15)%13]
               +ls[(i+18)%13]+ls[(i+21)%13]+ls[(i+24)%13]
               +ls[(i+27)%13])%M
  return val_ls
def mat100(ls):
  val_ls=[0]*13
  for i in range(13):
    val_ls[i]=(ls[i]+ls[(i+4)%13]+ls[(i+8)%13]
               +ls[(i+12)%13]+ls[(i+16)%13]+ls[(i+20)%13]
               +ls[(i+24)%13]+ls[(i+28)%13]+ls[(i+32)%13]
               +ls[(i+36)%13])%M
  return val_ls
def mat1000(ls):
  val_ls=[0]*13
  for i in range(13):
    val_ls[i]=(ls[i]+ls[(i+1)%13]+ls[(i+2)%13]
               +ls[(i+3)%13]+ls[(i+4)%13]+ls[(i+5)%13]
               +ls[(i+6)%13]+ls[(i+7)%13]+ls[(i+8)%13]
               +ls[(i+9)%13])%M
  return val_ls
def mat10000(ls):
  val_ls=[0]*13
  for i in range(13):
    val_ls[i]=(ls[i]+ls[(i-3)%13]+ls[(i-6)%13]
               +ls[(i-9)%13]+ls[(i-12)%13]+ls[(i-15)%13]
               +ls[(i-18)%13]+ls[(i-21)%13]+ls[(i-24)%13]
               +ls[(i-27)%13])%M
  return val_ls
def mat100000(ls):
  val_ls=[0]*13
  for i in range(13):
    val_ls[i]=(ls[i]+ls[(i-4)%13]+ls[(i-8)%13]
               +ls[(i-12)%13]+ls[(i-16)%13]+ls[(i-20)%13]
               +ls[(i-24)%13]+ls[(i-28)%13]+ls[(i-32)%13]
               +ls[(i-36)%13])%M
  return val_ls


######漸化式を適用
modulos=[1,0,0,0,0,0,0,0,0,0,0,0,0]
for j in range(six[0][1]):
  modulos=mat1(modulos)
for j in range(six[1][1]):
  modulos=mat10(modulos)
for j in range(six[2][1]):
  modulos=mat100(modulos)
for j in range(six[3][1]):
  modulos=mat1000(modulos)
for j in range(six[4][1]):
  modulos=mat10000(modulos)
for j in range(six[5][1]):
  modulos=mat100000(modulos)
print((modulos[rem]))


import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

main()

import numpy as np

S = input()
mod = int(10**9 + 7)
dp = np.zeros(13, dtype=int)
dp[0] = 1

M = np.zeros((13, 13), dtype=int)
for i in range(13):
    for d in range(10):
        M[i][(i * 10 + d) % 13] += 1

for s in S:
    ndp = np.zeros(13, dtype=int)
    if s == '?':
        ndp = np.dot(dp, M)
    else:
        d = int(s)
        for j in range(13):
            ndp[(j * 10 + d) % 13] += dp[j]
    dp = ndp % mod

print(dp[5])

import sys
import numpy as np
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()


def convolve(x, y):
    MOD = 10**9+7
    z = np.convolve(x, y) % MOD
    z[:12] += z[13:25]
    return z[:13] % MOD


def main():
    mod = 10**9+7
    S = input()[::-1]
    dp = np.zeros((len(S), 13), dtype='int64')
    amari = 1
    if S[0] == '?':
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][int(S[0])] = 1

    for i in range(1, len(S)):
        arr = np.zeros(13, dtype='int64')
        amari = 10*amari % 13
        if S[i] == '?':
            for si in range(10):
                arr[amari*si % 13] += 1
        else:
            arr[amari*int(S[i]) % 13] = 1
        dp[i] = convolve(dp[i-1], arr)

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


def __starting_point():
    main()
__starting_point()

import numpy as np
s = input()
effects = [1, 10, 9, 12, 3, 4]
mod = 10**9+7

amari = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
arrays = [np.eye(13, k=i, dtype=np.int64)+np.eye(13, k=i-13, dtype=np.int64) for i in range(13)]
brrays = [sum(arrays[c*effects[i]%13] for c in range(10)) for i in range(6)]
for i, c in enumerate(reversed(s)) :
    if c != "?" :
        c = int(c)
        array = arrays[c*effects[i%6]%13]
        amari = np.dot(amari, array)
    else :
        array = brrays[i%6]
        amari = np.dot(amari, array)%mod

print(amari[5])

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():
    if c>'9':
        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[5])

import numpy as np
import sys
def input():
    return sys.stdin.readline()[:-1]

# S = [int(x) if x!="?" else -1 for x in input()]

# print (S)

# div_num = 1000000007
# arr = np.arange(13, dtype = np.uint64)
# # dp = np.zeros([2, 13], dtype = np.uint64)

# div13_list = [1]
# for ii in range(1, len(S)):
#     n = div13_list[-1] * 10 % 13
#     if n in div13_list:
#         break
#     else:
#         div13_list.append(n)
# div13_mat = np.array([div13_list] * 10, dtype = int)
# div13_mat = (div13_mat * np.arange(10)[:, None] % 13).T

# if S[-1] == -1:
#     dp[0, :10] = 1
# else:
#     dp[0, S[-1]] = 1

# for ii in range(1, len(S)):
#     # ind = -ii-1
#     # tmp = div13_mat[ii%6]
#     # if S[ind] == -1:
#     #     for n in range(10):
#     #         res = np.roll(arr, -tmp[n])
#     #         # dp[1, res] += dp[0, arr]
#     # else:
#     #     res = np.roll(arr, -tmp[S[ind]])
#     #     # dp[1, res] += dp[0, arr]
#     dp[0] = dp[1] % div_num
#     dp[1] = 0


# print (dp[0, 5])

#
# 大きい方の桁からやってく方法
#

MOD = 1000000007;

S = [int(x) if x!="?" else -1 for x in input()]
n = len(S)

# r[i]
# 現在考えてる一つ前の桁数で、余りが i になる整数の個数
r = [0] * 13

# まず一つ目の値が１の位とする
s = S[0]
if (s != -1):
    r[s] = 1
else:
    for i in range(10): r[i] = 1

# 桁を進めながら個数をカウント
for i in range(1, n):
    # dp[j]
    # 現在考えている桁(i)を除く、余りが j となる整数の個数
    dp = [0] * 26

    # 桁が一つ上がるので、一つ前の余りが 10 倍になる
    for j in range(13):
        dp[j*10%13] += r[j] % MOD

    # アクセスを高速にするため２倍の長さとる (dp[i] == dp[i + 13])
    dp[13:26] = dp[0:13]

    r = [0]*13

    s = S[i]
    if (s == -1):
        w = sum(dp[4:14])
        for j in range(13):
            r[j] += w
            w += dp[j + 1]-dp[j + 4]
    else:
        for j in range(13):
            r[j] += dp[13-s+j]
print((r[5]%MOD))


s = input()
 
mod = 10**9+7
n = len(s)
res = [1] + [0] * 12
for ss in s:
    dp = [0] * 13
    for i in range(13):
        dp[(10*i)%13] = res[i]
    dp += dp
 
    if ss == '?':
        for i in range(13):
            res[i] = sum(dp[i+4:i+14])
    else:
        for i in range(13):
            res[i] = dp[i+13-int(ss)]
    res = [v%mod for v in res]
print(res[5])

s = input()
pre = [1]+[0]*12
n = 10**9 + 7
tem = [[i*j%13 for i in range(10)] for j in range(13)]
t = 1
for i in range(len(s)):
    if s[-1*i-1] > "9":
        pre = [sum([pre[k-i] for i in tem[t]])%n for k in range(13)]      
    else:
        te = int(s[-1*i-1])*t % 13
        pre = [pre[i-te] for i in range(13)]
    t = t*10 % 13
print(pre[5])