Buggy python submission (verdict: Time Limit Exceeded):
S=input()
M=13
MOD=10**9+7
dp=[[0]*M for i in range(len(S))]
tmp=[0]*M
tmp[0]=1
for i in range(len(S)):
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(tmp):
        dp[i][(j+s)%M]+=d
        #dp[i+1][(j+s)%M]+=d
  else:
    s=int(s)
    for j,d in enumerate(tmp):
      dp[i][(j+s)%M]=d
  for j,d in enumerate(dp[i]):
    tmp[(10*j)%M]=d%MOD
print(dp[-1][5]%MOD)

Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
M=13
MOD=10**9+7
dp=[[0]*M for i in range(2)]
dp[1][0]=1
for i in range(len(S)):
  dp[0]=[0]*13
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[1]):
        dp[0][(j+s)%M]+=d
        #dp[0][(j+s)%M]%=MOD
  else:
    s=int(s)
    for j,d in enumerate(dp[1]):
      dp[0][(j+s)%M]=d
  for j,d in enumerate(dp[0]):
    dp[1][(10*j)%M]=d%MOD
print(dp[0][5]%MOD)



Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
M=13
MOD=10**9+7
dp=[[0]*M for i in range(2)]
dp[1][0]=1
for i in range(len(S)):
  dp[0]=[0]*13
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[1]):
        dp[0][(j+s)%M]+=d
        #dp[0][(j+s)%M]%=MOD
  else:
    s=int(s)
    for j,d in enumerate(dp[1]):
      dp[0][(j+s)%M]=d
  for j,d in enumerate(dp[0]):
    dp[1][(10*j)%M]=d
print(dp[0][5]%MOD)



Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x=0
M=13
MOD=10**9+7
dp=[[0]*M for i in range(2)]
dp[1][0]=1
for i in range(len(S)):
  dp[0]=[0]*13
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[1]):
        dp[0][(j+s)%M]+=d
        dp[0][(j+s)%M]%=MOD
  else:
    s=int(s)
    for j,d in enumerate(dp[1]):
      dp[0][(j+s)%M]=d
  for j,d in enumerate(dp[0]):
    dp[1][(10*j)%M]=d
print(dp[0][5]%MOD)



Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x=0
M=13
MOD=10**9+7
dp=[[0]*M for i in range(2)]
dp[0][0]=1
p=0
for i in range(len(S)):
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[p%2]):
        dp[(p+1)%2][(10*j+s)%M]+=d
        dp[(p+1)%2][(10*j+s)%M]%=MOD
  else:
    s=int(s)
    for j,d in enumerate(dp[p%2]):
      dp[(p+1)%2][(10*j+s)%M]=d
  dp[p%2]=[0]*13
  p+=1
  p%=2
print(dp[p%2][5]%MOD)


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
M=13
MOD=10**9+7
dp=[[0]*M for i in range(len(S)+1)]
dp[0][0]=1
for i in range(len(S)):
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[i]):
        dp[i+1][(10*j+s)%M]+=d
        dp[i+1][(10*j+s)%M]%=MOD
  else:
    s=int(s)
    for j,d in enumerate(dp[i]):
      dp[i+1][(10*j+s)%M]=d
print(dp[-1][5]%MOD)

Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
M=13
MOD=10**9+7
dp=[[0]*M for i in range(len(S)+1)]
dp[0][0]=1
for i in range(len(S)):
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[i]):
        dp[i+1][(10*j+s)%M]+=d
  else:
    s=int(s)
    for j,d in enumerate(dp[i]):
      dp[i+1][(10*j+s)%M]=d
print(dp[-1][5]%MOD)

Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x=0
M=13
MOD=10**9+7
dp=[[0]*M for i in range(2)]
dp[0][0]=1
p=0
for i in range(len(S)):
  s=S[i]
  if s=='?':
    for s in range(10):
      for j,d in enumerate(dp[p%2]):
        dp[(p+1)%2][(10*j+s)%M]+=d
  else:
    s=int(s)
    for j,d in enumerate(dp[p%2]):
      dp[(p+1)%2][(10*j+s)%M]=d
  dp[p%2]=[0]*13
  p+=1
  p%=2
print(dp[p%2][5]%MOD)

Fixed submission:
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)