Schedule
Time limit2sMemory limit1024 MB
Given a year, the weekday of January 1, and a list of public holidays, find the day off that gives the most days off and the one that gives the fewest.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Statement
Ilya is tired of studying. First came school, then university. Finally the day has come when he does not have to go to classes in the morning. But the hardest part is still ahead: after university he has to find a job.
Ilya joined Goondex, a well-known company where employees are expected to work hard. Staff work a six-day week. As a bonus, every year Goondex lets each employee choose any day of the week as a day off. The remaining six days are workdays.
Ilya noticed that public holidays (which are always days off) change the picture. Depending on which weekday he picks as his day off, the number of workdays in a year changes. He wants to know which weekday to choose to rest as many days as possible, or, on the contrary, to work as many days as possible.
Input
The first line contains one integer N (0 ≤ N ≤ 366), the number of public holidays.
The second line contains one integer year (1800 ≤ year ≤ 2100), the year in which Ilya needs help.
Each of the next N lines contains a day and a month separated by exactly one space, meaning that day day of the month month is a public holiday. Here month is the English name of the month.
The last line contains the word day_of_week, the weekday of January 1 of year.
All dates are valid, the given weekday of January 1 is correct, and all holidays fall on different days.
Output
Print two weekdays separated by a space: the best choice for the day off (the weekday that gives the maximum number of days off in the year), then the worst choice (the weekday that gives the minimum). If several answers are possible, print any of them.
Note
Look at the third sample in detail. The year 2013 starts and ends on a Tuesday. Tuesday occurs 53 times in the year, and every other weekday occurs 52 times. All three holidays fall on a Wednesday.
If Ilya picks Tuesday as his day off, he gets 53 + 3 = 56 days off (53 Tuesdays and 3 holidays). If he picks Wednesday, he gets only 52 days off. If he picks any other day, he gets 52 + 3 = 55 days off.
So the best choice is Tuesday and the worst is Wednesday. The only correct answer for this sample is Tuesday Wednesday.
Reference
February has 29 days only in leap years. A year is a leap year if it is divisible by 400, or divisible by 4 and not divisible by 100. For example, 1996 and 2000 are leap years, while 1999 and 1900 are not.