#P10024. Lucky Number Range

    ID: 12001 Type: Default 1000ms 256MiB

Lucky Number Range

Lucky Number Range

Little R's home features a large electronic display that recorded the registration count for HCOI-R1. Initially, when Little R finished setting up the display, the registration count was l, and later the final count became r.

A pair of integers \((i, j)\) (with \(l \le i \le j \le r\)) is called lucky if during the registration process there exist moments when the displayed number is exactly \(i, i+1, \dots, j\) (i.e. every number from \(i\) to \(j\) appears) and, when the numbers are written in standard decimal notation without any leading zero, they all require the same number of short vertical segments.

The short vertical segments are determined by the seven‐segment display style, counting only the vertical segments. Specifically, each digit uses the following number of vertical segments in its seven‐segment representation:

[ \begin{array}{c|c} \text{Digit} & \text{Vertical Segments} \ \hline 0 & 4 \ 1 & 2 \ 2 & 2 \ 3 & 2 \ 4 & 3 \ 5 & 2 \ 6 & 3 \ 7 & 2 \ 8 & 4 \ 9 & 3 \end{array} ]

For example, the number 10 is composed of digits \(1\) and \(0\) which have \(2\) and \(4\) vertical segments respectively, so 10 uses \(2+4=6\) vertical segments.

Your task is: given two integers l and r, find the maximum value of \(j-i+1\) (i.e. the count of consecutive numbers) for any lucky pair \((i,j)\) where all numbers from \(i\) to \(j\) have the same vertical segment count.

inputFormat

The input consists of a single line containing two integers l and r (\(l \le r\)).

outputFormat

Output a single integer — the maximum number of consecutive numbers (i.e. maximum \(j-i+1\)) among all lucky pairs.

sample

1 10
3