1567  Lucky Sum
Time Limit : 3 Second
Memory Limit : 128 MB
Submission: 27
Solved: 3
 Description
Sheep loves lucky numbers. Everybody knows that lucky digits are positive integers 4 and 8. Now let's define the lucky number. the first digit and the last digit of lucky numbers should be lucky digits, and the distance between each adjacent pair of lucky digits should be less than 4. For example, 4, 8, 408, 4218, 4448, 44098, 80924 are lucky numbers, but 1, 23, 4097, 04, 400008, 812324 are not lucky numbers.
One day Sheep came up with a question: what is the maximum sum of each digit of the lucky number between number A and B(inclusive)? Because sheep is so stupid, he needs your help. Can you help him solve it? Input
Several test cases. The first line of each test case contains a number A, and the second line of each test case contains a number B (0≤A≤B≤10^{300000}).
There will be a blank line between each test case. Output
For each test case, you should print the maximum sum in a line. If there is no lucky number between A and B, you should print 0.
 sample input

4 8 44 88 5 7
 sample output

8 16 0
 hint
Huge input/output, scanf/printf is recommended
 source
 xiaoyang