Invested Money
InterviewTime limit0.1sMemory limit1024 MB
Given today's weekday and how many days ago each deposit was made, find the fewest days until a deposit renews, where renewals never fall on weekends.
- Level
Easy3 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Statement
Nowadays your programming skills are amazing, and you regularly receive lots of money for your work. Your financial skills did not keep up, though. So each time you earn money, you put it in a bank as a 30-day time deposit with an automatic renewal clause. Thirty days after you invest, the money is invested for another 30 days, over and over, until you tell the bank to stop renewing and return your money.
Time deposits cannot be created or renewed on weekends. If a 30-day period ends on a weekend, the renewal happens on the next Monday.
Suppose today is Saturday and you created five time deposits: one last Monday, one last Tuesday, one last Wednesday, and two yesterday. The Monday deposit renews on Wednesday, 25 days from today. The Tuesday deposit renews on Thursday after 26 days, and the Wednesday deposit renews on Friday after 27 days. The two Friday deposits would renew on Sunday after 30 days, but renewals on Sunday are not allowed, so they renew on Monday. In this case, you must wait 25 days to get money from the bank.
Since the bank holds almost all your money, you must wait until the closest renewal whenever you want to buy anything other than daily food. Today you decided to buy a new smartphone to replace your six-month-old device. Given the dates when you created each deposit, find the minimum number of days you must wait to get money from the bank.
Input
The first line contains a string T and an integer N (), today's day of the week and the number of time deposits. T is one of "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", or "Sun", representing Monday through Sunday.
The second line contains N integers D1, D2, ..., DN (), the number of days elapsed since each deposit was created. No deposit was created on a weekend.
Output
Print one integer, the minimum number of days you must wait to get money from the bank.