Day 5 : The Election Day Protocol

hardRecursion + Precomputation
In the Republic of Digitalia, election laws follow a unique system. During counting, votes are only considered valid if the counting station ID contains exclusively the digits 4 and 7. For example, stations 47, 744, and 4 are valid, while stations 5, 17, and 467 are invalid. When tallying votes, electoral officer Mikhail must assign each non-valid station to the nearest valid station with an equal or higher ID number. Mikhail defines a function reassign($x$) as the minimum valid station ID that is greater than or equal to $x$. For a range of stations from $l$ to $r$, Mikhail needs to calculate the sum of all station IDs after reassignment, which is expressed as reassign($l$) + reassign($l + 1$) + ... + reassign($r - 1$) + reassign($r$). Can you help him solve this problem?

Input Format:

The first and only line contains two integers l and r --- the first and last station IDs in the range.

Output Format:

Give the answer to the problem as an integer in a single line

Constraints:

($1 \le l \le r \le 10^9$)

Examples:

Example 1:

Input:

2 7

Output:

33

Example 2:

Input:

7 7

Output:

7

Code

Loading Editor...