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

K = map(int, iter(input()))
D = int(input())

s = 0
dp = [0] * D
for k in K:
    ndp = [0] * D
    for d in range(10):
        for i, dpi in enumerate(dp):
            ndp[(i + d) % D] += dpi

    for d in range(k):
        ndp[(s + d) % D] += 1

    s = (s + k) % D
    dp = [x % mod for x in ndp]

print((dp[0] - (s != 0)) % mod)

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

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

K = map(int, list(input()))
D = int(input())

s = 0
dp = [0] * D
for k in K:
    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

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

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] += dpi
            T[(i + x) % D] % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

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

    K = list(map(int, list(input())))
    D = int(input())

    s = 0
    dp = [0] * D
    for k in K:
        T = [0] * D
        for i, dpi in enumerate(dp):
            for x in range(10):
                T[(i + x) % D] += dpi
                T[(i + x) % D] % mod
        for x in range(k):
            T[(s + x) % D] += 1

        s = (s + k) % D
        dp = T

    print((dp[0] + (-1 if s != 0 else 0)) % mod)

main()

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

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

    K = map(int, list(input()))
    D = int(input())

    s = 0
    dp = [0] * D
    for k in K:
        T = [0] * D
        for i, dpi in enumerate(dp):
            for x in range(10):
                T[(i + x) % D] += dpi
                T[(i + x) % D] % mod
        for x in range(k):
            T[(s + x) % D] += 1

        s = (s + k) % D
        dp = T

    print((dp[0] + (-1 if s != 0 else 0)) % mod)

main()

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

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

K = map(int, list(input()))
D = int(input())

s = 0
dp = [0] * D
for k in K:
    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] += dpi
            T[(i + x) % D] % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

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

K = map(int, list(input()))
D = int(input())

s = 0
dp = [0] * D
for k in K:
    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] += dpi
            T[(i + x) % D] % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)

Fixed submission:
mod = 10 ** 9 + 7

K = input()
D = int(input())

s = 0
dp = [0] * D
for k in K:
    k = int(k)

    T = [0] * D
    for i, dpi in enumerate(dp):
        for x in range(10):
            T[(i + x) % D] = (T[(i + x) % D] + dpi) % mod
    for x in range(k):
        T[(s + x) % D] += 1

    s = (s + k) % D
    dp = T

print((dp[0] + (-1 if s != 0 else 0)) % mod)