#P2010. [NOIP 2016 普及组] 回文日期

[NOIP 2016 普及组] 回文日期

Description

In daily life, a unique date can be specified by the three components: year, month, and day.

Niuniu habitually uses an 8-digit number to represent a date, where the first 4 digits denote the year, the next 2 digits denote the month, and the last 2 digits denote the day. Clearly, a date has only one representation, and two different dates do not share the same representation.

Niuniu considers a date to be palindromic if and only if the 8-digit number representing this date is a palindrome. Now Niuniu wants to know: between the two dates he specifies (including both endpoints), how many real dates are palindromic.

An 8-digit number is palindromic if and only if, for all ii (1i81 \le i \le 8), the ii-th digit from the left is the same as the (9i)(9 - i)-th digit (that is, the ii-th digit from the right).

For example:

  • For November 19, 2016, represented by the 8-digit number 2016111920161119, it is not palindromic.
  • For January 2, 2010, represented by the 8-digit number 2010010220100102, it is palindromic.
  • For October 2, 2010, represented by the 8-digit number 2010100220101002, it is not palindromic.

Each year has 12 months:

Among them, months 1,3,5,7,8,10,121, 3, 5, 7, 8, 10, 12 each have 3131 days; months 4,6,9,114, 6, 9, 11 each have 3030 days; and for February, there are 2929 days in a leap year and 2828 days in a common year.

A year is a leap year if and only if it satisfies one of the following:

  1. The year is a multiple of 44 but not a multiple of 100100;
  2. The year is a multiple of 400400.

For example:

  • The following years are leap years: 2000,2012,20162000, 2012, 2016.
  • The following years are common years: 1900,2011,20141900, 2011, 2014.

Input Format

Two lines, each containing an 8-digit number.

The first line is the start date specified by Niuniu.

The second line is the end date specified by Niuniu.

It is guaranteed that date1\mathit{date}_1 and date2\mathit{date}_2 are real dates, the year part always has 4 digits with a nonzero first digit, and date1\mathit{date}_1 is not later than date2\mathit{date}_2.

Output Format

Output a single integer, representing how many dates between date1\mathit{date}_1 and date2\mathit{date}_2 (inclusive) are palindromic.

20110101
20111231

1

20000101
20101231

2

Hint

Sample Explanation:

  • For sample 1, the valid date is 2011110220111102.
  • For sample 2, the valid dates are 2001100220011002 and 2010010220100102.

Subtasks:

  • For 60%60\% of the testdata, date1=date2\mathit{date}_1 = \mathit{date}_2.

Translated by ChatGPT 5