#P2188. 小Z的 k 紧凑数

小Z的 k 紧凑数

Description

Xiao Z listed many numbers on scratch paper. He calls an integer a kk-compact number if the absolute difference between every pair of adjacent digits does not exceed kk.

Now Xiao Z wants to know how many kk-compact numbers are within [l,r][l, r] and asks for your help.

Input Format

A single line with three integers l,r,kl, r, k.

Output Format

A single line containing one integer: the number of kk-compact numbers in [l,r][l, r].

1 13 1
12

Hint

Sample explanation: within [1,13][1, 13], only 1313 is not a 11-compact number.

For 30%30\% of the testdata, rl105r - l \le 10^5.

For another 30%30\% of the testdata, l=1l = 1, and rr is a multiple of 1010.

For 100%100\% of the testdata, 1lr10181 \le l \le r \le 10^{18}, 0k80 \le k \le 8.

Translated by ChatGPT 5