Last super-last one P95909


Statement
 

pdf   zip

thehtml

Professor Oak is very strict. However, his two nieces are not aware of this fact. So, when he says “últim” (Catalan word for “last one”), this means in practice “not the last time” (that his nieces are doing whatever they are doing). When he says “superúltim”, this means “maybe the last time” (with probability ℓ1, typically small). And when he says “últimsuperúltim”, this also means “maybe the last time” (but with probability ℓ2 > ℓ1).

Supose that Prof. ‍Oak says “últim”, “superúltim” and “últimsuperúltim” with independent probabilities p1, p2 and p3 = 1 − p1p2, respectively, until their nieces stop. How many phonemes will Prof. ‍Oak need to say on the average? Take into account that, for all those Catalan words, each letter corresponds to one phoneme.

Input

Input consists of several cases, each one with the probabilities ℓ1, ℓ2, p1 and p2. Assume 0 < ℓ1 < ℓ2 ≤ 1, 0 ≤ p1 < 1, 0 ≤ p2 ≤ 1, and p1 + p2 ≤ 1.

Output

For every given case, print with three digits after the decimal point the expected number of phonemes said by Prof. ‍Oak. The input cases do not have precision issues.

Public test cases
  • Input

    0.5 1 0 0
    0.2 0.6 0.6 0.3
    

    Output

    15.000
    62.500
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++