Upside Down Clock
Thanks to the programmers' efforts, the robbers arrived at the warehouse right on schedule. The operation was set to begin precisely at 22:11. As seasoned thieves do, our heroes synchronized their watches and took their positions.
After about ten minutes, Balbes, who was hiding in the bushes behind the warehouse, sensed that it was time to start the operation. To confirm his intuition, he reached into his pocket for his brand-new electronic watch.
Balbes's watch was unique in that it lacked any markings or inscriptions on the frame to indicate whether it was upside down. Thus, the correct orientation could only be determined by the electronic display and, naturally, the time of day.
Upon taking out the watch, Balbes glanced at the display and saw 11:22. He was about to head home and wait for the evening when he suddenly remembered he had already seen the sunset today. Checking his watch again, Balbes saw 22:11.
"Must have drunk too much milk yesterday..." thought Balbes as he made his way to the warehouse...
The image below illustrates what happens when each digit on the electronic display is flipped. 'X' indicates that a correct digit does not result.
Let's define a moment in time as interesting if, when the watch is flipped at that moment, the display still shows a valid time of day. For example, the moments 22:11 and 21:51 are interesting (when flipped, the display shows 11:22 and 15:12 respectively), while the moment 22:19 is not interesting (when flipped, it results in 61:22).
Write a program that takes two moments in time, time1 and time2, as input and calculates the number of interesting moments within the time interval from time1 to time2, inclusive.
Input
The input consists of two lines, time1 and time2, which describe the start and end of the time interval in the format "HH:MM". Here, HH represents the hours, and MM represents the minutes.
Output
Output a single integer - the number of interesting moments within the time interval from time1 to time2, inclusive.