P28218 [洛谷] [NOIP2016 Junior Group] Palindrome Dates
普及
题目描述

Problem Background

NOIP2016 Junior Group T2

Problem Description

In daily life, a unique date can be represented by the three elements of year, month, and day.

Cow Cow prefers to represent a date with an 8-digit number, 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 method, and two different dates will not have the same representation.

Cow Cow considers a date to be a palindrome if and only if the 8-digit number representing the date is a palindrome. Now, Cow Cow wants to know how many palindrome dates exist between two specified dates (including the dates themselves).

An 8-digit number is a palindrome if and only if for all \( i \) ( \( 1 \le i \le 8 \) ), the \( i \)-th digit from the left is the same as the \( i \)-th digit from the right.

For example:

  • For January 19, 2016, represented as 20161119, it is not a palindrome.
  • For January 2, 2010, represented as 20100102, it is a palindrome.
  • For October 2, 2010, represented as 20101002, it is not a palindrome.

Each year has 12 months:

  • Months 1, 3, 5, 7, 8, 10, and 12 each have 31 days.
  • Months 4, 6, 9, and 11 each have 30 days.
  • February has 29 days in a leap year and 28 days in a common year.

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

  1. The year is a multiple of 4 but not a multiple of 100.
  2. The year is a multiple of 400.

For example:

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

Input Format

Two lines, each containing an 8-digit number.

The first line represents the start date specified by Cow Cow.

The second line represents the end date specified by Cow Cow.

It is guaranteed that both \(\mathit{date}_1\) and \(\mathit{date}_2\) are valid dates, with the year part being exactly 4 digits and the first digit not being 0.

It is also guaranteed that \(\mathit{date}_1\) is not later than \(\mathit{date}_2\).

Output Format

An integer representing the number of palindrome dates between \(\mathit{date}_1\) and \(\mathit{date}_2\).

Sample Input and Output

Input Sample #1

20110101
20111231

Output Sample #1

1

Input Sample #2

20000101
20101231

Output Sample #2

2

Notes

[Sample Explanation]

For Sample 1, the date that meets the condition is 20111102.

For Sample 2, the dates that meet the condition are 20011002 and 20100102.

[Subtasks]

For 60% of the data, \(\mathit{date}_1\) equals \(\mathit{date}_2\).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
20110101 20111231
样例输出
1