Buggy python submission (verdict: Time Limit Exceeded):
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] +=dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
# S="".join(["1" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = {}
for i in range(13):
    dp[(-1,i)] = 0
dp[(-1,0)] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    for i in range(13):
        dp[(t,i)] = 0
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (t,(j*tt+i)%13)
                dp[k] = (dp[k]+dp[(t-1,i)])%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (t,(s*tt+i)%13)
            dp[k] = (dp[(t-1,i)] + dp[k])%MOD

print(dp[(t,5)])

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
# S="".join(["1" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = {}
for i in range(13):
    dp[(-1,i)] = 0
dp[(-1,0)] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    for i in range(13):
        dp[(t,i)] = 0
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (t,(j*tt+i)%13)
                dp[k] += dp[(t-1,i)]
                dp[k] %= MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (t,(s*tt+i)%13)
            dp[k] += dp[(t-1,i)]
            dp[k] %= MOD

print(dp[(t,5)])

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
# S="".join(["1" for _ in range(10**4)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = {}
for i in range(13):
    dp[(-1,i)] = 0
dp[(-1,0)] = 1
for t,ss in enumerate(S[::-1]):
    tt = 10**t
    for i in range(13):
        dp[(t,i)] = 0
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (t,(j*tt+i)%13)
                dp[k] += dp[(t-1,i)]
                dp[k] %= MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (t,(s*tt+i)%13)
            dp[k] += dp[(t-1,i)]
            dp[k] %= MOD

print(dp[(t,5)])

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
# S=input()
S="".join(["1" for _ in range(10**4)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = {}
for i in range(13):
    dp[(-1,i)] = 0
dp[(-1,0)] = 1
for t,ss in enumerate(S[::-1]):
    tt = 10**t
    for i in range(13):
        dp[(t,i)] = 0
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (t,(j*tt+i)%13)
                dp[k] += dp[(t-1,i)]
                dp[k] %= MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (t,(s*tt+i)%13)
            dp[k] += dp[(t-1,i)]
            dp[k] %= MOD

print(dp[(t,5)])

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = {}
for i in range(13):
    dp[(-1,i)] = 0
dp[(-1,0)] = 1
for t,ss in enumerate(S[::-1]):
    for i in range(13):
        dp[(t,i)] = 0
    if ss=="?":
        for i in range(13):
            for j in range(10):
                dp[(t,(j*10**t+i)%13)] += dp[(t-1,i)]
                dp[(t,(j*10**t+i)%13)] %= MOD
    else:
        s = int(ss)
        for i in range(13):
            dp[(t,(s*10**t+i)%13)] += dp[(t-1,i)]
            dp[(t,(s*10**t+i)%13)] %= MOD


print(dp[(t,5)])

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Runtime Error):
S=input()
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = {}
for i in range(13):
    dp[(-1,i)] = 0
dp[(-1,0)] = 1
for t,ss in enumerate(S[::-1]):
    for i in range(13):
        dp[(t,i)] = 0
    if ss=="?":
        for i in range(13):
            for j in range(10):
                dp[(t,(j*10**t+i)%13)] += dp[(t-1,i)]
                dp[(t,(j*10**t+i)%13)] %= MOD
    else:
        s = int(ss)
        for i in range(13):
            dp[(t,(s*10**t+i)%13)] += dp[(t-1,i)]
            dp[(t,(j*10**t+i)%13)] %= MOD


print(dp[(t,5)])

Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
S=input()
# S = "??2??5"
# S = "?44"
# S = "?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???"
# S = "".join(["1" for _ in range(10**5)])
ROT = [1,10,9,12,3,4]
rcnt = [0 for i in range(6)]
MOD = 10**9+7
remain = 0
mod = -1
for i,ss in enumerate(S[::-1]):
  mod = (mod+1)%6
  r = ROT[mod]
  # print(ss,r)
  if ss=="?":
    rcnt[mod] += 1
  else:
    remain += int(ss)*10**i
    remain = remain%13

# print(rcnt, remain)

dp = {}

for rem in range(13):
  dp[(0,rem)] = 0
dp[(0,0)] = 1
for i in range(1,max(rcnt)+1):
  for rem in range(13):
    dp[(i, rem)] = 0
  for rem in range(13):
    for num in range(10):
      key = (i,(rem+num)%13 )
      # if key == (2,0):
      #   print(rem,num, dp[(i-1,rem)])
      dp[key] += dp[(i-1,rem)]

# print(dp)

seq = list(range(13))
am = 0
for k in itertools.product(seq,repeat=6):
  sm = 0
  for i in range(6):
    sm += k[i]*ROT[i]
  if (sm+remain)%13==5:
    cros = 1
    for i in range(6):
      cros*=dp[(rcnt[i], k[i])]
    # if cros>=1:
      # print(k, cros)
    am = (am+cros)%MOD
print(am)


Fixed submission:
S=input()
# S="".join(["?" for _ in range(10**5)])
# S = "??2??5"
# S= "?44"

MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for t,ss in enumerate(S[::-1]):
    if t==0:
        tt = 1
    else:
        tt = (10*tt)%13
    if ss=="?":
        for i in range(13):
            for j in range(10):
                k = (j*tt+i)%13
                dp[t+1][k] += dp[t][i]%MOD
    else:
        s = int(ss)
        for i in range(13):
            k = (s*tt+i)%13
            dp[t+1][k] += dp[t][i]%MOD

print(dp[t+1][5]%MOD)