Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
Input
The only line of the input is in one of the following two formats:
"x of week" where x (1 ≤ x ≤ 7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday.
"x of month" where x (1 ≤ x ≤ 31) denotes the day of the month.
Output
Print one integer — the number of candies Limak will save in the year 2016.
Examples
Input
4 of week
Output
52
Input
30 of month
Output
11
Note
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – https://en.wikipedia.org/wiki/Gregorian_calendar. The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are given a problem: "Limak and a New Year 2016". The input is a string in one of two formats: "x of week" or "x of month". For week: x is between 1 and 7 representing Monday to Sunday. For month: x is between 1 and 31 representing day of month.
We need to output number of candies Limak will save in the year 2016. That is: How many times does that day occur in 2016? If it's a weekday (x of week), then answer is number of that weekday in 2016. Since 2016 is a leap year (2016 is divisible by 4? Actually Gregorian: leap year if divisible by 4 but not by 100 unless divisible by 400. 2016 is divisible by 4, not by 100, so yes leap year). So year 2016 has 366 days. The day of week for Jan 1, 2016? We can compute: We know that Jan 1, 2016 is a Friday? Let's check: 2015 Jan 1 was Thursday? Actually we can compute. But easier: Since the problem statement says "Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015." So today is Wednesday and tomorrow is Dec 31, 2015? If tomorrow is last day of 2015, then tomorrow is Dec 31, 2015. So today is Dec 30, 2015. Dec 30, 2015 is Wednesday. So we can compute day of week for Jan 1, 2016. Dec 31, 2015 is Thursday (since Dec 30 Wednesday, Dec 31 Thursday). So Jan 1, 2016 is Friday (since after Dec 31, Thursday comes Friday). So Jan 1, 2016 is Friday. That matches known calendar: 2016 started on Friday. Good.
Thus weekdays: We need mapping: Monday = 1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6, Sunday=7. Jan 1 is Friday = day 5. So we can compute number of occurrences of a particular weekday in 2016. Since year length 366 = 52 weeks + 2 days (because 52*7=364, plus 2 extra days). The first day of the year (Friday) occurs 53 times if the weekday is among the first two days of the year? Actually a year of 366 days: It starts on a certain day (Friday, day5). Then there are 52 complete weeks (364 days) plus two extra days: day5 (Friday) and day6 (Saturday) as the extra days? Let's list: Day 1 = Friday (5), day 2 = Saturday (6), day 3 = Sunday (7), day 4 = Monday (1), etc. After 364 days (52 weeks), the day of the week is again Friday? Actually after 364 days, it's exactly 52 weeks later, so the next day (day 365) would be the same weekday as day 1 (Friday). So the two extra days beyond 52 weeks are day 365 and day 366. Day 365 = Friday (5), day 366 = Saturday (6). So the weekdays that appear 53 times in a leap year are the weekday of the first day (Friday) and the weekday of the second day (Saturday). Actually more precisely: In a 366-day year, the distribution: The weekday of Jan 1 appears 53 times (since it appears on day1, then after 7 days, ... plus the extra day 365). The weekday of Jan 2 appears also 53 times (since it appears on day2 and day366). All other weekdays appear 52 times. So for 2016, weekdays: Friday (5) and Saturday (6) appear 53 times, others 52 times. Check: Monday? Jan 1 Friday, so Monday is day 4? Actually Jan 4 is Monday. So Monday appears 52 times? Let's compute: Number of Mondays in 2016: there are 52 weeks = 52 Mondays. Plus, does the extra days (365,366) include Monday? No, they are Fri and Sat. So Monday appears 52 times. So answer for week: if x=5 or x=6, output 53; else 52.
Now for month: "x of month". Need number of months in 2016 that have a day x. Since months have different lengths: Jan 31, Feb 29 (leap year), Mar 31, Apr 30, May 31, Jun 30, Jul 31, Aug 31, Sep 30, Oct 31, Nov 30, Dec 31. So we count months where x <= month's days. For x = 1..31. But we need to output count.
For x <= 28: all months have at least 28 days? Actually February has 28? Actually February 2016 has 29 days because leap year. So for x <= 29, February has day x. So for x <= 29, all 12 months include day x? Wait, not exactly: For x = 29, February has day 29, so yes, 12 months? But what about months with 30 days? They have days 1-30, so include 29. Months with 31 include 29. So for x=29, all months have day 29? Actually check: February has 29 days, so yes. So for x from 1 to 29 inclusive, all 12 months have that day? But wait: February only has 29 days, so for x=29 it's included. So indeed for x <= 29, all months have that day. However, is it always 12? For x=30: Months with at least 30 days: All except February. February has 29 days, so for x=30, February doesn't have day 30. So count = 11 (Jan, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec? Wait, April, June, September, November have 30 days, they have day 30. Jan, Mar, May, Jul, Aug, Oct, Dec have 31, they have day 30. So that's 11 months: all except February). For x=31: Only months with 31 days: Jan, Mar, May, Jul, Aug, Oct, Dec = 7 months.
But careful: In a leap year, February has 29 days. So the threshold is: For x between 1 and 29 inclusive, all 12 months have that day? But check: Does February have day 29? Yes, since 29 days. So yes, 12. For x=30: 11 months. For x=31: 7 months.
But the input constraints: x of month: 1 ≤ x ≤ 31. So the answer can be 12, 11, or 7. But is there any scenario where x=1-28 yields 12? Yes. However, note: Are there any months that have less than 28 days? No, all months have at least 28 days. So for x <= 28, definitely all months have that day, so 12. For x=29: In non-leap years, February has 28 days, so for x=29 count would be 11. But here year is 2016 which is leap year, so February has 29 days. So count = 12 for x=29 as well. So we need to treat it accordingly.
So answer: If "of week": if x == 5 or x == 6: 53 else 52. If "of month": if x <= 29: 12 else if x == 30: 11 else if x == 31: 7. However, note: x can be 29, 30, 31. Check for x=29: yes 12. x=30: 11. x=31: 7. But is x=30 always 11? In any year? But specifically for 2016, it's 11. So correct.
Edge cases: x=29 but is it possible that x=29 and month February has 29 days, so indeed 12. So answer.
Now we need to parse input. Input format: a line containing something like "4 of week" or "30 of month". So we read the line, we can split by spaces. The first token is x (as integer). Then "of", then "week" or "month". So we need to detect which. The third token is either "week" or "month". So we can check.
But careful: The line may have trailing newline. We can read full line and parse.
Thus solution: read line, split into parts. Let parts = s.split(). Then x = int(parts[0]), type = parts[2] (since parts[0] is x, parts[1] is "of", parts[2] is either "week" or "month"). Alternatively, we can just check if "week" in s or "month" in s, but parse properly.
Then compute answer.
But we should also consider: For "of week", x is 1 to 7. Could there be a case where x=5 or x=6? Yes.
Now I'll produce code accordingly.
But wait: We need to double-check the day-of-week mapping. The problem says Monday is 1, Sunday is 7. Jan 1, 2016 is Friday. Friday is day 5? Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6, Sunday=7. So yes.
Number of Fridays in 2016: Actually we counted Friday appears 53 times. Let's quickly verify: 2016 has 366 days. The first day is Friday. So there are 52 full weeks (364 days) which includes 52 Fridays. Then the extra two days: Friday and Saturday. So total Fridays = 53, Saturdays = 53, others = 52. So correct.
But is there any nuance about weeks? The problem says week starts with Monday. That matches mapping.
Thus answer for week: if x == 5 or x == 6 -> 53 else 52.
Now for month: x of month. Count months with day x. The month lengths: 31, 29 (Feb), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31. So indeed.
So final answer.
But one more thing: Could there be a case x=30 in month where we count 11? Actually what about April (30 days) includes day 30. So 30 is valid. All months except Feb. So 11. x=31: months with 31 days: Jan, Mar, May, Jul, Aug, Oct, Dec = 7. So correct.
Now code.
Implementation:
def solve():
import sys
s = sys.stdin.readline().strip()
parts = s.split()
x = int(parts[0])
typ = parts[2] # "week" or "month"
if typ == "week":
if x == 5 or x == 6:
print(53)
else:
print(52)
else: # month
if x <= 29:
print(12)
elif x == 30:
print(11)
else:
print(7)
But careful: Actually for month, x <= 28 -> 12, x=29 -> 12 (since leap year), x=30 -> 11, x=31 -> 7. So condition x <= 29 yields 12. That's fine.
Double-check: If x=29, 12. But is there any month that has less than 29 days? In a leap year February has 29, so yes. So 12.
Test with given examples:
Input: "4 of week" -> x=4, typ="week" -> not 5 or 6 -> 52, matches.
Input: "30 of month" -> x=30, typ="month" -> x == 30 -> print 11, matches.
Edge test: "5 of week" -> 53. "6 of week" -> 53. "7 of week" -> 52 (Sunday). "1 of week" -> 52 (Monday). etc.
Test: "31 of month" -> 7. "29 of month" -> 12. "28 of month" -> 12. "1 of month" -> 12.
Check if any month has day 0? Not allowed.
All good.
Now we could also compute by actual calendar but this is simpler.
But maybe we need to consider if input is "x of week" and x is 1-7, output could be 52 or 53 based on year. Our reasoning is correct.
Thus finalize.
However, ensure we parse correctly: If input has spaces, split works. In some languages, we need to handle newline. Python fine.
Now produce final solution.
But note: The problem statement says "The only line of the input is in one of the following two formats: * "x of week" where x (1 ≤ x ≤ 7) denotes the day of the week. * "x of month" where x (1 ≤ x ≤ 31) denotes the day of the month."
So format is exactly that. So parse accordingly.
Now I will produce final answer with explanation.
Also note: Could there be leading/trailing spaces? Might not, but strip handles.
Thus final code.
Will output.
Now check with more test: "1 of week" -> Monday, output 52? Is that correct? Let's manually: In 2016, first Monday is Jan 4? Actually Jan 1 Friday, so Monday Jan 4. Number of Mondays: 52? Since total days 366, weeks 52 plus 2 days, extra days Fri and Sat, so Monday not among extra days, so 52. Yes.
"2 of week" -> Tuesday, 52. "3 of week" -> Wednesday, 52. "4 of week" -> Thursday, 52. "5 of week" -> Friday, 53. "6 of week" -> Saturday, 53. "7 of week" -> Sunday, 52? Check Sunday: Jan 3 is Sunday? Actually Jan 1 Friday, Jan 2 Saturday, Jan 3 Sunday. So Sunday appears 52? There are 52 Sundays plus? Extra days Fri, Sat, so no extra Sunday, so 52. Yes.
Now for month: "29 of month" -> output 12. But if we consider non-leap year, it would be 11. So correct.
Thus solution.
Edge: x=0? not allowed.
Alright.
Now output final answer.
Will produce solution explanation and code.
Note: The problem is from Codeforces Round #348? But that's fine.
I'll output final solution.
Also, sometimes they might require considering if x=29 for month in leap year: 12. So fine.
One might also compute using datetime, but easier with conditional.
Thus final.
Now produce final answer. ```python
import sys
def solve() -> None:
line = sys.stdin.readline().strip()
parts = line.split()
x = int(parts[0])
typ = parts[2] # "week" or "month"
code
if typ == "week":
# Monday = 1, Tuesday = 2, ..., Sunday = 7
# In 2016 (leap year, starts on Friday) Friday (5) and Saturday (6) occur 53 times
if x == 5 or x == 6:
print(53)
else:
print(52)
else: # month
# 2016 is a leap year: February has 29 days
if x <= 29:
print(12) # all months have this day
elif x == 30:
print(11) # all months except February
else: # x == 31
print(7) # only months with 31 days: Jan, Mar, May, Jul, Aug, Oct, Dec