P10024 "HCOI-R1" Number of Registrations

Background

On an electronic display board, for a decimal number $P$, from right to left, from the lowest digit of $P$ to the highest digit, we show each digit in the following way: ![](https://cdn.luogu.com.cn/upload/image_hosting/taibn0fi.png) So, for digits $0\sim 9$, the numbers of short vertical segments used for each digit are $6, 2, 5, 5, 4, 5, 6, 3, 7, 6$, respectively.

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 $l$. Now, the final number of registrations for HCOI-R1 is $r$. Xiao R considers an integer pair $(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, \dots, j$ (that is, $l \leq i \leq j \leq r$), and, **without leading $\bm 0$**, the numbers of short vertical segments used to display $i, i + 1 \dots j$ are the same. Xiao R wants to know: among all lucky pairs $(i, j)$, what is the maximum possible value of $j - i + 1$, that is, the number of integers.

Input Format

Only one line containing two integers $l, 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 $j - i + 1$ among all pairs $(i, j)$.

Explanation/Hint

### Sample Explanation 1 There is a lucky pair $(2, 3)$, meaning they both need $5$ short vertical segments. ### Constraints **This problem uses bundled testdata.** + Subtask 0 (19 pts): $r \leq 10^3$. + Subtask 1 (33 pts): $r \leq 10^6$. + Subtask 2 (48 pts): no special constraints. For all testdata, it is guaranteed that $1 \leq l \leq r \leq 10^{18}$. Translated by ChatGPT 5