18. Count the Sundays

Difficulty: easy · Math

Problem

Jack loves Sundays. A month can start on any day of the week. Given the day the month starts on and a number `n`, count how many Sundays Jack gets **within the next `n` days**, where the starting day is day 0 and the days considered are day 0, day 1, ..., day `n`. For example, if the month starts on Monday (`mon`) and `n = 13`, the first Sunday is 6 days later (day 6) and the next is 7 days after that (day 13), so Jack gets 2 Sundays.

Input

- Line 1: the starting day, one of `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun`. - Line 2: the integer `n`.

Output

Print the number of Sundays among days 0 to `n`.

Example 1

Input:
mon
13
Output:
2

Explanation: Sundays fall on day 6 and day 13 after Monday; both are within days 0..13, so the answer is 2.

Example 2

Input:
sun
6
Output:
1

Explanation: The start day itself (day 0) is a Sunday; the next is day 7, outside the window, so the answer is 1.

Example 3

Input:
tue
4
Output:
0

Explanation: From Tuesday the first Sunday is day 5, which is beyond day 4, so the answer is 0.

Constraints

- 0 <= n <= 10^9

Solutions are judged against 3 sample and 11 hidden tests. Sign in to solve it · All problems