Buggy python submission (verdict: Runtime Error):
def main():
    S = input()[::-1]
    N = len(S)
    mod = 10 ** 9 + 7

    dp = [[0] * 13 for _ in range(N + 5)]
    dp[0][0] = 1

    digit = 1
    for i, s in enumerate(S):
        if s == "?":
            num = tuple(range(10))
        else:
            num = (int(s), )

        ni = i + 1
        for j in range(13):
            for k in num:
                nj = (j + k * digit) % 13
                dp[ni][nj] += dp[i][j]
                dp[ni][nj] %= mod

        digit *= 10
        digit %= 13

    return dp[N][5]


if __name__ == "__main__":
    print(main())pyp

Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()[::-1]
    N = len(S)
    mod = 10 ** 9 + 7

    dp = [[0] * 13 for _ in range(N + 5)]
    dp[0][0] = 1

    digit = 1
    for i, s in enumerate(S):
        if s == "?":
            num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        else:
            num = [int(s)]

        ni = i + 1
        for j in range(13):
            for k in num:
                nj = (j + k * digit) % 13
                dp[ni][nj] += dp[i][j]
                dp[ni][nj] %= mod

        digit *= 10
        digit %= 13

    return dp[N][5]


if __name__ == "__main__":
    print(main())

Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
N = len(S)
mod = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(N + 10)]
dp[0][0] = 1

for i, s in enumerate(S):
    if s == "?":
        val = tuple(range(10))
    else:
        val = (int(s),)

    digit = pow(10, i, 13)
    for j in range(13):
        for k in val:
            ni = i + 1
            nj = (j + digit * k) % 13
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod

ans = dp[N][5] % mod
print(ans)


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
N = len(S)
mod = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(N + 10)]
dp[0][0] = 1

for i, s in enumerate(S):
    if s == "?":
        val = tuple(range(10))
    else:
        val = (int(s),)

    digit = pow(10, i, 13)
    for j in range(13):
        for k in val:
            ni = i + 1
            nj = (j + digit * k) % 13
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod

ans = dp[N][5] % mod
print(ans)


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10 ** 9 + 7

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

tmp = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * tmp + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * tmp + x
            new[next_x % 13] = dp[x]

    dp = new
    tmp *= 10 % 13

ans = dp[5] % mod
print(ans)


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10 ** 9 + 7

dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
cnt = 1

for i, s in enumerate(S[::-1]):
    if s == "?":
        tmp = pow(10, i, 13)
        for x in range(13):
            for y in range(10):
                next_x = y * tmp + x
                dp[i+1][next_x % 13] += dp[i][x]
                dp[i+1][next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s)*10**i+x
            dp[i + 1][next_x % 13] = dp[i][x]


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


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10 ** 9 + 7

dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
cnt = 1

for i, s in enumerate(S[::-1]):
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * 10 ** i + x
                dp[i+1][next_x % 13] += dp[i][x]
                dp[i+1][next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s)*10**i+x
            dp[i + 1][next_x % 13] = dp[i][x]


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


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(2)]
dp[0][0] = 1
cnt = 1

for i, s in enumerate(S[::-1]):
    dp[cnt] = [0]*13
    if s == "?":
        for j in range(10):
            d = j * (10 ** i) % 13
            for k in range(13):
                x = k + d
                if x >= 13:
                    x -= 13
                dp[cnt][x] += dp[1 - cnt][k]
                dp[cnt][k] %= mod
    else:
        d = int(s) * (10 ** i) % 13
        for j in range(13):
            x = j + d
            if x >= 13:
                x -= 13
            dp[cnt][x] += dp[1 - cnt][j]
            dp[cnt][j] %= mod
    cnt = 1-cnt

ans = dp[1-cnt][5] % mod
print(ans)


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(2)]
dp[0][0] = 1
cnt = 1

for i, s in enumerate(S[::-1]):
    dp[cnt] = [0]*13
    if s == "?":
        for j in range(10):
            d = j * (10 ** i) % 13
            for k in range(13):
                x = k + d
                if x >= 13:
                    x -= 13
                dp[cnt][x] += dp[1 - cnt][k]
                dp[cnt][k] %= mod
    else:
        d = int(s) * (10 ** i) % 13
        for j in range(13):
            x = j + d
            if x >= 13:
                x -= 13
            dp[cnt][x] += dp[1 - cnt][j]
            dp[cnt][j] %= mod
    cnt = 1-cnt

ans = dp[1-cnt][5] % mod
print(ans)


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()
mod=1000000007

#後ろから解くアルゴリズム
n=13
dp=[0 for _ in range(n)]
dp[0]=1

mul=1
for i in range(len(s)-1, -1, -1):
    nextDP=[0 for _ in range(n)]
    c=s[i]
    if c=='?':
        for k in range(10):
            for j in range(13):
                nextDP[(mul*k+j)%13] += dp[j]
                nextDP[(mul*k+j)%13] %= mod
    else:
        k=int(c)
        for j in range(n):
            nextDP[(mul*k+j)%13] += dp[j]
            nextDP[(mul*k+j)%13] %= mod
    
    mul*=10
    mul%=n
    dp=nextDP.copy()   

print(dp[5])


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
mod=1000000007

#後ろから解くアルゴリズム
n=13
dp=[0 for _ in range(n)]
dp[0]=1

mul=1
for i in range(len(s)-1, -1, -1):
    nextDP=[0 for _ in range(n)]
    c=s[i]
    if c=='?':
        for k in range(10):
            for j in range(13):
                nextDP[(mul*k+j)%13] += dp[j]
                nextDP[(mul*k+j)%13] %= mod
    else:
        k=int(c)
        for j in range(n):
            nextDP[(mul*k+j)%13] += dp[j]
            nextDP[(mul*k+j)%13] %= mod
    
    mul*=10
    mul%=n
    dp=nextDP.copy()   

print(dp[5])


Fixed submission:
S = input()
mod = 10 ** 9 + 7

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

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)