#P10024. 「HCOI-R1」报名人数

「HCOI-R1」报名人数

Background

On an electronic display board, for a decimal number PP, from right to left, from the lowest digit of PP to the highest digit, we show each digit in the following way:

So, for digits 090\sim 9, the numbers of short vertical segments used for each digit are 6,2,5,5,4,5,6,3,7,66, 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Problem Description

There is a large electronic display board in Xiao R's home, which records the number of registrations for HCOI-R1.

When Xiao R finished setting it up, the number of registrations for HCOI-R1 was ll. Now, the final number of registrations for HCOI-R1 is rr.

Xiao R considers an integer pair (i,j)(i, j) to be lucky if and only if, during the registration process, there exists a period when the number of registrations was i,i+1,,ji, i + 1, \dots, j (that is, lijrl \leq i \leq j \leq r), and, without leading 0\bm 0, the numbers of short vertical segments used to display i,i+1ji, i + 1 \dots j are the same.

Xiao R wants to know: among all lucky pairs (i,j)(i, j), what is the maximum possible value of ji+1j - i + 1, that is, the number of integers.

Input Format

Only one line containing two integers l,rl, r, representing the initial number of registrations and the final number of registrations.

Output Format

One line containing one integer, representing the maximum value of ji+1j - i + 1 among all pairs (i,j)(i, j).

2 5
2
114514 114514
1

Hint

Sample Explanation 1

There is a lucky pair (2,3)(2, 3), meaning they both need 55 short vertical segments.

Constraints

This problem uses bundled testdata.

  • Subtask 0 (19 pts): r103r \leq 10^3.
  • Subtask 1 (33 pts): r106r \leq 10^6.
  • Subtask 2 (48 pts): no special constraints.

For all testdata, it is guaranteed that 1lr10181 \leq l \leq r \leq 10^{18}.

Translated by ChatGPT 5