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

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)


Fixed submission:
K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)

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

L=len(K)

DP=[[0]*D for i in range(2)]#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数


for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        DP[1][j%D]+=1
    else:
        DP[0][j%D]+=1

for ketanum in K[1:]:
    NDP=[[0]*D for i in range(2)]

    for i in range(D):
        for j in range(10):
            NDP[0][(i+j)%D]=(NDP[0][(i+j)%D]+DP[0][i])%mod

            if j>int(ketanum):
                continue
            if j==int(ketanum):
                NDP[1][(i+j)%D]=(NDP[1][(i+j)%D]+DP[1][i])%mod
            else:
                NDP[0][(i+j)%D]=(NDP[0][(i+j)%D]+DP[1][i])%mod

    DP=NDP

print((DP[0][0]+DP[1][0]-1)%mod)

Fixed submission:
K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)

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

L=len(K)

DP=[[0]*D for i in range(2)]#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数


for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        DP[1][j%D]+=1
    else:
        DP[0][j%D]+=1
        


for keta in range(1,L):
    NDP=[[0]*D for i in range(2)]

    for i in range(D):
        for j in range(10):
            NDP[0][(i+j)%D]+=DP[0][i]

    for i in range(D):
        for j in range(10):
            if j>int(K[keta]):
                continue
            if j==int(K[keta]):
                NDP[1][(i+j)%D]+=DP[1][i]
            else:
                NDP[0][(i+j)%D]+=DP[1][i]

    DP=NDP

print((DP[0][0]+DP[1][0]-1)%mod)

Fixed submission:
K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)

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

L=len(K)

DP=[[0]*D for i in range(2)]#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数


for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        DP[1][j%D]+=1
    else:
        DP[0][j%D]+=1

for keta in range(1,L):
    NDP=[[0]*D for i in range(2)]

    for i in range(D):
        for j in range(10):
            NDP[0][(i+j)%D]=(NDP[0][(i+j)%D]+DP[0][i])%mod

    for i in range(D):
        for j in range(10):
            if j>int(K[keta]):
                continue
            if j==int(K[keta]):
                NDP[1][(i+j)%D]=(NDP[1][(i+j)%D]+DP[1][i])%mod
            else:
                NDP[0][(i+j)%D]=(NDP[0][(i+j)%D]+DP[1][i])%mod

    DP=NDP

print((DP[0][0]+DP[1][0]-1)%mod)

Fixed submission:
K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)