Description

Serve soup from A and B with 4 operations of different portions. Return probability A empties first + 0.5 * probability both empty together.

Examples

Input:n = 50
Output:0.625
Explanation:

Calculated probability.

Input:n = 0
Output:0.5
Explanation:

When n = 0, both soups are already empty, so they empty simultaneously. The probability of A emptying first is 0, plus half the probability of simultaneous emptying (which is 1), giving us 0.5.

Input:n = 25
Output:0.5625
Explanation:

With n = 25, there are a smaller soup amount than the existing examples. The probability calculation considers all possible serving combinations, and with fewer total servings possible, soup A has a moderate advantage in emptying first or simultaneously.

Constraints

  • 0 ≤ n ≤ 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!