# Contracting gas P33955

Statement

thehtml

Some time ago, professor Oak bought an old flat that had no gas contract. What follows is a simpliflied model of the nightmare that he had to suffer.

To acquire gas, you need two papers: one from the gas distributor, and another from the gas marketer. Initially, you have none of them. When you try to get a paper from the distributor, you will get it with probability pd. However, if you already have a paper from the marketer, you will lose it with probability qm (the distributor will decide that it is not good enough). Simetrically, when you try to get a paper from the marketer, you will get it with probability ‍pm. However, if you already have a paper from the distributor, you will lose it with probability qd. You spend a whole day every time that you try to get a paper. You win this stupid game when you first manage to have a valid paper from both the distributor and the marketer.

Given all this information, and assuming an optimal strategy, what is the expected number of days to get both papers and therefore gas?

Input

Input consists of several cases, each with pd, qm, pm and qd in this order. All the probabilities are real numbers with at most two digits after the decimal point. Additionally, pd and pm are at least 0.1, and qm and qd are at most 0.9.

Output

For every case, print with four digits after the decimal point the optimal expected number of days to get gas. The input cases have no precision issues.

Public test cases
• Input

```1 0 1 0
1 0 1 0.5
0.23 0.5 0.42 0.9
0.1 0.9 0.1 0.9
```

Output

```2.0000
2.0000
20.6156
920.0000
```
• Information
Author
Salvador Roura
Language
English
Official solutions
C++
User solutions
C++