|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||0||0||0||0.000%|
“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.”
“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:
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 m (0 ≤ m ≤ 6) is the day of week in demand, where m = 0 represents Sunday, m = 1 represents Monday, m = 2 represents Tuesday, and so on. The second integer n (0 ≤ n ≤ 31) is the day part of the date in demand. After that, there will be six integers, y1, m1, d1, y2, m2, d2. y1, m1 and d1 are the year part, the month part and the day part of the start date, and y2, m2 and d2 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.
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.
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
1 0 1 35