Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline


def main():
    def digit_dp(n, m):
        # dp[i][j][k] -> i: 現在見ている桁数
        #                j: n以下が保証されているかどうか
        #                k: m で割った余りの総和
        n = list(map(int, list(str(n))))
        n_len = len(n)
        dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
        dp_table[0][0][0] = 1

        for j in range(2):
            for i in range(n_len):
                for d in range(0, 10 if j else n[i] + 1):
                    for k in range(m):
                        dp_table[i + 1][j or (d < n[i])][(k + d % m) % m] += dp_table[i][j][k]

        return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
        #0 の分、1を減算


    a = int(readline())
    b = int(readline())
    mod = 10**9 + 7
    print(digit_dp(a, b) % mod)

if __name__ == "__main__":
    main()


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline


def main():
    def digit_dp(n, m):
        # dp[i][j][k] -> i: 現在見ている桁数
        #                j: n以下が保証されているかどうか
        #                k: m で割った余りの総和
        n = list(map(int, list(str(n))))
        n_len = len(n)
        dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
        dp_table[0][0][0] = 1

        for j in range(2):
            for i in range(n_len):
                for d in range(0, 10 if j else n[i] + 1):
                    for k in range(m):
                        dp_table[i + 1][j or (d < n[i])][(k + d % m) % m] += dp_table[i][j][k]

        return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
        #0 の分、1を減算


    a = int(readline())
    b = int(readline())
    mod = 10**9 + 7
    print(digit_dp(a, b) % mod)

if __name__ == "__main__":
    main()


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline

def main():
    def digit_dp(n, m):
        # dp[i][j][k] -> i: 現在見ている桁数
        #                j: n以下が保証されているかどうか
        #                k: m で割った余りの総和
        n = list(map(int, list(str(n))))
        n_len = len(n)
        dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
        dp_table[0][0][0] = 1

        for i in range(n_len):
            for j in range(2):
                for k in range(m):
                    for d in range(0, 10 if j else n[i] + 1):
                        dp_table[i + 1][j or (d < n[i])][(k + d) % m] += dp_table[i][j][k]

        return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
        #0 の分、1を減算


    a = int(readline())
    b = int(readline())
    mod = 10**9 + 7
    print(digit_dp(a, b) % mod)

if __name__ == "__main__":
    main()


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline

def main():
    def digit_dp(n, m):
        # dp[i][j][k] -> i: 現在見ている桁数
        #                j: n以下が保証されているかどうか
        #                k: m で割った余りの総和
        n = list(map(int, list(str(n))))
        n_len = len(n)
        dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
        dp_table[0][0][0] = 1

        for i in range(n_len):
            for j in range(2):
                for k in range(m):
                    for d in range(0, 10 if j else n[i] + 1):
                        dp_table[i + 1][j or (d < n[i])][(k + d) % m] += dp_table[i][j][k]

        return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
        #0 の分、1を減算


    a = int(readline())
    b = int(readline())
    mod = 10**9 + 7
    print(digit_dp(a, b) % mod)

if __name__ == "__main__":
    main()


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline

def main():
    def digit_dp(n, m):
        # dp[i][j][k] -> i: 現在見ている桁数
        #                j: n以下が保証されているかどうか
        #                k: m で割った余りの総和
        n = list(map(int, list(str(n))))
        n_len = len(n)
        dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
        dp_table[0][0][0] = 1

        for i in range(n_len):
            for j in range(2):
                for k in range(m):
                    for d in range(0, 10 if j else n[i] + 1):
                        dp_table[i + 1][j or (d < n[i])][(k + d % m) % m] += dp_table[i][j][k]

        return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
        #0 の分、1を減算


    a = int(readline())
    b = int(readline())
    mod = 10**9 + 7
    print(digit_dp(a, b) % mod)

if __name__ == "__main__":
    main()


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Buggy python submission (verdict: Time Limit Exceeded):
def digit_dp(n, m):
    # dp[i][j][k] -> i: 現在見ている桁数
    #                j: n以下が保証されているかどうか
    #                k: m で割った余りの総和
    n = list(map(int, list(str(n))))
    n_len = len(n)
    dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
    dp_table[0][0][0] = 1

    for i in range(n_len):
        for j in range(2):
            for k in range(m):
                for d in range(0, 10 if j else n[i] + 1):
                    dp_table[i + 1][j or (d < n[i])][(k + d % m) % m] += dp_table[i][j][k]

    return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
    #0 の分、1を減算


a = int(input())
b = int(input())
mod = 10**9 + 7
print(digit_dp(a, b) % mod)


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Buggy python submission (verdict: Runtime Error):
def digit_dp(n, m):
    # dp[i][j][k] -> i: 現在見ている桁数
    #                j: n以下が保証されているかどうか
    #                k: m で割った余りの総和
    n = list(map(int, list(str(n))))
    n_len = len(n)
    dp_table = [[[0 for k in range(m)] for j in range(2)] for i in range(n_len + 1)]
    dp_table[0][0][0] = 1

    for i in range(n_len):
        for j in range(2):
            for k in range(m):
                for d in range(0, 10 if j else n[i] + 1):
                    dp_table[i + 1][j or (d < n[i])][(k + d % m) % m] += dp_table[i][j][k]

    return dp_table[-1][0][0] + dp_table[-1][1][0] - 1
    #0 の分、1を減算


a, b = map(int, input().split())
mod = 10**9 + 7
print(digit_dp(a, b) % mod)


Fixed submission:
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)