P15853 [Lanqiao Cup 2nd International Contest] Special Dates

Description

A date consists of year, month, and day. The year has four digits, the month has at most two digits, and the day has at most two digits. Xiaoming likes to write the year, month, and day together as one number. When the month or day has only one digit, he pads a $0$ in front, forming an eight-digit number. For example, January $3$, $2018$ is written as $20180103$, and November $15$, $2018$ is written as $20181115$. Xiaoming found that when written this way, some dates contain $3$ consecutive identical digits. Xiaoming calls such dates special dates. For example, $20181115$ is such a number, because it contains $3$ consecutive $1$'s in the middle. Of course, November $11$, $2011$ is also such a date. Given a start date and an end date, please calculate how many special dates there are between these two dates (including both dates).

Input Format

The input has two lines. The first line contains an eight-digit number representing the start date, and the second line contains an eight-digit number representing the end date.

Output Format

Output one line containing an integer, indicating how many special dates there are.

Explanation/Hint

The given dates are guaranteed to be valid dates. The year ranges from $1900$ to $9999$. The end date will not be earlier than the start date. Translated by ChatGPT 5