Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 6 点
問題文
あなたは、毎週土曜日と日曜日に必ず 1 個ずつりんごを食べます。それ以外の日にはりんごを食べません。
2 つの日付 S,T が YYYY-MM-DD
形式で与えられるので、S から T までの期間(S 及び T も含む)に何個のりんごを食べることにな るか求めてください。
なお、必要であれば、以下の事実を用いても構いません。
- 2022 年 1 月 1 日は土曜日
- 次のいずれかの条件を満たすとき、かつ、そのときに限り X 年はうるう年
- X が 4 の倍数であり、かつ、100 の倍数でない
- X が 400 の倍数
YYYY-MM-DD
形式とは
年を表す 4 桁の整数、月を表す 2 桁の整数、日を表す 2 桁の整数を、この順に -
区切りで繋げたものを YYYY-MM-DD
形式といいます。
ただし、月や日が 1 桁のときは、上位に 0 を付けて 2 桁とします。
例えば、4567 年 1 月 23 日を YYYY-MM-DD
形式で表すと 4567-01-23
となります。
制約
- S,T は 2022 年 1 月 1 日以降 9999 年 12 月 31 日以前の有効な日付を
YYYY-MM-DD
形式で表したものである - T は S 以降の日付を表す
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
答えを出力せよ。
入力例 1
2022-01-01 2022-01-08
出力例 1
3
与えられた期間のうち 2022 年 1 月 1,2,8 日にそれぞれりんごを 1 個ずつ食べます。
入力例 2
2024-02-26 2024-03-02
出力例 2
1
うるう年に注意してください。
入力例 3
2022-01-01 9999-12-31
出力例 3
832544
Score : 6 points
Problem Statement
You eat an apple every Saturday and Sunday. You do not eat one any other day.
Given two dates S and T in YYYY-MM-DD
format, find the number of apples you eat between S and T (inclusive).
Here are some facts that may be useful.
- January 1, 2022 is Saturday.
- The year X is a leap year if and only if one of the following is satisfied.
- X is a multiple of 4 but not a multiple of 100
- X is a multiple of 400
What is YYYY-MM-DD
format?
YYYY-MM-DD
format is a concatenation of a 4-digit integer representing the year, a 2-digit integer representing the month, and a 2-digit integer representing the day, in this order, separated by -
.
Here, the month and the day are zero-padded to two digits.
For example, January 23, 4567 in YYYY-MM-DD
format is 4567-01-23
.
Constraints
- S and T are valid dates between January 1, 2022 and December 31, 9999 (inclusive) in
YYYY-MM-DD
format. - T is not earlier than S.
Input
Input is given from Standard Input in the following format:
S T
Output
Print the answer.
Sample Input 1
2022-01-01 2022-01-08
Sample Output 1
3
During the given period, you eat an apple on January 1, 2, and 8 in 2022.
Sample Input 2
2024-02-26 2024-03-02
Sample Output 2
1
Beware the leap years.
Sample Input 3
2022-01-01 9999-12-31
Sample Output 3
832544