atcoder#ARC142A. [ARC142A] Reverse and Minimize

[ARC142A] Reverse and Minimize

Score : 300300 points

Problem Statement

For a positive integer xx, let f(x)f(x) be the answer to the question below.

The following operation on xx can be performed zero or more times.

  • Let xx' be the integer obtained by reversing the decimal notation of xx. Then, replace xx with xx'. If xx now has one or more leading zeros, delete them so that it begins with a non-zero digit.

For example, from x=1420x=1420, you get x=241x=241 after one operation, x=142x=142 after two operations, and x=241x=241 after three operations. Find the minimum possible value of xx after operations.

Find the number of integers xx such that 1xN1 \leq x \leq N and f(x)=Kf(x)=K.

Constraints

  • 1N,K10121 \leq N,K \leq 10^{12}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Output

Print the answer.

1420 142
3

Three integers x=142x=142, 241241, and 14201420 satisfy 1x14201 \leq x \leq 1420 and f(x)=142f(x)=142.

1419 142
2
6 19
0