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 Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

func readLine(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

var CYCLE = 1000000007

var K string
var D int

func shiftAndAdd(a []int, b []int, s int) {
	for j := 0; j < D; j++ {
		jj := (j + s) % D
		a[jj] = (a[jj] + b[j]) % CYCLE
	}
}

func convolute(a []int, b []int, s int) {
	for i := 0; i <= s; i++ {
		shiftAndAdd(a, b, i)
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	K = readLine(reader)
	D = parseInt(readLine(reader))

	d := make([]int, D, D)
	q := make([]int, D, D)
	d[0] = 1
	q[0] = 1

	for i := len(K) - 1; i >= 0; i-- {
		a := int(K[i] - '0')
		// fmt.Printf("a=%d\n", a)
		dd := make([]int, D, D)

		convolute(dd, q, a-1)
		shiftAndAdd(dd, d, a)
		// fmt.Println(q)
		// fmt.Println(dd)

		d = dd

		qq := make([]int, D, D)
		convolute(qq, q, 9)
		q = qq
	}

	fmt.Println(d[0] - 1)
}