cho.sh
Notes
Loading...

Digital Clock

Time limit

2s

Memory limit

128 MB

Problem

A digital clock usually writes a time in the form hh:mm:ss. The value hh is between 00 and 23, and mm and ss are each between 00 and 59. If all colons (:) are removed, the result is an integer of the form hhmmss; call this the clock integer. The clock integer for 17:05:13 is 170513, and the clock integer for 00:07:37 is 737.

In this problem, a time range is a closed interval with a start time and an end time. For the interval [00:59:58, 01:01:24], both endpoints are included.

Given a range, list the clock integers for every time contained in it. In the interval [00:59:58, 01:01:24], the clock integers are 5958, 5959, every integer from 10000 through 10059, and every integer from 10100 through 10124, for a total of 87 values. We want to know how many of these clock integers are multiples of 3.

A range may pass midnight. Thus, in a range such as [23:59:03, 00:01:24], the clock integer of the start time, 235903, can be larger than the clock integer of the end time, 124. In that case, the included clock integers are those from 235903 through 235959, those from 0 through 59, and those from 100 through 124. You may assume every range is shorter than 24 hours.

Write a program that, given a start time and an end time, counts how many clock integers in the inclusive range are divisible by 3.

Input

The input consists of three lines. Each line contains a start time and an end time in the form hh:mm:ss, separated by one space. Including this space, each line has exactly 17 characters. The start time and end time are always different.

Output

For the three input ranges, output the number of included clock integers that are multiples of 3. Print one answer per line in the same order as the input.