P27945 [洛谷] "HCOI-R1" Registration Count
普及
题目描述

Problem Background

On an electronic display, for a decimal number \( P \), from right to left, from the lower to the higher digits of \( P \), each digit is displayed as follows:

Thus, for digits ranging from \( 0 \) to \( 9 \), the number of short vertical lines used for each digit is \( 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 \) respectively.

Problem Description

Xiao R has a large electronic display at home, which records the registration count for HCOI-R1.

When Xiao R set it up, the registration count for HCOI-R1 was \( l \). Now, the final registration count is \( r \).

Xiao R considers the integer pair \( (i, j) \) to be lucky if and only if during the registration process, there exists a moment when the count is \( i, i + 1, \ldots, j \) (i.e., \( l \leq i \leq j \leq r \)), and in the absence of leading zeros, the number of short vertical lines used to represent the numbers \( i, i + 1, \ldots, j \) is the same.

Xiao R wants to know the maximum value of \( j - i + 1 \), which is the number of digits, for all lucky pairs \( (i, j) \).

Input Format

A single line containing two integers \( l \) and \( r \), representing the initial and final registration counts, respectively.

Output Format

A single integer representing the maximum value of \( j - i + 1 \) for all lucky pairs \( (i, j) \).

Sample Input and Output

Sample Input #1

2 5

Sample Output #1

2

Sample Input #2

114514 114514

Sample Output #2

1

Notes

Sample Explanation 1

There exists a lucky pair \( (2, 3) \), both of which require \( 5 \) short vertical lines.

Data Range and Constraints

This problem uses batched testing.

  • Subtask 0 (19 pts): \( r \leq 10^3 \).
  • Subtask 1 (33 pts): \( r \leq 10^6 \).
  • Subtask 2 (48 pts): No additional constraints.

For all data, it is guaranteed that \( 1 \leq l \leq r \leq 10^{18} \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 5
样例输出
2