eolymp
bolt
Try our new interface for solving problems
Problems

How Many Days Are There?

How Many Days Are There?

"\textit{I’m sorry but I can’t attend the party on the 10th of this month. You know, my holidays are only on Thursdays. I have been longing for the party, but I have to give up being present there.}" "\textit{It doesn’t matter. I hope that you will be present the next time.}" Have you ever encountered such situations? No matter how regretful you are about them, you still could do nothing. So, we desire to find a way to know how many days in a period meet our demand not only of the date but of the day of week. In this problem, we consider a special calendar from ancient to future times. In the calendar, we stipulate as follows: \begin{enumerate} \item In the calendar, the year preceding \textbf{1} year \textbf{A.D.} is \textbf{1} year \textbf{B.C.} For the convention, we represent \textbf{1} year \textbf{B.C.} by \textbf{0},\textbf{2} year \textbf{B.C.} by \textbf{−1}, and so on. \item There are seven days in a week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. They occur in this order repeatedly. In the calendar, Jan. 1st, 1 year A.D. is Monday. The day of week of another date is determined consistent with Jan. 1st, 1 year A.D. \item A year divisible by \textbf{4} but not by \textbf{100} is a leap year. A year divisible by \textbf{400} is also a leap year. This rule applies to years of \textbf{B.C.} For example, \textbf{5} year \textbf{B.C.} is a leap year because that year is represented by \textbf{−4}. \item A year consists of twelve months. In January, March, May, July, August, October and December, there are 31 days each. In April, June, September and November, there are 30 days each. And in February, there are 29 days if the year is a leap year; 28 days otherwise. \item Your program should process dates from \textbf{2000000} year \textbf{B.C.} to \textbf{2000000} year \textbf{A.D.} \end{enumerate} \InputFile The input file for this problem will contain a series of data sets. Each data set will given in a line, and begin with two integers. The first integer \textbf{m} (\textbf{0} ≤ \textbf{m} ≤ \textbf{6}) is the day of week in demand, where \textbf{m = 0} represents Sunday, \textbf{m = 1 }represents Monday, \textbf{m = 2} represents Tuesday, and so on. The second integer \textbf{n} (\textbf{0} ≤ \textbf{n} ≤ \textbf{31}) is the day part of the date in demand. After that, there will be six integers, \textbf{y_1}, \textbf{m_1}, \textbf{d_1}, \textbf{y_2}, \textbf{m_2}, \textbf{d_2}. \textbf{y_1}, \textbf{m_1} and \textbf{d_1} are the year part, the month part and the day part of the start date, and \textbf{y_2}, \textbf{m_2} and \textbf{d_2} are the year part, the month part and the day part of the end date. You may assume that the start date and the end date will conform to the calendar. The end date will not be earlier than the start date. The end of input is signified by a line which contains two zeros. This line should not be processed. \OutputFile The output for each data set should include a line containing a integer which tells how many days conform to our demands from the start date to the end date (including the start date and the end date). Here, we say the date conform to our demands if the day of week of a date equals to m and the day part of this date equals to n. You should not print any more whitespaces or blank lines in the output.
Time limit 1 second
Memory limit 64 MiB
Input example #1
0 28 1999 11 18 1999 11 28
5 28 1999 11 18 1999 11 28
5 13 1999 1 1 1999 12 31
0 30 1976 6 30 1999 11 28
0 0
Output example #1
1
0
1
35
Source ACM International Collegiate Programming Contest, Summer Camp (2nd Day), Tokyo, 2005–9–24