Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
p = 10**9+7
DP = [[0]*13 for i in range(n+1)]
DP[0][0] = 1
for i in range(1, n+1):
    for j in range(13):
        if S[i-1] == '?':
            DP[i][j] = sum([DP[i-1][(4*(j-k)) % 13] for k in range(10)]) % p
        else:
            k = int(S[i-1])
            DP[i][j] = DP[i-1][(4*(j-k)) % 13]
print(DP[n][5])


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = list(input())
    S.reverse()
    N = len(S)
    mod = 10**9+7
    dp = [[0 for r in range(13)] for n in range(N+1)]
    dp[0][0] = 1
    lookup = [[0 for d in range(10)] for n in range(N)]
    for n in range(N):
        for d in range(10):
            lookup[n][d] = d*pow(10, n, 13) % 13
    for n in range(1, N+1):
        if S[n-1] == '?':
            for d in range(10):
                for r in range(13):
                    dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
        else:
            for r in range(13):
                dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
    print(dp[-1][5] % mod)


main()


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+pow(10, n-1, 13)*d) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+pow(10, n-1, 13)*int(S[n-1])) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10 ** 9 + 7
ans = [0 for r in range(13)]
if S[0] == '?':
    ans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]
else:
    ans[int(S[0])] = 1
for n in range(1, N):
    if S[n] == '?':
        ans = [sum([ans[(r-(d*pow(10, n, 13) % 13)) % 13]
                    for d in range(10)]) % mod for r in range(13)]
    else:
        ans = [ans[(r-(int(S[n])*pow(10, n, 13) % 13)) % 13]
               for r in range(13)]
print(ans[5])


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10 ** 9 + 7
ans = [0 for r in range(13)]
if S[0] == '?':
    ans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]
else:
    ans[int(S[0])] = 1
for n in range(1, N):
    ans_new = []
    if S[n] == '?':
        for r in range(13):
            count = 0
            for d in range(10):
                r1 = d * (10 ** n) % 13
                r0 = (r - r1) % 13
                count += ans[r0] % mod
            ans_new.append(count % mod)
    else:
        for r in range(13):
            d = int(S[n])
            r1 = d * (10 ** n) % 13
            r0 = (r - r1) % 13
            ans_new.append(ans[r0] % mod)
    ans = ans_new
print(ans[5])


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10 ** 9 + 7
ans = [0 for r in range(13)]
if S[0] == '?':
    ans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]
else:
    ans[int(S[0])] = 1
for n in range(1, N):
    ans_new = []
    if S[n] == '?':
        for r in range(13):
            count = 0
            for d in range(10):
                r1 = d * (10 ** n) % 13
                r0 = (r - r1) % 13
                count += ans[r0] % mod
            ans_new.append(count % mod)
    else:
        for r in range(13):
            d = int(S[n])
            r1 = d * (10 ** n) % 13
            r0 = (r - r1) % 13
            ans_new.append(ans[r0] % mod)
    ans = ans_new
print(ans[5])


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10 ** 9 + 7
ans = [[0 for r in range(13)] for n in range(N)]
if S[0] == '?':
    ans[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]
else:
    ans[0][int(S[0])] = 1
for n in range(1, N):
    if S[n] == '?':
        ans[n] = [sum([ans[n-1][(r-(d*(10**n) % 13)) % 13]
                       for d in range(10)]) % mod for r in range(13)]
        # for r in range(13):
        #     count = 0
        #     for d in range(10):
        #         r1 = d * (10 ** n) % 13
        #         r0 = (r - r1) % 13
        #         count += ans[n - 1][r0] % mod
        #     ans[n][r] = count % mod
    else:
        ans[n] = [ans[n-1][(r-(int(S[n])*(10**n) % 13)) % 13]
                  for r in range(13)]
        # for r in range(13):
        #     d = int(S[n])
        #     r1 = d * (10 ** n) % 13
        #     r0 = (r - r1) % 13
        #     ans[n][r] = ans[n-1][r0] % mod
print(ans[N-1][5])


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7

ans = [[0 for r in range(13)] for n in range(N)]
if S[0] == '?':
    for r in range(10):
        ans[0][r] = 1
else:
    ans[0][int(S[0])] = 1
for n in range(1, N):
    if S[n] == '?':
        for r in range(13):
            count = 0
            for d in range(10):
                r1 = d * (10 ** n) % 13
                r0 = (r - r1) % 13
                count += ans[n - 1][r0]
            ans[n][r] = count % mod
    else:
        for r in range(13):
            d = int(S[n])
            r1 = d * (10 ** n) % 13
            r0 = (r - r1) % 13
            ans[n][r] = ans[n-1][r0] % mod
print(ans[N-1][5])


Fixed submission:
S = list(input())
S.reverse()
N = len(S)
mod = 10**9+7
dp = [[0 for r in range(13)] for n in range(N+1)]
dp[0][0] = 1
lookup = [[0 for d in range(10)] for n in range(N)]
for n in range(N):
    for d in range(10):
        lookup[n][d] = d*pow(10, n, 13) % 13
for n in range(1, N+1):
    if S[n-1] == '?':
        for d in range(10):
            for r in range(13):
                dp[n][(r+lookup[n-1][d]) % 13] += dp[n-1][r] % mod
    else:
        for r in range(13):
            dp[n][(r+lookup[n-1][int(S[n-1])]) % 13] += dp[n-1][r] % mod
print(dp[-1][5] % mod)