Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)


# def debug(var, name="hoge"):
#     print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
#     return


def main():
    MOD = 10**9 + 7
    S = list(input()[:-1])
    L = len(S)
    modsum = 0
    # 余り
    memo_prev = [0 for _ in range(13)]
    memo_prev[0] = 1
    memo = [0 for _ in range(13)]

    for i in range(L):
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            for m in range(13):
                cur = (10*m+int(S[i]))%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
                    memo[cur] %= MOD
        memo_prev = memo.copy()
    print(memo[5])


if __name__ == "__main__":
    main()


Fixed submission:
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)


# def debug(var, name="hoge"):
#     print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
#     return


def main():
    MOD = 10**9 + 7
    S = list(input()[:-1])
    L = len(S)
    modsum = 0
    # 余り
    memo_prev = [0 for _ in range(13)]
    memo_prev[0] = 1
    memo = [0 for _ in range(13)]

    for i in range(L):
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            for m in range(13):
                cur = (10*m+int(S[i]))%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
                    memo[cur] %= MOD
        memo_prev = memo.copy()
    print(memo[5])


if __name__ == "__main__":
    main()


Fixed submission:
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)


# def debug(var, name="hoge"):
#     print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
#     return


def main():
    MOD = 10**9 + 7
    S = list(input()[:-1])
    # print(S)
    L = len(S)
    modsum = 0
    # 余り
    memo_prev = [0 for _ in range(13)]
    memo_prev[0] = 1
    memo = [0 for _ in range(13)]

    for i in range(L):
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            for m in range(13):
                cur = (10*m+int(S[i]))%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
                    memo[cur] %= MOD
        memo_prev = memo.copy()


    print(memo[5])
    # print(memo)








if __name__ == "__main__":
    main()


Fixed submission:
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
MOD = 10**9 + 7

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    S = list(input()[:-1])[::-1]
    # print(S)
    L = len(S)
    modsum = 0
    # はじめ長さ、つぎは余り
    memo = [[ 0 for __ in range(13)] for _ in range(L)]

    # 0だけ別に
    if S[0].isnumeric():
        memo[0][int(S[0])] = 1
    else:
        for n in range(10):
            memo[0][n] = 1
    p = 1
    for i in range(1, L):
        # 数字なら以前までの余りにたす
        p *= 10
        if S[i].isnumeric():
            mod = (int(S[i])*p)%13
            for m in range(13):
                # 0でない余りを次に持ち越し
                if memo[max(0,i-1)][m] > 0:
                    memo[i][(m+mod)%13] += memo[max(0,i-1)][m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                mod = (n*p)%13
                for m in range(13):
                    # その前の数があるなら足す
                    if memo[max(0,i-1)][m] > 0:
                        cur = (m+mod)%13
                        memo[i][cur] += memo[max(0,i-1)][m]
                        memo[i][cur] %= MOD
    print(memo[L-1][5])
    # print(memo)








if __name__ == "__main__":
    main()


Fixed submission:
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
MOD = 10**9 + 7

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    S = list(input()[:-1])[::-1]
    # print(S)
    L = len(S)
    modsum = 0
    # はじめ長さ、つぎは余り
    memo = [[ 0 for __ in range(13)] for _ in range(L)]

    # 0だけ別に
    if S[0].isnumeric():
        memo[0][int(S[0])%13] = 1
    else:
        for n in range(10):
            memo[0][n] = 1

    for i in range(1, L):
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            mod = (int(S[i])*pow(10,i))%13
            for m in range(13):
                # 0でない余りを次に持ち越し
                if memo[max(0,i-1)][m] > 0:
                    memo[i][(m+mod)%13] = memo[max(0,i-1)][m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                mod = (n*pow(10,i))%13
                for m in range(13):
                    # その前の数があるなら足す
                    if memo[max(0,i-1)][m] > 0:
                        cur = (m+mod)%13
                        memo[i][cur] += memo[max(0,i-1)][m]
                        memo[i][cur] %= MOD
    print(memo[L-1][5])
    # print(memo)








if __name__ == "__main__":
    main()


Fixed submission:
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
MOD = 10**9 + 7

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    S = list(input()[::-1][1:])
    L = len(S)
    modsum = 0
    # はじめ長さ、つぎは余り
    memo = [[ 0 for __ in range(13)] for _ in range(L)]

    # 0だけ別に
    if S[0].isnumeric():
        memo[0][int(S[0])%13] = 1
    else:
        for n in range(10):
            memo[0][n] = 1

    for i in range(1, L):
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            mod = (int(S[i])*pow(10,i))%13
            for m in range(13):
                # 0でない余りを次に持ち越し
                if memo[max(0,i-1)][m] > 0:
                    memo[i][(m+mod)%13] = memo[max(0,i-1)][m]
        # ?なら1~10の余りのケース全てインクリメント
        else:
            for n in range(10):
                mod = (n*pow(10,i))%13
                for m in range(13):
                    # その前の数があるなら足す
                    if memo[max(0,i-1)][m] > 0:
                        cur = (m+mod)%13
                        memo[i][cur] += memo[max(0,i-1)][m]
                        memo[i][cur] %= MOD
    print(memo[L-1][5])
    # print(memo)








if __name__ == "__main__":
    main()


Fixed submission:
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()