PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000352. Đếm số thần kỳ (Magic Numbers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm số thần kỳ (Magic Numbers)

Magic Numbers

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer is dd-magic when digit dd occurs at every even position of its decimal representation (positions counted from the left, starting at 1) and at no odd position. Leading zeros are forbidden.

For d=6d=6, 1626 is 66-magic, while 1666 is not: its third digit is 6. Given mm, a digit dd, and positive integers a≤ba\le b with the same number of digits, count the dd-magic numbers in inclusive range [a,b][a,b] divisible by mm. Output the count modulo 109+710^9+7.

The bounds may contain up to 2000 digits; read them as strings.

Input

  • First line: mm and dd.
  • Second line: decimal integer aa.
  • Third line: decimal integer bb.

Output

One integer: the count modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): $1 <= m <= 20, 0 <= d <= 9, 1 <= |a|=|b| <= 6, 1 <= a <= b$.
  • Subtask 2 (30 points): $1 <= m <= 300, 0 <= d <= 9, 1 <= |a|=|b| <= 250, 1 <= a <= b$.
  • Subtask 3 (50 points): $1 <= m <= 2000, 0 <= d <= 9, 1 <= |a|=|b| <= 2000, 1 <= a <= b$.

Examples

Example 1

Input

2 6
10
99

Output

8

Explanation

The eight values are 16, 26, 36, 46, 56, 76, 86, and 96: the second digit is 6, the first is not, and each is even.

Example 2

Input

2 0
1
9

Output

4

Explanation

With one digit, position 1 is odd and cannot be 0; the even numbers 2,4,6,8 qualify.

Example 3

Input

19 7
1000
9999

Output

6

Explanation

The six valid integers are 1767, 2717, 5757, 6707, 8797, and 9747.