Under construction

Still being built. Things may change

Expected Flight Delay

Time limit1sMemory limit1024 MB

Summary
Given the meeting weekday, weekday and weekend flight success rates, and a required on-time probability, find the earliest departure day that reaches it.
Level

Medium4 of 10

Topics
Math, Probability, Simulation
Solved
No attempts yet

Problem

Once upon a time, there was a businesswoman named Grace who lived in New York City, New York and frequently traveled to Des Moines, Iowa on a regular daily flight for work. Unfortunately, there was one big problem: flights from New York to Des Moines were notoriously unreliable, especially on weekends. The weather, maintenance issues, and other unpredictable factors always seemed to interfere.

Grace knew from her previous experiences that it would be very handy to have an app that would let her enter the day of the week of an upcoming meeting, the importance of arriving on time (she arrives on time if she successfully departs the day before, at the latest), and the probabilities of successfully flying out on weekdays (Monday-Friday) and on weekends (Saturday-Sunday). This would help her decide what day to schedule her flight in order to have confidence that she could reach Des Moines on time. Since her skills in programming and knowledge of probability are somewhat lacking, she is asking you to come up with the app.

As an example, suppose the meeting date is a Monday. Let the chance of success on weekdays be pwday=80%p_{\mathrm{wday}}=80\%, and on weekends be pwend=60%p_{\mathrm{wend}}=60\%. Let the importance of getting to the meeting on time be 90%90\% certainty. If Grace tries to fly on Sunday, the chance of her making it on time would simply be 60%60\%. Not great, and not the 90%90\% assurance she wants, either. Perhaps flying on Saturday instead will work. This way, if Saturday's flight is canceled, she could still try again on Sunday.

The probability of her leaving by Sunday in this case would be 60%60\% (chance of Saturday's flight being good) + 40%40\% (chance of Saturday's flight being bad) ⋅60%\cdot 60\% (chance of Sunday's flight being good) = 84%84\%. That is still not good enough.

If we add Friday as an option and calculate the probability Grace leaves by Sunday given the weekday 80%80\% chance of success, we get 0.8+0.2⋅0.6+0.2⋅0.4⋅0.6=96.8%0.8 + 0.2 \cdot 0.6 + 0.2 \cdot 0.4 \cdot 0.6 = 96.8\%. That is sufficient for Grace.

Input

The only line of input contains four space-separated integers. The first is in the range [1,7][1,7] and gives the meeting day of the week, with 11 for Sunday, 22 for Monday, and so on. The next two integers are the percentage chances of successful flights on weekdays and weekends, pwdayp_{\mathrm{wday}} and pwendp_{\mathrm{wend}} (0≤pwday,pwend≤1000 \leq p_{\mathrm{wday}}, p_{\mathrm{wend}} \leq 100). At least one of pwdayp_{\mathrm{wday}} and pwendp_{\mathrm{wend}} is nonzero. The fourth is the importance factor of making the meeting on time, pimpp_{\mathrm{imp}}, as a percentage (1≤pimp≤991 \leq p_{\mathrm{imp}} \leq 99).

Let p(i)p(i) be the percent chance that Grace makes it to her meeting on time if she starts trying to fly there ii days before the meeting. It is guaranteed that min⁡i≥1∣p(i)−pimp∣>10−6\min_{i \geq 1} |p(i) - p_{\mathrm{imp}}| > 10^{-6}.

Output

Print a string of the form Try to leave on DEPDAY, N days before the MEETDAY meeting. DEPDAY is the day of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) closest to the meeting date on which to schedule the flight so that the percent chance of Grace making the meeting is at least pimpp_{\mathrm{imp}}. N is the number of days before the meeting day to leave. Grace may need to leave more than 7 days early to meet the importance factor requirement. MEETDAY is the day of the week of the meeting. Print day instead of days if N is 1.

Examples2

  1. Example 1

    Input
    2 80 60 90
    
    Expected output
    Try to leave on Friday, 3 days before the Monday meeting.
    
  2. Example 2

    Input
    1 40 60 10
    
    Expected output
    Try to leave on Saturday, 1 day before the Sunday meeting.