← Back to Problems
High-Water Mark
Easy standard Martingales & Stopping
Time limit: 1 s per test  ·  Memory: 256 MB

A book's PnL follows a random walk: each day it moves +1 with probability p and -1 with probability 1 - p, independently, starting at 0. The game is losing: p < 1/2. You trade forever.

Compute the probability that the PnL ever reaches the level a > 0.

Input

Two values p and ap with at most 6 digits after the decimal point, a an integer.

Output

One real number: the probability that the PnL ever reaches a, with relative error at most 1e-9. Note that the probability can be extremely small; your output must be relatively accurate, not just close to zero.

Constraints

0.05 <= p <= 0.499999

1 <= a <= 150

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Numeric answers are accepted if they are within a relative tolerance of 1e-09 of the expected value.

Examples

input
0.25 2
output
1.111111111111111e-01
input
0.4 5
output
1.316872427983540e-01
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2