Problem:
Score : 100 points

Problem Statement

Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:

The sum of the digits in base ten is a multiple of D.

Constraints

All values in input are integers.

1 \leq K < 10^{10000}

1 \leq D \leq 100

Input

Input is given from Standard Input in the following format:

K
D

Output

Print the number of integers satisfying the condition, modulo 10^9 + 7.

Sample Input 1

30
4

Sample Output 1

6

Those six integers are: 4, 8, 13, 17, 22 and 26.

Sample Input 2

1000000009
1

Sample Output 2

2

Be sure to print the number modulo 10^9 + 7.

Sample Input 3

98765432109876543210
58

Sample Output 3

635270834

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var k = ReadLine();
        var d = Input.num;
        var dp = new long[k.Length+1, d, 2];
        dp[0, 0, 0] = 1;
        for (var i = 1; i <= k.Length; i++)
            for (var w = 0; w < d; w++)
                for (var j = 0; j < 2; j++)
                {
                    var val = k[i - 1] - '0';
                    for (var h = 0; h < 10; h++)
                        if (h < val)
                            dp[i, (w + h) % d, 1] = (dp[i, (w + h) % d, 1] + dp[i - 1, w, j]) % Input.MOD;
                        else if (h == val) dp[i, (w + h) % d, j] = (dp[i, (w + h) % d, j] + dp[i - 1, w, j]) % Input.MOD;
                        else if (j == 1) dp[i, (h + w) % d, j] = (dp[i, (w + h) % d, j] + dp[i - 1, w, j]) % Input.MOD;
                }
        WriteLine((dp[k.Length, 0, 0] + dp[k.Length, 0, 1]) % Input.MOD - 1);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}