Under construction

Still being built. Things may change

Weekend Gardening

Interview

Time limit1sMemory limit1024 MB

Summary
Find the probability that buying plants one at a time, each drawn from the remaining stock, keeps the running total within the budget range from L to H.
Level

Medium5 of 10

Topics
Dynamic programming, Probability
Solved
No attempts yet

Problem

Your roommate is planning weekend projects to make the yard look better. The plan is to buy some plants. Your roommate wants to spend at least LL dollars and at most HH dollars. There are three types of plants: cheap, normal, and expensive. You cannot tell the difference just by looking at a plant. Each type has a different cost, and you know how many of each type the local nursery has in stock.

You walk through the nursery aisles, pick out a plant, bring it to the clerk to be rung up, and repeat. You want your total cost to stay within the desired budget range. If the total is too low or too high, your roommate will get frustrated.

Given the cost and stock of each plant type along with the budget range, determine the probability that you can buy plants one at a time and stay within the total cost range.

Input

The first line contains two integers LL and HH (1≤L≤H≤1091 \le L \le H \le 10^9), the low and high ends of the budget.

The second line contains three integers CC, NN, and EE (1≤C<N<E≤1091 \le C < N < E \le 10^9), the costs of the cheap, normal, and expensive plants.

The third line contains three integers cc, nn, and ee (1≤c,n,e≤1001 \le c, n, e \le 100), the number of cheap, normal, and expensive plants in stock.

Output

Print the probability that you successfully complete the purchase within the desired budget by choosing plants one at a time. Your answer is accepted if it is within 10−610^{-6} of the correct answer.

Examples2

  1. Example 1

    Input
    30 60
    5 15 70
    3 1 1
    
    Expected output
    0.2
    
  2. Example 2

    Input
    40 60
    5 15 70
    3 1 1
    
    Expected output
    0.0