Buggy python submission (verdict: Time Limit Exceeded):
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        for ndk in ndp:
            ndk %= md

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int,list(input())))
d = int(input())
f(ks, d)


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)

Buggy python submission (verdict: Time Limit Exceeded):
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        k = int(k)
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        for ndk in ndp:
            ndk %= md

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = input()
d = int(input())
f(ks, d)


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)

Buggy python submission (verdict: Time Limit Exceeded):
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        k = int(k)
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        for dk in dp:
            dk %= md

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = input()
d = int(input())
f(ks, d)


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)

Buggy python submission (verdict: Time Limit Exceeded):
md = 10 ** 9 + 7
ks = input()
d = int(input())
dp = [0] * d
just = 0

for k in ks:
    k = int(k)
    ndp = [0] * d

    for di, dk in enumerate(dp):
        for ndi in range(di, di + 10):
            ndp[ndi % d] += dk

    for ndi in range(just, just + k):
        ndp[ndi % d] += 1

    for dk in dp:
        dk %= md

    just = (just + k) % d
    dp = ndp

print((dp[0] + (just == 0) - 1) % md)


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

def cnt(i, f, s):
    if i == n:
        if s % d or s == 0:
            return 0
        else:
            return 1
    t = (i, f, s)
    if t in memo:
        return memo[t]
    if f:
        m = 10
        re = 0
    else:
        ki = int(k[i])
        m = ki
        re = cnt(i + 1, 0, s + ki)
    for j in range(m):
        re += cnt(i + 1, 1, s + j)
    memo[t] = re = re % md
    return re


md = 10 ** 9 + 7
memo = {}
k = input()
d = int(input())
n = len(k)
print(cnt(0, 0, 0))


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

def cnt(i, f, s):
    if i == n:
        if s % d or s == 0:
            return 0
        else:
            return 1
    t = (i, f, s)
    if t in memo:
        return memo[t]
    if f:
        m = 10
        re = 0
    else:
        ki = int(k[i])
        m = ki
        re = cnt(i + 1, 0, s + ki)
    for j in range(m):
        re += cnt(i + 1, 1, s + j)
    memo[t] = re = re % md
    return re


md = 10 ** 9 + 7
memo = {}
k = input()
d = int(input())
n = len(k)
print(cnt(0, 0, 0))


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)

Buggy python submission (verdict: Runtime Error):
def cnt(i, f, s):
    if i == n:
        if s % d or s == 0:
            return 0
        else:
            return 1
    t = (i, f, s)
    if t in memo:
        return memo[t]
    if f:
        m = 10
        re = 0
    else:
        ki = int(k[i])
        m = ki
        re = cnt(i + 1, 0, s + ki)
    for j in range(m):
        re += cnt(i + 1, 1, s + j)
    memo[t] = re = re % md
    return re


md = 10 ** 9 + 7
memo = {}
k = input()
d = int(input())
n = len(k)
print(cnt(0, 0, 0))


Fixed submission:
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)