Buggy python submission (verdict: Time Limit Exceeded):
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
  S = input()
  MOD = int(1e9+7)
  N = len(S)

  dp = np.zeros((N, 13))
  amari = 1
  if S[N-1] != '?':
    dp[0, int(S[N-1])] = 1
  else:
    for j in range(10):
      dp[0,j] = 1

  for i in range(1,N):
    amari = amari * 10 % 13
    idx = N-i-1
    if S[idx] != '?':
      shift = int(S[idx]) * amari % 13
      for j in range(13):
        XX = (j+shift)%13
        dp[i, XX] = dp[i-1, j]
    else:
      for k in range(10):
        shift = k * amari % 13
        for j in range(13):
          XX = (j+shift)%13
          dp[i, XX] = (dp[i, XX] + dp[i-1, j]) % MOD

  print(int(dp[N-1, 5]))

if __name__ == '__main__':
    main()


Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
  S = input()
  MOD = int(1e9+7)
  N = len(S)

  dp = np.zeros((N, 13))
  amari = 1
  for i in range(N):
    amari = amari * 10 % 13 if i > 0 else 1
    idx = N-i-1
    if i == 0:
      if S[idx] != '?':
        dp[i, int(S[idx])] = 1
      else:
        for j in range(10):
          dp[i][j] = 1
    else:
      if S[idx] != '?':
        shift = int(S[idx]) * amari % 13
        for j in range(13):
          XX = (j+shift)%13
          dp[i, XX] = dp[i-1, j]
      else:
        for k in range(10):
          shift = k * amari % 13
          for j in range(13):
            XX = (j+shift)%13
            dp[i, XX] = (dp[i, XX] + dp[i-1, j]) % MOD

  print(int(dp[N-1, 5]))

if __name__ == '__main__':
    main()


Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
  S = input()
  MOD = int(1e9+7)
  N = len(S)

  dp = np.zeros((N, 13))

  for i in range(N):
    idx = N-i-1
    if i == 0:
      if S[idx] != '?':
        dp[i, int(S[idx])] = 1
      else:
        for j in range(10):
          dp[i][j] = 1
    else:
      amari = (10 ** i) % 13
      if S[idx] != '?':
        shift = int(S[idx]) * amari % 13
        for j in range(13):
          XX = (j+shift)%13
          dp[i, XX] = dp[i-1, j]
      else:
        for k in range(10):
          shift = k * amari % 13
          for j in range(13):
            XX = (j+shift)%13
            dp[i, XX] = (dp[i, XX] + dp[i-1, j]) % MOD

  print(int(dp[N-1, 5]))

if __name__ == '__main__':
    main()


Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  S = input()
  MOD = int(1e9+7)
  N = len(S)

  dp = [[0] * 13 for i in range(N)]

  for i in range(N):
    idx = N-i-1
    if i == 0:
      if S[idx] != '?':
        dp[i][int(S[idx])] = 1
      else:
        for j in range(10):
          dp[i][j] = 1
    else:
      amari = (10 ** i) % 13
      if S[idx] != '?':
        shift = int(S[idx]) * amari % 13
        for j in range(13):
          if j+shift < 13:
            dp[i][j+shift] = dp[i-1][j]
          else:
            dp[i][j+shift-13] = dp[i-1][j]
      else:
        for k in range(10):
          shift = k * amari % 13
          for j in range(13):
            if j+shift < 13:
              dp[i][j+shift] = (dp[i][j+shift] + dp[i-1][j]) % MOD
            else:
              dp[i][j+shift-13] = (dp[i][j+shift-13] + dp[i-1][j]) % MOD

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

if __name__ == '__main__':
    main()


Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

MOD = int(1e9+7)
N = len(S)

dp = [[0] * 13 for i in range(N)]

for i in range(N):
  idx = N-i-1
  if i == 0:
    if S[idx] != '?':
      dp[i][int(S[idx])] = 1
    else:
      for j in range(10):
        dp[i][j] = 1
  else:
    amari = (10 ** i) % 13
    if S[idx] != '?':
      shift = int(S[idx]) * amari % 13
      for j in range(13):
        if j+shift < 13:
          dp[i][j+shift] = dp[i-1][j]
        else:
          dp[i][j+shift-13] = dp[i-1][j]
    else:
      for k in range(10):
        shift = k * amari % 13
        for j in range(13):
          if j+shift < 13:
            dp[i][j+shift] = (dp[i][j+shift] + dp[i-1][j]) % MOD
          else:
            dp[i][j+shift-13] = (dp[i][j+shift-13] + dp[i-1][j]) % MOD
            
print(dp[N-1][5])
#print(dp)

Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

MOD = int(1e9+7)
N = len(S)

dp = [[0] * 13 for i in range(N)]

for i in range(N):
  idx = N-i-1
  if i == 0:
    if S[idx] != '?':
      dp[i][int(S[idx])] = 1
    else:
      for j in range(10):
        dp[i][j] = 1
  else:
    amari = (10 ** i) % 13
    if S[idx] != '?':
      shift = int(S[idx]) * amari % 13
      for j in range(13):
        if j+shift < 13:
          dp[i][j+shift] = dp[i-1][j]
        else:
          dp[i][j+shift-13] = dp[i-1][j]
    else:
      for k in range(10):
        shift = k * amari % 13
        for j in range(13):
          if j+shift < 13:
            dp[i][j+shift] = (dp[i][j+shift] + dp[i-1][j]) % MOD
          else:
            dp[i][j+shift-13] = (dp[i][j+shift-13] + dp[i-1][j]) % MOD
            
print(dp[N-1][5])
#print(dp)

Fixed submission:
import copy
S = input()
S = S[::-1]
dp = [0 for _ in range(13)]
dp[0] = 1

mod = int(1e9+7)

def calc(dp,i,k):
  dpw = [0 for _ in range(13)]
  if S[i] == '?':
    X = [i for i in range(10)]
  else:
    X = [int(S[i])]
  for j in range(13):
    for x in X:
      dpw[(j+x*k)%13] += dp[j]  
      dpw[(j+x*k)%13] %= mod
  return dpw

keta = 1
for i in range(len(S)):
  dp = calc(dp,i,keta)
  keta = keta * 10 % 13

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