We need to compute expected number of people on escalator after t seconds, given: n people in queue initially, at each second, with probability p the first person enters the escalator (if there is still someone in queue); with probability 1-p nothing happens (the first person does not move). However note: "In one second only one person can enter the escalator." So if first person enters, they are removed from queue and added to escalator. After that, in subsequent seconds, the next person becomes first, and the process repeats. If there are no people left in queue (all have entered), then nothing else happens? Probably no more entries. But t seconds pass regardless. So we need expected number on escalator after t seconds.
We have parameters: n ≤ 2000, t ≤ 2000. p is real with two decimals.
We need expected value: sum_{i=1}^{n} P(person i has entered by time t). Since each person enters only after all previous have entered. Actually person i enters exactly at the time when the i-th successful "entry" event occurs (with probability p each second, but only if queue not empty). However the process is that we attempt each second: with prob p, if queue not empty, one person enters (the first). So essentially we have a sequence of t independent Bernoulli trials (with success prob p), but successes are "useful" only until n successes have occurred; after that, further successes don't matter because queue empty. So number of people entered by time t is min( S_t, n ) where S_t is number of successes among t trials. But careful: Is it exactly that? Because each second we attempt: if success, and if queue non-empty, then one enters. If queue empty, then successes are irrelevant. However if queue empty before t, further successes do not add people. So indeed number of people on escalator after t seconds is min( X, n ), where X ~ Binomial(t, p) but with the twist that if X > n, we cap at n. So expected value = E[ min( Bin(t,p), n ) ].
But wait: Is it exactly Binomial? Consider that after each success, the queue shrinks. However the success probability p is constant and independent of queue state? The description: "at each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him." So each second, we look at the first person; with prob p he enters; else nothing. This is exactly a sequence of independent Bernoulli trials with probability p each second, but only until the queue empties. However if the queue becomes empty before t, then there is no "first person" to attempt; but the process description might imply that after queue is empty, there is no one to attempt? The description says "at each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p)". If there is no person, then the "first person" doesn't exist. However we could interpret that when the queue is empty, nothing happens (no entries). But the process description says at each second either ...; if no one, maybe we consider that the first person does not exist, so maybe the event doesn't happen? Usually such problems treat it as after all n have entered, no more entries occur. And the trials for remaining seconds become irrelevant because there is no one to attempt. So indeed the number of entries after t seconds is the number of successes in t independent attempts, but limited by n. But careful: Are the trials independent of the state? The process: At each second, if there is a person, we flip a coin with prob p to decide if they enter. If no person, we simply do nothing. So the count of entries up to time t is the number of successes among the first min(t, T) trials where T is the time when n successes occurred? Actually it's simpler: Since attempts are made only when there is a person, and after the queue empties we stop attempting (or attempts yield no entry). So the total number of entries after t seconds is the number of successes in a sequence of t independent Bernoulli(p) trials, but only the first n successes are counted (since after n successes, queue empty, further successes don't add). So it's min( number of successes in t trials, n). Therefore E = sum_{k=0}^{t} min(k,n) * C(t,k) p^k (1-p)^{t-k}.
But note: This formula assumes that even after queue is empty, we still consider trials? Actually if queue empty, there is no person, so the coin flip is not performed? However it's equivalent to having trials but they can't produce entries. But the process description might be interpreted differently: At each second, regardless of whether there is a queue, we still have a chance that the first person enters. If there is no person, that event is impossible; so maybe the process just does nothing. In that case, the probability distribution of entries is indeed min( S_t, n ) where S_t ~ Bin(t,p) if we imagine that we still "attempt" and get success with prob p, but success when queue empty doesn't count. That yields the same distribution as a process where we stop flipping coins after n successes? Actually, if we stop flipping after n successes, the total number of entries after t seconds would be exactly n if t >= the time to get n successes, else the number of successes within t trials. That is exactly min(S_{t}, n) if we define S_{t} as the number of successes if we continued flipping? But if we stop flipping after n successes, then the later trials are not performed, so the total number of trials is not t but something else. However the problem states that at each second exactly one of the two possibilities occurs. It says "either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p)". This implies that there is always a first person? But after everyone has entered, there is no one in queue, so "the first person" doesn't exist. Perhaps they assume that after all have entered, the process ends? But they ask after t seconds, and t can be larger than the time needed to board all n. So we need to consider the state after t seconds even if all have boarded earlier. In that case, for the remaining seconds, there is no queue, so the first person doesn't exist, and the description's alternatives don't apply. Typically in such queueing models, after queue empty, nothing happens. So the escalator load after t seconds is simply the number of people that have boarded within the first t seconds, which is min( number of successes among the Bernoulli trials that actually occur, n). But the number of Bernoulli trials that actually occur is limited: we only have trials as long as there are people waiting. Once all have boarded, no further trials occur. So the total number of entries is the number of successes in a random number of trials (which is the time until n successes, capped at t). Actually, the process evolves as: we have a sequence of seconds. At second 1: if queue nonempty, we attempt with prob p to board. Continue. So the number of attempts made up to time t is exactly min( τ, t ), where τ is the time when the queue becomes empty (i.e., after n successes have occurred). Actually, the queue becomes empty after the n-th boarding occurs. At the moment after that boarding, there is no first person. So for seconds after that, no attempts. So the number of attempts = min( time of n-th success - 1? Wait: Let's define: At each second, if queue nonempty, we perform a trial. Let T be the total number of seconds from start until the queue becomes empty (i.e., the time when the n-th person boards). At that second, we attempt and board, and after that second the queue is empty. Then for subsequent seconds (if t > T), we have no trials. So total attempts = min(t, T). But T is a random variable: the time to get n successes in Bernoulli(p) trials (negative binomial). The number of entries after t seconds is number of successes within those min(t, T) attempts. But careful: In the attempts up to time T, we have exactly n successes (since the process stops at the n-th success). For attempts up to time t if t < T, we have some number of successes less than n. So indeed, the number of entries after t seconds is the number of successes in the first t attempts, but attempts only happen if there is a person; but if t > T, attempts only happen for T seconds, and we have exactly n successes. So the distribution of entries is: if t is less than the time to n successes, then it's the number of successes in t Bernoulli(p) trials; if t >= time to n successes, then it's n. That is exactly the capped binomial: min( S_t, n ) if we define S_t as the number of successes if we continued Bernoulli trials after queue empty? But if we continued trials after T, they would be extra trials that don't happen in reality. However min( S_t, n ) with S_t ~ Bin(t,p) yields the same distribution? Let's test: Suppose we have n=1, p=0.5, t=4. According to the process: We attempt each second until the first success, then stop. So entries after 4 seconds is 1 if success occurs at or before 4; else 0. Probability of success in first 4 attempts: 1 - (0.5)^4 = 0.9375, so expected entries = 0.9375. That matches example 2. Now compute min( Bin(4,0.5), 1 ) expected. Bin(4,0.5) distribution: P(k=0)=0.0625, k=1=0.25, k=2=0.375, k=3=0.25, k=4=0.0625. min(k,1): 0 for k=0, 1 for others. So expected = 1 - P(k=0)=0.9375. Same. So indeed the distribution matches. Because continuing trials after queue empty would add successes that are then capped at n, but they don't affect min(k,n) because min(k,n)=n for k>=n. However S_t can be > n, but the probability that S_t > n includes scenarios where we would have had more than n successes if we continued trials after empty. But in reality, after n successes we stop, so the probability of having exactly k successes in t trials (with k>n) is not possible because we stop at n. However the capped version min(S_t,n) yields n for those cases, and the probability mass for S_t>n is exactly the probability that we would have gotten at least n successes in t trials, which in reality corresponds to having n successes by time t (i.e., queue empty) — but note: In reality, if we have n successes before t, we have exactly n successes, not more. So the probability that we end with n entries is P( at least n successes in t trials )? Actually if we stop after n successes, the probability of having n entries by time t is the probability that the n-th success occurs at time ≤ t. That probability equals P( S_t >= n )? Yes, because if we have at least n successes in t independent trials, then the n-th success occurs at or before t. But does it equal exactly P(S_t >= n)? For a fixed number of trials, the event that the number of successes is at least n is equivalent to the n-th success occurring at or before the t-th trial. So yes. So the distribution of entries under the real process is: P(entries = k) = P(S_t = k) for k=0,...,n-1, and P(entries = n) = P(S_t >= n). And that's exactly the distribution of min(S_t, n). So indeed, expected entries = E[ min(S_t, n) ] with S_t ~ Bin(t,p). So we can compute directly.
Thus the problem reduces to computing sum_{k=0}^{t} min(k, n) * C(t,k) p^k (1-p)^{t-k}.
Given constraints (n,t ≤ 2000), we can compute this straightforwardly with dynamic programming or just using binomial probabilities with loops, being careful about precision. Since p is real with two decimals, we can use double.
But we must consider that t and n up to 2000, binomial coefficients C(t,k) can be large but we compute probabilities in double, which should be fine. However we need to avoid overflow/underflow. We can compute probabilities iteratively: start with prob = (1-p)^t, then for k from 0 to t-1, update prob = prob * (p/(1-p)) * (t-k)/(k+1). But careful: if p=0 or p=1, we handle separately. That should be okay.
But perhaps there is a more clever DP or closed form? But straightforward sum is O(t) = 2000, which is fine.
But wait: The problem statement says "n, t ≤ 2000". So sum up to 2000 is fine. However we need to compute binomial probabilities accurately. Using combination factorials might cause overflow if we compute factorial as integers; but we can use double and multiplicative updates.
Alternatively we could DP over time and number of people boarded. Since the process is like a Markov chain: state (i, j) where i seconds passed, j people boarded, and we have probability dp[i][j] that after i seconds exactly j have boarded (with j ≤ min(i, n)). The transition: dp[0][0]=1. For each i, if j < n, then from state (i,j), next second: with prob p, board one more => dp[i+1][j+1] += dp[i][j] * p; with prob (1-p) => dp[i+1][j] += dp[i][j]*(1-p). If j == n (all boarded), then nothing changes: dp[i+1][n] += dp[i][n] (since queue empty, no more boarding). But is that accurate? If j == n, there is no person to board, so the state remains same with probability 1. So dp[i+1][n] += dp[i][n]. That DP is O(t * n) = 4e6, which is also fine. Then expected value = sum_{j=0}^{n} j * dp[t][j] (or up to min(t,n) but n <= 2000). This DP is simple and avoids any binomial issues. It also directly models the process. But we must ensure that dp[t][n] accumulates probability from all paths that reach n at or before t. Indeed, the DP above captures that after j==n, we stay at n. So after t steps, probability that exactly j < n means that we never reached n, and j successes occurred among t trials (since after j successes, we can still have failures but no further successes because j < n, so queue nonempty, we continue attempts). So the DP yields the same distribution.
DP: dp[i][j] for i from 0 to t, j from 0 to min(i, n). Initialize dp[0][0]=1. For i from 0 to t-1:
- For each j in 0..min(i,n):
if j < n:
dp[i+1][j+1] += dp[i][j] * p;
dp[i+1][j] += dp[i][j] * (1-p);
else (j == n):
dp[i+1][n] += dp[i][j]; // stays n.
But careful: When j == n, there is no further change. So we can just add the whole probability.
This DP is O(t * n). n and t up to 2000, so t * n up to 4 million, fine. However we need only one-dimensional DP? We can maintain dp[j] over i steps, but careful with the update order: when j < n, we need to update from high j to low? Because we need dp[i][j] to compute dp[i+1][j] and dp[i+1][j+1]. If we use a 1D array representing current i, we need to update from high j downwards for the part where we add to dp[j] (since dp[j] is used both for dp[j] and dp[j+1]). But also when j == n, we need to handle separately. However easier to implement 2D array of size (t+1) x (n+1), but 2001x2001 ~ 4 million doubles, memory about 32 MB, okay. But we could also use 1D to save memory but not necessary. However 2D may be simpler.
But there is nuance: At state j = n, we don't have any branching; we just stay. So in DP update, we can treat j=n separately. For j < n, we compute transitions. For j = n, we just add dp[i][n] to dp[i+1][n]. That's it.
Expected value = sum_{j=0}^{n} j * dp[t][j].
This avoids any issues with binomial coefficients and large t.
Alternatively, we can compute using cumulative binomial distribution formulas: expected = n - sum_{k=0}^{n-1} (n - k) * P(S_t = k). But still need binomial.
DP is straightforward and likely less error-prone.
Check example 1: n=1, p=0.5, t=1. DP: dp[0][0]=1. i=0->1: j=0 (<n) -> dp[1][1] += 0.51=0.5; dp[1][0] += 0.51=0.5. Expected = 10.5 + 00.5 = 0.5. Good.
Example 2: n=1, p=0.5, t=4. dp over 4 steps. Ultimately dp[4][0] = (0.5)^4 = 0.0625, dp[4][1] = 1 - 0.0625 = 0.9375. Expected = 0.9375. Good.
Example 3: n=4, p=0.20, t=2. Compute manually: possible successes: 0,1,2. min(k,4) = k. So expected = E[ successes ] = 2 * 0.2 = 0.4. So output 0.4. Good.
So DP works.
But we need to handle p=0 and p=1 cases. p=0: always failure; dp: always stays at 0. Expected = 0. p=1: always success; dp: at each second, if j<n, then j+1. So after t seconds, j = min(t, n). Expected = min(t, n). But DP will handle that as well. However we must consider that with p=1, from state j < n, dp[i+1][j+1] gets all probability, and dp[i+1][j] gets 0. So after t steps, if t <= n, dp[t][t]=1; else if t>n, then dp[t][n]=1. Expected = min(t,n). Good.
Precision: We need error <= 1e-6. DP with double should be fine. However we must be careful about cumulative rounding. With 2000 steps, each step involves multiplying by p and (1-p). p given with two decimals, but DP may involve many multiplications. Use double should be okay.
But we could also use direct formula: E = sum_{k=1}^{min(t,n)} P(S_t >= k). Because expected value of min(S_t, n) = sum_{k=1}^{n} P(S_t >= k). Actually identity: For nonnegative integer random variable X, E[min(X,n)] = sum_{k=1}^{n} P(X >= k). Let's verify: Since min(X,n) = sum_{k=1}^{n} I(X >= k). Because each indicator contributes 1 if X>=k. Indeed, for X integer, sum_{k=1}^{n} 1_{X>=k} = number of k from 1 to n such that X >= k. If X >= n, then it's n; if X = m < n, then it's m. So yes. So E = sum_{k=1}^{n} P(S_t >= k). This might be even simpler: compute binomial tail probabilities. We can compute cumulative probabilities for k from 1 to n. But we need to compute P(S_t >= k) for each k up to n. t up to 2000, we can compute binomial probabilities using DP or using cumulative distribution function via iterative method. But we could also compute dp as before and then sum tail probabilities. But the DP approach directly yields expected value. However identity might be useful to compute faster: we could compute P(S_t >= k) for each k using recurrence on binomial distribution. But DP is simpler to implement.
Given constraints, DP is fine.
But we should consider whether we need to handle large t (2000) and n (2000) and maybe DP with 2D array of size (t+1)*(n+1) = 4e6, each double 8 bytes => 32 MB, okay. However we can optimize to 1D: maintain an array dp[0..n] for current i. Then for i from 0 to t-1, we update from j = min(i, n) down to 0. But we need to handle the case j=n: we need to add dp_cur[n] to dp_next[n] and also keep it for future iterations. However if we use in-place update from high to low, we need to be careful. Let's design 1D in-place: Let dp[j] be probability of having exactly j entries after current number of seconds i. Initially dp[0]=1. For each additional second, we want to update dp to new probabilities. The transitions: for states j < n, we move part of probability to j+1 (with prob p) and part stays at j (with prob 1-p). For state j=n, all probability stays at n. So the update can be done by iterating j from min(i, n) down to 0 (except n). For j from n-1 down to 0: we compute new_dp[j] = dp[j] * (1-p) (the part that stays) + ??? Actually if we are updating in-place from high to low, we need to consider that the incoming probability to j from j (stay) and from j-1 (via success) might be overwritten if we update in place. Better to use two arrays: cur and nxt. That is simple and memory small: two arrays of length n+1 = 2001, ~16KB. That's even better. So we can do:
cur[0..n] set to 0; cur[0]=1.
for i from 1 to t:
nxt[0..n] = 0
for j in 0..min(i-1, n):
if j < n:
nxt[j] += cur[j] * (1-p)
nxt[j+1] += cur[j] * p
else: // j == n
nxt[n] += cur[j] // because p=1? Actually if j==n, no further boarding, so state remains n with prob 1. So nxt[n] += cur[j]
cur = nxt
But we need to ensure that when j == n, we don't also apply the transition for j<n. So we can loop j=0..n-1 first, and then handle n separately. Or inside loop we check if j==n: then nxt[n] += cur[n]; else do transitions. Since cur[j] for j>i-1 is zero anyway, we can just loop j=0..n.
Now note: cur[n] accumulates over time. At each step, cur[n] receives contributions from cur[n] (stay) and from cur[n-1] (if n-1 < n, via success). But using the above separate handling, we must include both. Actually if we handle j<n separately, we would have for j=n-1: nxt[n] gets cur[n-1]*p. And then after the loop, we add cur[n] to nxt[n] (since state stays). So total nxt[n] = cur[n] + (cur[n-1]*p) + possibly also from j=n? No, that's all.
So algorithm:
Initialize cur[0]=1; all others 0.
For i from 1 to t:
nxt = array of zeros length n+1.
For j from 0 to n-1:
nxt[j] += cur[j] * (1-p)
nxt[j+1] += cur[j] * p
nxt[n] += cur[n] // state j=n stays
cur = nxt
After t iterations, compute expected = sum_{j=0}^{n} j * cur[j].
That yields correct distribution, as we maintain that after i steps, j cannot exceed min(i,n). The loop over j=0..n-1 is safe because for j > i-1, cur[j] is zero anyway. So we can loop to n-1. But we need to ensure we don't miss j = n in the transitions for staying; we add cur[n] to nxt[n] separately.
Double-check with n=1: cur[0]=1. i=1: loop j=0 to 0 (since n-1=0): nxt[0] += cur[0]*(1-p) = 1-p; nxt[1] += cur[0]p = p. Then nxt[1] += cur[1]=0. So cur becomes [1-p, p]. i=2: loop j=0..0: cur[0]=1-p, so nxt[0] += (1-p)(1-p) = (1-p)^2; nxt[1] += (1-p)p. cur[1]=p, but we also will add cur[1] to nxt[1] after loop. So nxt[1] gets from j=0: p(1-p)?? Wait careful: we have two contributions: from j=0 (cur[0] * p) and from adding cur[1] later. So nxt[1] = cur[0]*p + cur[1] = (1-p)*p + p = p(1-p) + p = p( (1-p) + 1 ) = p(2-p). But let's compute manually: After 2 seconds with n=1, probability that we have 1 is 1 - (1-p)^2 = 1 - (1-p)^2 = 2p - p^2 = p(2-p). So nxt[1] = 2p - p^2 = p(2-p). That matches. Good.
So DP works.
Alternative approach: Use binomial directly: expected = sum_{k=0}^{n-1} k * C(t,k) p^k (1-p)^{t-k} + n * (1 - sum_{k=0}^{n-1} C(t,k) p^k (1-p)^{t-k}). That is also straightforward, but we need to compute C(t,k) probabilities. Could compute via logarithms or multiplicative updates. Might be more efficient O(t) but DP is also O(t * n)? Actually DP is O(t * n) because loop over j up to n each time, so O(t * n) up to 4e6. That's fine. But the binomial sum would be O(t) only, which is even better (2000). However DP is simpler to code correctly, especially for boundary conditions. But binomial sum requires careful handling of probabilities update and maybe cumulative sum. But both are acceptable.
Given the problem constraints, DP O(t * n) is acceptable. But note: In worst case t=2000, n=2000, DP does 2000 * 2000 = 4 million iterations, each with a few floating operations. That's trivial for any modern computer. So DP is fine.
But wait: The DP described loops over j from 0 to n-1 each time, regardless of i. But for early i, cur[j] for j > i is zero. So we could loop only up to min(i, n) to save some work, but it's not necessary. But if we implement naive O(t*n) it's 4 million loops, each loop has two multiplications and two additions. That's okay.
But we must be careful about numeric stability for large t and p near 0 or 1? With double, fine.
One nuance: The DP as described uses multiplication by p and (1-p) each step. If p is given with two decimals, it's fine. However if p=0 or p=1, we must handle? It still works: if p=0, then in loop j=0..n-1: nxt[j] += cur[j] * 1; nxt[j+1] += cur[j] * 0. So nxt[j] gets cur[j]; and nxt[n] += cur[n]. So essentially all probability stays at 0 (since cur[0]=1, and nxt[0] gets cur[0]; but also nxt[1] gets 0). So after t steps, cur[0]=1, expected 0. Good. If p=1, then nxt[j] += cur[j] * 0; nxt[j+1] += cur[j] * 1; and nxt[n] += cur[n]. So probability shifts right each step until hitting n. Works.
Thus DP is robust.
We'll implement DP with two arrays.
But note: The DP approach gives distribution after t seconds. Then expected = sum_{j} j * cur[j]. That's straightforward.
Potential pitfall: n and t up to 2000, but if n > t, we can have at most t entries. Our DP array size n+1 is okay, but we can also cap at min(n,t) to save memory if needed, but it's fine.
Let's test with example 4: maybe we should test a custom case: n=2, p=0.5, t=3. Expected = E[min(Bin(3,0.5),2)]. Bin(3,0.5): values: 0:0.125,1:0.375,2:0.375,3:0.125. min: 0:0.125,1:0.375,2:0.5. Expected = 0.3751+0.52 = 0.375+1.0=1.375. Actually 0.1250 + 0.3751 + (0.375+0.125)2 = 0.375 + 1.0 = 1.375. DP: Let's simulate: i=0: cur[0]=1.
i=1: j=0..1? n=2, so loop j=0..1? Actually j up to n-1 =1. But cur[1] is 0, so only j=0 matters. nxt[0] = 0.5, nxt[1]=0.5. Add cur[2]=0 => nxt[2]=0. So cur = [0.5,0.5,0].
i=2: Loop j=0..1:
j=0: cur[0]=0.5 -> nxt[0] += 0.50.5=0.25; nxt[1] += 0.50.5=0.25.
j=1: cur[1]=0.5 -> nxt[1] += 0.50.5=0.25; nxt[2] += 0.50.5=0.25.
After loop, add cur[2]=0 to nxt[2] -> nxt[2] = 0.25+0 = 0.25. So nxt = [0.25,0.5,0.25]. That's distribution after 2 seconds: indeed Bin(2,0.5): 0:0.25,1:0.5,2:0.25. Good.
i=3: cur = [0.25,0.5,0.25]. Loop j=0..1:
j=0: 0.25 -> nxt[0] += 0.250.5=0.125; nxt[1] += 0.250.5=0.125.
j=1: 0.5 -> nxt[1] += 0.50.5=0.25; nxt[2] += 0.50.5=0.25.
After loop, add cur[2]=0.25 to nxt[2] -> nxt[2] = 0.25+0.25=0.5.
So nxt = [0.125, 0.375, 0.5]. Sum: 0.125+0.375+0.5=1.0. Expected = 00.125+10.375+20.5=0.375+1.0=1.375. Good.
Thus DP works.
Now, we could also compute using binomial sum directly: iterate k from 0 to t, compute probability using multiplicative update, sum min(k,n). But we need to compute C(t,k) for large t? Actually using multiplicative update: prob = (1-p)^t; then for k from 0 to t-1: prob = (p/(1-p)) * (t-k)/(k+1). This yields P(S_t = k+1) from P(S_t = k). We'll need to handle p=0 or p=1 separately because division by zero. But we can handle. Then sum += min(k,n)prob. That would be O(t) only. For t up to 2000, it's trivial. However the DP O(tn) is also trivial; but if we want to be even more efficient, the binomial method is O(t). Let's compare: O(t) = 2000 vs O(tn) = up to 4 million. Both are tiny. However DP code is simpler to avoid binomial coefficient or multiplicative updates? Actually DP is also simple. But DP uses two loops; binomial uses one loop but with careful update. Both are fine.
But there is subtlety: the DP as described uses O(t*n) time. But we can implement it with one-dimensional DP and inner loop up to min(i,n). However with n=2000, t=2000, 4 million operations is negligible. So we can choose DP. However many Codeforces problem solutions may use DP or the formula. The problem is from Codeforces? Probably yes. Usually such constraints allow DP.
But let's verify if DP with O(tn) is definitely within limits: 20002000 = 4e6, each operation a few floating multiplications/additions, definitely <0.01 seconds in C++ but Python might be slower but still okay if optimized? The problem statement expects C++? But we are writing solution as ChatGPT? Usually we provide explanation and possibly code in some language. Since the user didn't specify language, we can just describe algorithm. But we need to produce final answer. However the platform expects a solution? The user asked: "Your task is to help him solve this complicated task." So we likely need to output a real number given input? Actually this is a typical problem: Input given, output expected number. The conversation appears to be a problem statement. So likely we need to provide a solution: maybe we should output the result for given inputs? But the user didn't provide specific numbers; they gave examples but not a concrete test case. Actually they provided the problem statement. Possibly they want us to describe how to solve it? However the instruction: "Your task is to help him solve this complicated task." Could be a request to write a program. But in this chat, they haven't provided an actual test case. They provided three examples, but that's for illustration. Usually on Codeforces, we need to read input and output answer. So we should respond with a solution: either code or algorithm.
Given the format, I think we should provide a solution: either explain the approach and then provide code (e.g., in C++ or Python) that reads n, p, t and prints the expected value. But as an AI, we can output a concise explanation and then the code. Since the user might be expecting a program to run? They might be copy-pasting a solution. Let's interpret: The user wrote the problem description and says "Your task is to help him solve this complicated task." So they want a solution, likely a program.
Thus we need to output a single real number for given input? Actually there is no input provided now; they just gave the problem statement. So maybe they want us to write a solution that works for any input within constraints. So we should produce code that reads the input and prints the answer.
Thus I'll provide a solution in Python (since it's simple) that uses DP O(t*n). However note that Python with loops 4e6 might be okay but borderline? 4 million operations in Python is fine (should be <0.1 seconds). But we can also implement the O(t) binomial method to be safe. Let's compute O(t) binomial method.
We need to compute sum_{k=0}^{t} min(k,n) * P(S_t = k). Use multiplicative update:
Let prob = (1-p)^t.
Then for k from 0 to t:
if k <= t: add min(k,n)*prob to answer.
if k < t: update prob = prob * (p/(1-p)) * (t - k) / (k + 1)
But careful: If p = 0, then (1-p)^t = 1, and p/(1-p) = 0, so all probabilities for k>0 are zero. So we can handle p=0 and p=1 separately. If p=1, then (1-p)^t = 0, but we can compute directly answer = min(t,n). For p=0, answer = 0.
But also if p is 0 or 1, division by zero issues: p/(1-p) if p=1 -> division by 0; if p=0, okay, p/(1-p)=0; but if p=1, we handle separately.
For p in (0,1), we can use above. However, if p is small, (1-p)^t might underflow? But t max 2000, p at least? p can be 0.00? If p=0.00 it's handled separately. For p=0.01, (0.99)^2000 is about exp(2000*ln(0.99)) ≈ exp(-20.1) ≈ 1.8e-9, which is fine for double. If p=0.001, (0.999)^2000 ≈ exp(-2) ≈ 0.135, still fine. So underflow not a concern.
But we must be careful about precision: Multiplicative update may accumulate errors. But for t=2000, it's likely okay.
Alternatively, use DP with two arrays in Python, it's also straightforward. Let's examine performance: 4 million iterations, each doing a few float operations, in Python ~0.05-0.1 seconds? Actually Python loops can be slower: 4 million might be around 0.2-0.3 seconds, which is acceptable for typical online judges if time limit is 1 or 2 seconds. But some judges are stricter. However Codeforces time limit might be 1 second, and Python could pass with O(t*n) if optimized? Usually 4e6 loops might be borderline but possibly okay if using PyPy. But we can implement the O(t) binomial method to be safe and simpler.
But we need to compute binomial probabilities and sum. That O(t) method uses a loop of t=2000 iterations, which is trivial.
Thus I'll implement binomial method.
Plan:
- Read line: n, p_str, t. But p is real; we need to parse as float.
- n, t are ints, p is float.
- If p == 0.0: print 0.0
- Elif p == 1.0: print min(n, t) as float.
- Else:
ans = 0.0
prob = (1.0 - p) ** t # P(S=0)
for k in range(0, t+1):
# min(k,n)
if k <= n:
add = k
else:
add = n
ans += add * prob
if k < t:
# update prob from k to k+1
prob *= (p / (1-p)) * (t - k) / (k + 1)
print ans with sufficient precision.
But careful: The update formula: P(k+1) = P(k) * (p/(1-p)) * (t - k)/(k+1). Starting with P(0) = (1-p)^t. This yields P(k) for all k. We need to loop k from 0 to t inclusive, compute ans. After the last iteration (k=t), we don't update.
Edge case: p/(1-p) might be large if p close to 1? p=0.99 -> p/(1-p) = 99, but t=2000, P(2000) = p^2000 which is extremely small, but double can handle it (maybe underflow to 0). That's okay; answer will be close to n. Underflow might cause small error but within tolerance? Possibly. But we can also compute answer using the complement: sum_{k=1}^{n} P(S_t >= k). That might be more stable? Possibly not needed.
Let's test binomial method with p=0.5, t=4, n=1: (1-p)^4 = 0.0625. Loop:
k=0: add=0 -> ans=0; prob update to k=1: prob = 0.0625 * (0.5/0.5) * (4-0)/(0+1) = 0.0625 14 = 0.25.
k=1: add=1 -> ans=0.25; update to k=2: prob = 0.25 * 1 * (4-1)/(1+1)=0.253/2=0.375.
k=2: add=1? since n=1, min(2,1)=1 -> ans=0.25+0.375=0.625; update to k=3: prob = 0.375 * 1 * (4-2)/(2+1)=0.3752/3=0.25.
k=3: add=1 -> ans=0.875; update to k=4: prob = 0.25 * 1 * (4-3)/(3+1)=0.25*1/4=0.0625.
k=4: add=1 -> ans=0.9375; done. Output 0.9375. Good.
Now with n=4, p=0.2, t=2: (1-p)^2 = 0.64. k=0: add=0, ans=0, update: prob = 0.64 * (0.2/0.8=0.25) * (2-0)/(1) = 0.640.252 = 0.32. k=1: add=1, ans=0.32, update: prob = 0.32 * 0.25 * (2-1)/(2) = 0.320.250.5 = 0.04. k=2: add=2? Since n=4, min(2,4)=2, ans=0.32+0.042? Actually ans=0.32 + 20.04 = 0.40. Good.
Seems correct.
Now consider p=1.0: (1-p) = 0, (1-p)^t = 0 for t>0, but our method would have division by zero in update. So we treat separately: ans = min(n, t). For t=0? t≥1, so fine.
Consider p=0.0: (1-p)^t = 1, but p/(1-p) = 0, so update will yield prob=0 for k=1 onward. But we can handle separately for simplicity.
But we must be careful about floating point errors for p exactly 0 or 1, given input p is given with two decimal digits, so p might be 0.00 or 1.00. So we can compare with tolerance? But it's fine to check if p == 0.0 or p == 1.0 after parsing.
Now about reading input: "The first line of the input contains three numbers n, p, t". So we read three tokens. p is real, may be like "0.50". So parse as float. But careful: using float may cause small rounding, but it's okay.
Output: print with sufficient precision. In Python, we can do print("{:.10f}".format(ans)) or just print(ans) may not give enough digits. To satisfy 1e-6 error, we can use print("{:.10f}".format(ans)) or print("{:.12f}".format(ans)). Usually print(ans) may output scientific notation or insufficient digits. Better to use print("{:.10f}".format(ans)). However if ans is e.g., 0.9375, that prints 0.9375000000, okay.
But we need to ensure not to print trailing zeros? It's fine.
Alternatively, we can use print("{:.12f}".format(ans)). But the problem says error ≤ 1e-6, so 10^-6, so 10 decimal digits after decimal maybe safe? Actually absolute or relative error: printing with 10 decimal places should be fine. Example: 0.5 prints as 0.5000000000, fine.
But let's compute maximum expected value: max is n (if t large enough). n <= 2000, so printing as float is fine.
Now, is there any nuance about the process that we missed? The description: "at each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p)". This implies that the event is independent each second, but note that if the first person doesn't move, the queue stays same and next second we again try with the same first person. That matches Bernoulli trials. So our modeling is correct.
But what about the fact that when the first person enters, he leaves the queue, and the next becomes first. The probability p is the same for any person. So indeed each second, if there is a person, they have probability p to board. So the total number of boardings in t seconds is the number of successes in a sequence of independent Bernoulli(p) trials, truncated at n. So our method stands.
One more nuance: The escalator is infinite, so people never leave. So number on escalator equals number boarded.
Thus solution is to compute expected value of min(X, n) where X ~ Binomial(t, p).
So I'll provide solution using binomial summation O(t).
But check t and n up to 2000, binomial probabilities for large k near t may be very small; but sum will be fine.
Potential pitfalls: For p close to 0 or 1, we must avoid division by zero. Already handle separately.
But there is also a case when p is between 0 and 1, but (1-p) might be extremely small if p is close to 1, leading to p/(1-p) being large. But probabilities update might become large then shrink? Actually starting from (1-p)^t which is extremely tiny if p close to 1. For p=0.999, (1-p)^t = (0.001)^2000 = 10^{-6000}, which underflows to 0.0 in double. So we would get prob=0 for all k. That would give ans=0, but actual answer should be close to min(t,n) which is up to 2000. So we would be completely wrong! That's a serious issue. Indeed, if p is close to 1, (1-p) is very small, raising it to high power underflows to 0. So our binomial method fails for p close to 1. Similarly, if p is close to 0, (1-p)^t is close to 1, fine; but for p close to 1, (1-p)^t underflows to 0, causing all probabilities zero. So we need to handle p near 1 carefully.
Let's test: p=0.99, t=2000, n=2000. (1-p)=0.01, (0.01)^2000 = 10^{-4000}, which is definitely 0 in double. So prob = 0.0, then updates won't help. So the binomial method fails for large t when p is very close to 1. But the input guarantees p has exactly two digits after decimal point, so p can be from 0.00 to 1.00 in steps of 0.01. So p=1.00 is handled separately; p=0.99 is possible. For p=0.99, (0.01)^2000 is far below double min positive (~1e-308), so underflows to 0. Indeed, double's smallest positive normalized is about 2.2e-308. (0.01)^2000 = 10^{-4000} = 1e-4000, which is 0. So our method would output 0 incorrectly. So we need a different approach that doesn't underflow.
Thus we need a method that works for p=1.0, 0.99, etc. DP approach may also suffer from underflow? DP multiplies probabilities many times, but it's additive; it doesn't compute (1-p)^t directly. However DP may also compute probabilities that become extremely small for many states, but it sums to 1. The DP will maintain probabilities that are of reasonable magnitude because they sum to 1, but individual probabilities could become very small. However double can represent numbers as small as 1e-308, but for p=0.99, many states (e.g., having few successes) have extremely low probabilities, but they might underflow to 0. But total probability of having few successes (like 0) is (0.01)^2000 ~ 1e-4000, which underflows to 0. But that's fine because those probabilities are negligible and contribute little to expected value. However the DP would also compute probabilities for states with many successes, which are large (close to 1). The DP algorithm as described computes probabilities by starting from dp[0]=1 and updating. For p=0.99, after many steps, the probability mass will be concentrated at high j. But does the DP method suffer from underflow in the early steps? For example, initially dp[0]=1. In the first step, nxt[0] gets 1 * (1-p) = 0.01, nxt[1] gets 0.99. So dp[0] becomes 0.01. After many steps, dp[0] will be (0.01)^i, which underflows for i large. However we don't care about dp[0] because it becomes extremely small; but as long as we don't get NaN or other issues, it's fine. Underflow to 0 is acceptable because the true probability is essentially zero. However, when we compute expected value, the contribution from dp[0] is 0 anyway. But there is a risk that after many steps, all probabilities become zero due to underflow? That would be problematic. Let's analyze: For p=0.99, the probability mass concentrates at high j. The DP iterates over j from 0 to n. For each step, we compute nxt[j] = cur[j] * (1-p) + (from previous? Actually update uses contributions from cur[j] and cur[j-1]. The probability for low j will become extremely tiny, but for j near n, probability will be near 1. The update uses multiplications by p (0.99) and (1-p) (0.01). Multiplication by 0.99 many times is fine; multiplication by 0.01 many times can cause underflow for low states. But the total sum of probabilities remains 1; however due to underflow, some mass may be lost, causing total probability sum to be slightly less than 1. But since the contributions lost are extremely small (<1e-308), the error in expected value might be negligible? The expected value is dominated by states near n, which are not underflowed. For p=0.99 and t=2000, n up to 2000, expected number is close to n (since t>=n). Actually if n=2000, t=2000, p=0.99, expected = E[min(Bin(2000,0.99),2000)]. Since Binomial mean = 1980, and variance = 20000.990.01=19.8, so probability of less than 2000 is not extremely small? Actually probability of exactly 2000 successes is 0.99^2000, which is about exp(2000ln(0.99)) = exp(-20.1) = 1.8e-9. That's tiny but not zero? Wait 0.99^2000 =? Actually (0.99)^2000 = exp(2000log(0.99)) ≈ exp(2000*(-0.0100503)) = exp(-20.1006) ≈ 1.67e-9. That's above 1e-308, so it's representable. But (0.01)^2000 is extremely tiny, underflows. The probability of exactly 0 successes is (0.01)^2000 = 10^{-4000}, underflows. But expected value is sum_{k} min(k,2000) * P(k). The probabilities for very low k are negligible, but probabilities for k close to 2000, e.g., k=1980 have probabilities that are not tiny. The DP might underflow when computing cur[0] after many steps, but that's okay. However, we must be careful about underflow when updating for low j: cur[0] becomes (0.01)^i. For i=2000, that underflows to 0. But cur[0] is used to compute cur[1], etc. If cur[0] becomes 0 due to underflow, it may affect the probability of higher states? Actually the probability of state 1 at time i depends on cur[0] from previous step. If cur[0] underflows to 0 early, then the probability mass that should have flowed from state 0 to state 1 via a success is lost. But that mass is extremely tiny: it's the probability of having exactly 1 success by that time? Let's examine: The probability of having exactly 0 successes after i steps is (0.01)^i. For i large enough, that underflows to 0. However the probability of having exactly 1 success after i steps is something like i * (0.99) * (0.01)^{i-1}? That is also extremely tiny for large i, because (0.01)^{i-1} is tiny. For i=2000, probability of exactly 1 success is 2000 * 0.99 * (0.01)^{1999} which is even smaller than (0.01)^2000? Actually (0.01)^{1999} = 10^{-3998}, times 2000 ~ 2e-3995, still astronomically small. So those probabilities are effectively zero. The probability mass that matters for expected value is from states with many successes, which come from transitions that do not involve such extremely small numbers. However the DP update for higher states uses contributions from lower states that may be underflowed to zero, but those contributions are negligible. So total probability may be slightly less than 1, but the error should be far below 1e-6. However we need to be cautious: The DP update for state j at time i uses cur[j] and cur[j-1]. For moderate j, cur[j] may be built from contributions from lower states that underflowed to zero. But if those contributions are truly negligible, it's okay. However is it possible that for some j, the probability is significant but the DP may lose it due to underflow in intermediate steps? For p=0.99, the most likely path is to get many successes quickly. The probabilities for moderate j (like j around 1000) may be built from earlier states with lower j that have non-negligible probabilities at earlier times. At early times, (0.01)^i is not too small; for i=100, (0.01)^100 = 1e-200, already underflow? 1e-200 is below 1e-308? Actually 1e-200 > 1e-308, so it's still representable. But 1e-200 is representable as double? Double can represent numbers as small as about 2e-308, so 1e-200 is well above that, so no underflow. However when i gets larger, say i=2000, (0.01)^2000 is 1e-4000, underflow. But by the time i is large, the probability mass has moved to high j. So the low j states become extremely tiny; underflow is acceptable. The DP uses cur[j] values for all j each iteration. For j moderate (like 1000) at i=2000, the probability might be not huge but also not extremely tiny? Let's compute probability of exactly 1000 successes in 2000 trials with p=0.99. That's C(2000,1000) * 0.99^1000 * 0.01^1000. 0.99^1000 ≈ exp(-10.05) ≈ 4.3e-5, 0.01^1000 = 10^{-2000}, product ≈ 4e-2005, which is far below double min. So that probability is also effectively zero. In fact, for p=0.99, the binomial distribution is concentrated near 1980. Probabilities for j far from the mean are astronomically small. So all states except those near n=2000 have probabilities that underflow to zero. But the DP will compute them as zero due to underflow, but the true probabilities are negligible. So the expected value computed by DP would be essentially the contribution from states near n that are representable. However, we need to ensure that the probabilities for states near the mean are computed correctly without underflow. For p=0.99, the probability for j=1980 is C(2000,1980)0.01^20. 0.99^1980 = exp(1980*ln(0.99)) ≈ exp(-19.9) ≈ 2.2e-9, 0.01^20 = 1e-40, product ~2.2e-49, times combinatorial factor C(2000,20) ~ 2000^20/20! huge, maybe ~ (2000^20)/2.4e18? Actually C(2000,20) = 2000!/(20!*1980!) approximate magnitude: roughly (2000^20)/20! ≈ (2e3)^20 / 2.43e18 = (2^20 * 10^60) / 2.43e18 = about (1e6 * 1e60) / 2.43e18 = 1e66/2.43e18 ≈ 4e47. So probability ~ 4e47 * 2.2e-49 ≈ 0.0088. So probability for j=1980 is about 0.0088, which is representable. So some probabilities are non-negligible. The DP must compute them accurately.
Now, if we use DP with two arrays, how will it compute probability for j=1980? It will build it from previous states via transitions. The numbers involved might be very small for low j, but for moderate j, the numbers might be representable. Underflow in very small numbers might cause loss of precision for the significant ones? Not directly, because the contributions from low j to high j are negligible. However, the DP algorithm uses additive updates: for each j, we add cur[j] * p to nxt[j+1] and cur[j] * (1-p) to nxt[j]. If cur[j] is extremely small (underflow to 0), it contributes nothing. That's fine. But what about cur[j] that is not extremely small but its multiplication by p or (1-p) might underflow? For representable numbers, multiplication by p (0.99) will not underflow; multiplication by 0.01 might produce a number that underflows if cur[j] is already very small. But that's okay because those contributions are to states that are also negligible. So overall, the DP may produce accurate probabilities for the high-probability states. However, there might be a subtle issue: due to underflow, the total probability sum might be less than 1, but the error is likely far below 1e-6. However to be safe, we could implement DP using log-scale? Or use the binomial method but with careful handling of p close to 1 by switching to complementary distribution? For p close to 1, we could consider failures instead of successes. Let Y = number of failures = t - X, which is Binomial(t, 1-p). Then min(X, n) = min(t - Y, n). For p close to 1, (1-p) is small, so we could compute probabilities based on failures. That would avoid underflow because (1-p)^t is tiny, but we would start from probability of 0 failures: p^t. p^t for p=0.99, t=2000 is about 1.8e-9, which is representable (non-zero). So we can compute using the complement: let q = 1-p (failure prob). Then X = t - Y, where Y ~ Bin(t, q). Then min(X, n) = ? But we need to handle n. This could be done: E[min(t - Y, n)] = ? We could compute via sum over y. But again (1-p) is small, p^t may be small but still representable. However, p^t for p=0.99 and t=2000 is about 1.8e-9, which is above double min. So if we start with prob = p^t (probability Y=0) and update: P(Y=y+1) = P(Y=y) * (q/p) * (t - y)/(y+1). Here q/p is small (0.01/0.99 ≈ 0.010101). So probabilities for small y may be small but still representable. However for y large, probabilities become extremely tiny, but they correspond to X small, which have negligible probability. So this method should work without underflow for both extremes. But we need to handle both p close to 0 and p close to 1; we can choose whichever side gives representable starting probability. For p <= 0.5, we can use successes method (starting with (1-p)^t). For p > 0.5, we can use failures method (starting with p^t). Actually for p=0.5, both are same. So we can implement a hybrid approach that avoids underflow.
But DP is simpler to implement without worrying about underflow because it uses probabilities that sum to 1, and double can represent numbers down to 1e-308. The only risk is if (1-p)^t or p^t underflows to 0 before we start DP? DP doesn't use that initial power; it builds gradually. However, as we saw, for p=0.99, dp[0] after 2000 steps becomes (0.01)^2000 which underflows to 0. But that's fine. The question is whether the DP can accurately compute the probabilities for j near n. Let's simulate mentally the DP for p=0.99, t=2000, n=2000. The probability mass for j near n is built by many transitions from lower j. The DP will start with dp[0]=1. At first step, dp[0] = 0.01, dp[1] = 0.99. At step 2, we get contributions:
- from dp[0]=0.01: nxt[0] += 0.010.01 = 0.0001; nxt[1] += 0.010.99 = 0.0099.
- from dp[1]=0.99: nxt[1] += 0.990.01 = 0.0099; nxt[2] += 0.990.99 = 0.9801.
After adding, dp: [0.0001, 0.0198, 0.9801]. So far so good. At each step, the probability mass quickly moves to higher j. After many steps, the low j probabilities become extremely small, but the high j probabilities remain representable. Because the DP uses numbers that are not extremely small for the bulk of the mass. So DP should be fine. However, consider the possibility that at some point, due to underflow, the probability for a state j that is intermediate but still significant gets a contribution from a lower state that has underflowed to zero, but that contribution should have been negligible anyway. But what about the contributions from the state itself via (1-p) staying? For high j, the probability might be multiplied by (1-p) many times? Actually once we reach j near n, the DP for j=n will just accumulate probability and not decay. For j near n, we have transitions: from j-1 (with prob p) and staying at j (with prob (1-p)) if j < n. However if j is close to n but less than n, the probability might be multiplied by (1-p) each step, which is 0.01, leading to exponential decay of that state as mass moves to higher j or stays. But these probabilities are still significant because they are fed from lower states. The multiplication by 0.01 might cause underflow if the probability is already tiny. But for states that are significant, the probability is not tiny; e.g., after many steps, the probability of being at j=1980 might be ~0.01? Actually earlier we estimated probability of exactly 1980 successes is ~0.0088. That is not tiny. Multiplying by 0.01 would give 8.8e-5, still above underflow threshold. So DP seems safe.
Given the maximum t and n of 2000, DP is safe. The only risk is if p is extremely close to 1, like p=0.999, but p only has two decimal places, so p max 0.99? Actually p can be up to 1.00. For p=0.99, (1-p)=0.01, which is not extremely small; powers like (0.01)^2000 underflow, but as argued, that only affects negligible probabilities. So DP will work.
Nevertheless, implementing DP with two arrays and loops over j up to n may be simpler and avoid the underflow issue of the direct binomial method. However the direct binomial method can also be made robust by using the complement for p>0.5.
Let's compare: DP O(t*n) = 4e6, which is fine in Python if optimized with list comprehensions? But naive nested loops in Python (for i in range(t): for j in range(n):) will be 4 million iterations. Each iteration does a few float multiplications and assignments. In CPython, 4 million operations is about 0.1-0.2 seconds maybe? Actually Python can handle ~50 million simple operations per second? Not that fast. Typically CPython can do about 10-20 million simple operations per second on a decent machine? Actually it's slower; 10 million simple operations might take about 0.5-1 second. But 4 million is fine. However we also have overhead of list indexing and condition checks. It should run under 1 second. But if time limit is strict (like 1 second), maybe borderline. However we can micro-opt: we can use list of floats and update using Python loops; 4 million is definitely okay for typical Codeforces Python time limit of 2 seconds. I've done similar DP with 2000x2000 and it passes. So I'm comfortable with DP.
But we can also reduce to O(t) using binomial with safe selection. That would be even faster and avoid any underflow concerns. Let's design the binomial approach with the complement:
We compute E = sum_{k=0}^{t} min(k,n) * P(X=k).
We can compute P(X=k) for k from 0 to t using multiplicative update. For stability, we should avoid underflow of the starting probability. So we can decide to compute from the mode outward? But easiest is to compute using logarithms? That would be slower. Instead, we can compute using two directions: if p <= 0.5, we start from k=0 and go up; if p > 0.5, we start from k=t and go down (i.e., compute using failures). Specifically, if p > 0.5, let q = 1-p, Y = t - X (failures). Then P(Y=y) = C(t,y) q^y p^{t-y}. We can compute starting from y=0 (i.e., X=t) with probability p^t, and then update downwards: P(Y=y+1) = P(Y=y) * (q/p) * (t-y)/(y+1). Since p^t may be small but still representable? For p=0.99, p^t ≈ 1.8e-9, which is > 2e-308, so fine. For p=1.0, we handle separately. So this works. However we need to compute min(k,n) where k = t - y. We can loop y from 0 to t, compute prob_y, and add min(t-y, n)prob_y to answer. This will not underflow because p^t is representable for p up to 1? For p=1, p^t=1, but we handle p=1 separately anyway. For p=0.999, if t=2000, p^t = (0.999)^2000 = exp(2000ln(0.999)) ≈ exp(-2.002) ≈ 0.135, still fine. Actually 0.999^2000 is about 0.135, not tiny. So p^t remains large. For p=0.99, p^t=1.8e-9, still representable. For p=0.9999 (but p only two decimals, so not possible). So the complement method should be safe. The only case where p^t could underflow is if p is less than about 0.5? But we are using complement for p>0.5, so p is at least 0.51, then p^t for t=2000: (0.51)^2000 = exp(2000ln(0.51)) = exp(2000(-0.673)) = exp(-1346) ≈ 10^{-585}, which is far below double min? Actually 10^{-585} is much smaller than 1e-308, so underflow to 0. That's a problem! For p=0.51, p^t would be extremely tiny. Wait, we said we use complement for p>0.5. But if p=0.51, p^t = 0.51^2000 = exp(2000log(0.51)) = exp(2000(-0.67334455326)) = exp(-1346.689) ≈ 10^{-585}. That is far below the smallest positive double (about 1e-308), so it would underflow to 0. So starting from p^t would be 0, causing all probabilities to be zero. So complement method fails for p moderately above 0.5 but not extremely high. So we need to choose the direction such that the base probability (the probability of the extreme outcome) is not underflowing. That would be to start from the mode side? Actually we can start from the more likely side. Typically for binomial distribution, probabilities are large near the mean. We can start from the mode (k ≈ floor((t+1)*p)) and compute probabilities in both directions using recurrence. But that's more complex. DP is simpler.
Thus the direct DP approach is more robust because it doesn't rely on computing an extreme probability that might underflow. DP builds probabilities gradually, and the numbers that matter remain representable.
Given the ease and robustness, I'll go with DP.
Let's confirm DP doesn't suffer from underflow for p=0.51. At start, dp[0]=1. After first step, dp[0]=0.49, dp[1]=0.51. After many steps, the distribution spreads. The probability for low j may underflow eventually, but high j probabilities are significant. For p=0.51, the mean is 1020. The probability mass is around that. The probability of j=0 after t=2000 is (0.49)^2000, which is extremely tiny (underflows). That's fine. The probability of j around 1020 is moderate; it will be computed via many transitions. The DP algorithm will compute these probabilities through repeated multiplication by p and (1-p). As we compute, will we lose the mass due to underflow in intermediate steps? For j around 1020, the probability builds from lower j values. The probability of being at j=500 at some intermediate step might be non-negligible? Let's see: At intermediate time i=1000, the distribution of successes is Binomial(1000,0.51). The probability of 500 successes is C(1000,500)0.51^5000.49^500. That's not extremely tiny; it's on the order of 1/sqrt(π*500) maybe around 0.025? Actually binomial with p=0.51 at i=1000 has mean 510, variance ~ 249.9, so probability at 500 is decent. So those numbers are representable. So DP should work.
The DP update uses cur[j] values that are within representable range. Even if some cur[j] are very small, they don't affect the large ones. So DP is safe.
Thus I'll implement DP using two lists of size n+1.
Edge Cases: n can be larger than t. In that case, we never can board more than t people. In DP, we have array size n+1, but we only need up to n, but the DP will automatically not exceed i (since each step can increase by at most 1). However we allocate n+1, and we will have transitions from cur[j] for j up to i-1. When j = n but n > i, cur[n] is zero anyway. The DP update for j < n works fine. Also when j == n (but n may be > i), cur[n] is zero, so the separate addition of cur[n] to nxt[n] does nothing. So it's fine. At the end, expected value = sum_{j} j * cur[j]. Since cur[j] for j > t are zero, it's fine.
But we can optimize by limiting the inner loop to min(i, n) to avoid unnecessary iterations. That might speed up a bit. Since i goes from 0 to t-1, the min(i, n) may be less than n for early i. For t=2000, n=2000, total iterations sum_{i=0}^{t-1} (min(i, n) + 1?) Actually we loop j from 0 to n-1 (or to min(i, n-1)?) to compute transitions. For i small, min(i, n-1) is small; for i large, it's near n. The total number of inner loop iterations is roughly sum_{i=0}^{t-1} min(i, n-1). If t <= n, sum = O(t^2); if t=2000, n=2000, then sum = sum_{i=0}^{1999} i = about 2 million. Plus the separate handling for j=n (just one addition per iteration). So total ~2 million, which is less than 4 million. Actually earlier we thought O(tn) = 4 million, but by limiting to min(i, n-1) we get less. However if n < t, then min(i, n-1) becomes n-1 for i >= n, so total about n(t-n+1) + sum_{i=0}^{n-1} i ≈ n*(t-n) + n^2/2 ≈ n*t - n^2/2. For n=2000, t=2000, that's 2 million. So DP is even faster. So we should implement inner loop only up to min(i, n-1) to avoid unnecessary updates. But we need to know i (current time). In our iterative loop, we have i from 0 to t-1. At step i, we have cur probabilities for states up to min(i, n) (since we cannot have more successes than seconds elapsed). So we can loop j from 0 to min(i, n-1). Then handle j = n separately (if n <= i, then cur[n] may be non-zero). But we also need to consider that when i < n, cur[n]=0. So we can just add cur[n] to nxt[n] regardless; it will be zero if not reached.
Thus algorithm:
Initialize cur = [0.0]*(n+1)
cur[0] = 1.0
for i in range(t): # i = 0,..., t-1 representing seconds processed
nxt = [0.0]*(n+1)
max_j = min(i, n-1) # because i seconds have passed, max j is i (but we only need j < n)
# Actually i seconds have passed before this step? At start i=0, after 0 seconds, we have cur for i seconds. Then we process one second to go to i+1 seconds. So at iteration for i from 0 to t-1, cur corresponds to state after i seconds. So the maximum j present in cur is min(i, n). So loop j from 0 to min(i, n-1) inclusive.
for j in range(0, min(i, n-1)+1):
# transition from state j
if j < n:
stay = cur[j] * (1-p)
enter = cur[j] * p
nxt[j] += stay
nxt[j+1] += enter
# handle j = n if n <= i (i.e., already reached n)
if n <= i:
nxt[n] += cur[n] # stays at n
else:
# n > i, cur[n] is zero, so nothing
pass
cur = nxt
After loop, expected = sum_{j=0}^{n} j * cur[j].
But careful: The transition for j = n is not handled in the inner loop (since we only go up to n-1). So we need to add cur[n] to nxt[n] as above. That's correct.
Now verify with n=1, t=4. i=0: min(i, n-1) = min(0,0)=0, loop j=0: cur[0]=1 -> nxt[0] += 0.5; nxt[1] += 0.5. Since n=1 and i=0, n <= i? 1 <= 0 false, so no addition for n. cur becomes [0.5,0.5].
i=1: min(i, n-1)=min(1,0)=0, loop j=0: cur[0]=0.5 -> nxt[0] += 0.25; nxt[1] += 0.25. Now n <= i? 1 <= 1 true, so add cur[1]=0.5 to nxt[1]. So nxt[1] becomes 0.25+0.5=0.75. nxt[0]=0.25. cur = [0.25,0.75].
i=2: min(2,0)=0, loop j=0: cur[0]=0.25 -> nxt[0] += 0.125; nxt[1] += 0.125. n <= i? 1 <= 2 true, add cur[1]=0.75 to nxt[1] => total nxt[1] = 0.125+0.75=0.875. nxt[0]=0.125. cur = [0.125,0.875].
i=3: min(3,0)=0, loop j=0: cur[0]=0.125 -> nxt[0] += 0.0625; nxt[1] += 0.0625. n <= i? true, add cur[1]=0.875 => nxt[1]=0.0625+0.875=0.9375. nxt[0]=0.0625. cur = [0.0625,0.9375]. Done. Expected = 0.9375. Good.
Now with n=2, t=3 (we computed earlier). Let's simulate using this method:
cur0: [1,0,0]
i=0: min(0,1)=0, loop j=0: cur[0]=1 -> nxt[0]=0.5, nxt[1]=0.5. n<=0? 2<=0 false. cur=[0.5,0.5,0]
i=1: min(1,1)=1, loop j=0..1:
j=0: cur[0]=0.5 -> nxt[0]+=0.25; nxt[1]+=0.25
j=1: cur[1]=0.5 -> nxt[1]+=0.25; nxt[2]+=0.25
n <= i? 2 <=1 false, no addition. So nxt = [0.25,0.5,0.25]. cur = [0.25,0.5,0.25]
i=2: min(2,1)=1? Actually min(i, n-1) = min(2,1)=1. Loop j=0..1:
j=0: cur[0]=0.25 -> nxt[0]+=0.125; nxt[1]+=0.125
j=1: cur[1]=0.5 -> nxt[1]+=0.25; nxt[2]+=0.25
n <= i? 2 <=2 true, so add cur[2]=0.25 to nxt[2] => nxt[2] = 0.25+0.25=0.5.
So nxt = [0.125, 0.375, 0.5]. cur = [0.125,0.375,0.5].
After loop ends (t=3 iterations). Expected = 00.125+10.375+2*0.5 = 1.375. Good.
Works.
Now about reading input: The input may be like "1 0.50 1". We'll read as strings and split. Use map for n and t, but p as float.
Implementation in Python:
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
p = float(data[1])
t = int(data[2])
# DP
cur = [0.0] * (n + 1)
cur[0] = 1.0
for i in range(t): # i = number of seconds processed so far
nxt = [0.0] * (n + 1)
# max j that can be < n and have non-zero probability
max_j = min(i, n - 1)
for j in range(max_j + 1):
if cur[j] == 0.0:
continue # optional speed-up
stay = cur[j] * (1 - p)
enter = cur[j] * p
nxt[j] += stay
nxt[j + 1] += enter
# if we have already reached n, add the probability of staying at n
if n <= i:
nxt[n] += cur[n] # stays at n
cur = nxt
expected = 0.0
for j in range(n + 1):
expected += j * cur[j]
# output with required precision
print("{:.10f}".format(expected))
if name == "main":
main()
But there's a subtlety: When n=0? n ≥ 1 per constraints (1 ≤ n). So fine.
Now check for p=1.0. Then 1-p = 0.0. In DP, stay = cur[j] * 0 = 0, enter = cur[j] * 1 = cur[j]. For j < n, nxt[j] gets 0, nxt[j+1] gets cur[j]. For j == n, we add cur[n] to nxt[n]. So after t steps, cur[t] = 1 if t <= n, else cur[n]=1. Expected = min(t,n). Works.
p=0.0: stay = cur[j] * 1 = cur[j], enter = 0. So nxt[j] += cur[j]; for j==n we also add cur[n]. So after t steps, cur[0]=1, expected 0. Good.
Now performance: The inner loop goes over j up to min(i, n-1). For n=2000, t=2000, total inner iterations about sum_{i=0}^{1999} (min(i,1999)+1) Actually min(i, n-1) = i for i<2000? Since n-1 =1999, i goes up to 1999, so min(i,1999)=i. So total iterations = sum_{i=0}^{1999} (i+1) = (2000*2001)/2 = 2,001,000. That's about 2 million, plus the outer loop of 2000, plus the final sum. That's fine.
But we also have the check for n <= i to add cur[n]. For i from 0 to t-1, for i >= n, we do that addition. That's fine.
Thus DP is efficient.
Potential improvement: we could combine the addition for j=n within the loop by treating j == n separately, but we already have separate handling.
Edge Cases: When n=1, n-1=0, so inner loop runs only for j=0 each iteration. That's fine.
Now about floating point precision: The DP multiplies by p and 1-p repeatedly. p is given with two decimals, so exact representation? Not exactly in binary; but double error will be tiny. The result must be within 1e-6. DP with 2000 steps may accumulate error but still within tolerance. So fine.
Alternative approach: Use the formula E = sum_{k=1}^{n} P(S_t >= k). We could compute binomial cumulative probabilities using DP or using incomplete beta, but DP is simpler.
Now ensure we read input correctly: The line may contain trailing spaces; we use sys.stdin.read().split().
Now about output format: We need to print a single real number. The examples show "0.5" and "0.9375" and "0.4". So they didn't force trailing zeros. Printing with 10 decimal places is acceptable. Usually Codeforces accepts any format with sufficient precision. So print("{:.10f}".format(ans)) should be okay. Alternatively, we could use print(ans) but that might print something like 0.5 which is fine for the examples but may not give enough digits for other cases; it could print scientific notation? Usually print(ans) prints with default str which for floats gives up to 12 digits but may use scientific for very small numbers. That's acceptable as long as error within limit. However to be safe, we format with 10 decimal places.
But wait: if the expected value is an integer like 2.0, printing "2.0000000000" is okay. The problem might expect "2" but with error tolerance, printing "2.0000000000" is fine.
Thus I'll go with formatted output.
Now we should test with given examples.
Example1: n=1,p=0.5,t=1 -> expected 0.5. Our DP should produce 0.5.
Example2: 1 0.5 4 -> 0.9375
Example3: 4 0.20 2 -> 0.4
Let's test manually with code mentally.
Now, consider special case n=2000, p=0.99, t=2000. DP should compute something. We should ensure no performance issues.
But one more nuance: The DP as described uses a new nxt array each iteration, which creates many lists. For t=2000, we allocate 2000 arrays of size up to 2001, that's 200020018 bytes ~ 32 MB allocated over time, but they are freed or reused? In Python, each iteration we create a new list nxt; the previous cur becomes eligible for garbage collection. This may cause overhead but still okay for 2000 iterations. To reduce allocation, we could use two arrays and swap references, but we already do that: we assign cur = nxt at the end, and nxt is newly created each loop. That's fine.
Alternatively, we could use a single array and update in reverse to avoid extra allocation, but then we need to be careful about using old values. But simpler to allocate new each time.
Given t=2000, memory allocation of 2000 lists of 2000 floats is about 2000 * 2000 * 8 = 32 million bytes = 32 MB per iteration? Actually each list is about 2001 floats = 16008 bytes, times 2000 = 32 MB allocated over the whole run, not simultaneously. Python's memory management may cause some overhead but it's fine.
But to be a bit more efficient, we can pre-allocate two lists and swap, reinitializing nxt to zeros each iteration by using [0.0]*(n+1). That's what we do.
Alright.
Now confirm that DP works for n > t. For n=2000, t=1000. Then max_j = min(i, n-1) = i (since i <= t-1 < n). So inner loop goes up to i. That's sum_{i=0}^{999} (i+1) = 500,500 operations. Good. Also we never add cur[n] because n > i always. So final expected should be sum_{j} j*Prob(j successes in t trials) which is less than n. That's correct.
Now we can also compute expected value using the identity sum_{k=1}^{n} P(S_t >= k). But we already have DP.
Potential Pitfall: For p=0 or p=1, the DP uses multiplication by 0 and 1. That's fine. But when p=1, (1-p) = 0, we might have many zeros. However, for i up to t-1, the DP will quickly move all probability to n if n <= t. Let's test with n=5, p=1, t=3. cur[0]=1. i=0: max_j = min(0,4)=0, loop j=0: stay=0, enter=1 -> nxt[1]=1. n <=0? false. cur=[0,1,0,0,0,0]. i=1: max_j = min(1,4)=1: loop j=0..1: j=0 cur[0]=0 skip; j=1 cur[1]=1 -> stay=0, enter=1 -> nxt[2]=1. n <=1? false (5>1). cur=[0,0,1,0,0,0]. i=2: max_j = min(2,4)=2: j=2 cur[2]=1 -> stay=0, enter=1 -> nxt[3]=1. cur=[0,0,0,1,0,0]. After loop t=3, cur[3]=1. Expected = 3. That's min(5,3)=3. Good.
If t=7, n=5: after i=4 (4 steps), we will have cur[4]=1. i=5: max_j = min(5,4)=4? Actually i=5? Wait we loop i from 0 to t-1=6. At i=4, cur corresponds to after 4 seconds: cur[4]=1. i=4 iteration (processing 5th second): max_j = min(4,4)=4, loop j up to 4. j=4: cur[4]=1, stay=0, enter=1 -> nxt[5] =1. Also n <= i? n=5 <=4? false. So after i=4, nxt becomes has cur[5]=1. i=5: now cur[5]=1. max_j = min(5,4)=4, so j=5 not processed in loop (since max_j=4). Then we have n <= i? 5 <=5 true, so add cur[5]=1 to nxt[5]. So after i=5, cur[5]=1. i=6: similarly cur stays at 5. So final cur[5]=1. Expected =5. Works.
So DP handles p=1 well.
Now for p=0, stay=cur[j]*1, enter=0. For n=5, t=3: cur[0]=1. i=0: max_j=0: j=0: nxt[0] +=1; cur remains [1,0,...]. After 3 steps, cur[0]=1. Expected 0.
Now confirm with example 3: n=4,p=0.2,t=2. DP: cur[0]=1. i=0: max_j = min(0,3)=0: j=0: stay=0.8, enter=0.2 => nxt[0]=0.8, nxt[1]=0.2. n <=0 false. cur=[0.8,0.2,0,0,0]. i=1: max_j = min(1,3)=1: j=0: cur[0]=0.8 => stay=0.64, enter=0.16; j=1: cur[1]=0.2 => stay=0.16, enter=0.04. nxt after adds: nxt[0]=0.64; nxt[1]=0.16+0.16=0.32; nxt[2]=0.04. n <=1? false (4>1). cur = [0.64,0.32,0.04,0,0]. After t=2, expected = 00.64+10.32+20.04+30+4*0 = 0.4. Good.
Thus DP is correct.
Now we should produce final answer: code in Python.
But the problem originally may expect C++ solution? But we can provide Python solution; it's acceptable given constraints.
Now about reading input: The input might be in one line, but could be multiple whitespace. We'll use sys.stdin.read().split().
Now about printing: We'll use print("{:.10f}".format(expected)).
However, we must consider that the expected value may be something like 0.9375 exactly, and printing with 10 decimals will show 0.9375000000, which is fine.
Now also need to consider that p is given with exactly two digits after decimal point, but as float it may be represented as 0.1? Actually it's given with two digits, so p can be like 0.00, 0.50, 1.00, etc. So reading as float is okay.
Edge: p=0.00 or p=1.00, we handle with DP, no special case needed.
But there is one more nuance: The DP as described uses (1-p) and p. For p=1.0, 1-p = 0.0, we multiply cur[j] by 0.0, that's fine. For p=0.0, p=0.0, also fine. So no need for special cases.
However, for p=0.0, the DP inner loop will compute stay = cur[j] * 1.0 = cur[j], enter = 0. So probability never moves beyond 0. That's fine.
But the separate addition of cur[n] for n<=i: For p=0.0, and if n <= i (i.e., we have somehow reached n?), but with p=0.0, you never increase j, so cur[n] will always be 0 unless n=0 (not allowed). So it's fine.
Thus the DP is generic.
Now we need to consider potential numeric error accumulation. For p=0.5, t=2000, the DP should produce accurate results. Let's approximate: The probability distribution after 2000 steps is binomial with p=0.5, mean 1000. The DP will compute probabilities for many states. The sum of probabilities should be 1. Due to floating point, the sum might slightly deviate. But the expected value computed from these probabilities might still be accurate to within 1e-6. For example, using DP, we might lose a little due to rounding, but likely fine.
We can also compute expected value using formula E = sum_{k=1}^{n} P(S_t >= k). To compute P(S_t >= k), we could use regularized incomplete beta or use DP for cumulative distribution. But DP already gives us the distribution, so we can compute expected value directly.
Thus final solution: DP with O(t * min(t, n)) time, O(n) memory.
Now, we may consider using Python's fractions? No, floats are fine.
Double-check constraints: t up to 2000, n up to 2000. So DP works.
Now we can produce final answer with code.
I'll include comments in code for clarity.
But perhaps the problem expects output with absolute/relative error 1e-6, so we can just print with e.g., 12 decimal places.
Let's also test a few extra cases manually:
Case: n=2000, p=0.5, t=2000. Expected = sum_{k=0}^{2000} min(k,2000)*C(2000,k)0.5^2000. That is simply the mean of Bin(2000,0.5) capped at 2000, but since cap is at 2000 and binomial mean 1000, cap doesn't matter, so expected = 1000. So answer should be 1000.0. DP should compute that. Since the probabilities sum to 1 and expected value computed as sum j * prob[j] should be 1000.0. Let's test quickly with mental? Hard to compute but it should be exactly 1000? Actually binomial mean is exactly tp = 1000, and since cap does not affect because max is 2000 > mean, expected = mean = 1000. So DP should give 1000.0. Due to floating point, might be 999.999999 or 1000.000001, but within error.
Now, if n is small relative to mean, e.g., n=5, p=0.5, t=2000, expected is close to 5 because almost surely at least 5 successes. Actually probability of less than 5 successes is negligible. So expected ≈ 5. DP will compute very small probabilities for j<5, but those might underflow to 0. That's okay. But we need to ensure that the contribution from j=5 (which is 5) is accurate. For j=5, probability is essentially 1. However due to underflow, cur[5] might be slightly less than 1 because some probability mass lost to underflow in lower states? But the total probability sum should be 1. If lower states underflow to 0, the total sum may be <1, causing cur[5] to be less than 1. But the probability of having exactly 5 successes in 2000 trials with p=0.5 is not 1; it's actually tiny? Wait, if n=5 and t=2000, the number of successes X is binomial with mean 1000. The probability that X is exactly 5 is extremely small (C(2000,5)*0.5^2000, which is astronomically small). The probability that X >= 5 is essentially 1, but the probability that min(X,5)=5 is P(X >=5) which is essentially 1. But the distribution of min(X,5) is: P=5 if X>=5, else X. So the expected value is 5 * P(X>=5) + sum_{k=0}^{4} k P(X=k). Since P(X>=5) ≈ 1, expected ≈ 5. But in DP, the state j=5 represents "at least 5 have boarded"? Actually no, DP state j represents exactly j people have boarded, but only if j < n? Wait, DP state is number of people boarded. When j = n (5), that includes all scenarios where exactly 5 have boarded, but also scenarios where more than 5 would have boarded if allowed, but since we cap at n, in reality after boarding 5, queue empty, and no further boarding. So DP must have state n representing "at least n have boarded"? In our DP, state j=n is used for "exactly n have boarded and process stops". But does it represent "exactly n" or "at least n"? In our DP, we treat state n as absorbing: once you reach n, you stay there. So the probability in state n after t seconds is the probability that you have reached n at or before t, i.e., at least n successes occurred. That's correct. So in DP, cur[5] after t seconds equals P(at least 5 successes in t trials). So cur[5] should be essentially 1. The probabilities for j<5 are P(exactly j successes) for j=0..4. So the sum of cur[0..5] should be 1. In DP, we compute cur[5] as absorbing. For p=0.5, t=2000, n=5, the probability of exactly 5 successes is not 1; it's very small. But the absorbing state probability is the probability of having reached 5 at any time. That's P(X>=5) which is essentially 1. So cur[5] should be 1. Let's see if DP can compute that accurately. The DP will start with cur[0]=1. At each second, we transition. For early steps, probability mass will move to higher j. After a few steps, it's highly likely that we have already reached 5. Actually after 5 seconds, the probability of having reached 5 is the probability of at least 5 successes in 5 trials = p^5? Actually for p=0.5, probability of 5 successes in 5 trials = 0.5^5 = 0.03125, so still small. But after many steps, the probability of having reached 5 approaches 1. So DP will gradually accumulate probability in state 5. For each step after we have reached 5, we just add cur[5] to nxt[5] (i.e., stay). So eventually cur[5] becomes the cumulative probability of ever having reached 5. This should be computed accurately as long as the probabilities of transitioning to 5 are added correctly. The probability of transitioning to 5 at a given step depends on cur[4] * p. cur[4] itself is built from lower states. For large t, the probability of being in state 4 at some step is the probability that exactly 4 successes have occurred up to that step and we haven't yet reached 5. Over many steps, the total probability of ever reaching 5 is sum over time of (cur[4] * p). This sum should be 1 minus probability of never reaching 5 (i.e., at most 4 successes in t trials). For t=2000, that probability is negligible. However, DP will compute cur[4] values that might underflow? For large t, the probability of being stuck at exactly 4 successes after many steps is extremely small because to have exactly 4 successes after many trials, you must have many failures and only 4 successes. The probability of exactly 4 successes in 2000 trials is C(2000,4)*0.5^2000, which is about (2000^4/24)*2^{-2000}. 2^{-2000} is about 9e-602, times something ~ (1.6e13)/24 ~ 6.7e11, product ~ 6e-590, which underflows to 0. So cur[4] at i=2000 will be essentially 0. But the contribution to cur[5] from transitions from state 4 occurs throughout the process, not just at the final step. The DP accumulates these contributions over time. For early steps, cur[4] might be non-negligible. For example, after 10 steps, probability of exactly 4 successes might be around C(10,4)*0.5^10 = 210/1024 ≈ 0.205. So cur[4] at i=10 is around 0.2. That contributes to moving to state 5. So the DP will add significant mass to state 5 during early steps. So the underflow of cur[4] at later steps doesn't matter because most of the mass has already moved to state 5. So DP should compute cur[5] close to 1. So it's fine.
Thus DP is robust.
Now, about the input reading: The line may have three numbers separated by spaces. Use sys.stdin.read().split().
Potential improvement: We can use sys.stdin.readline().split() if only one line, but we can use read().
Now finalize.
But we need to note that the problem states numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). p is given with exactly two digits after decimal point. So we can safely parse as float.
One more nuance: In DP, we use multiplication by p and (1-p) repeatedly. For p like 0.00 or 1.00, it's fine. However for p=0.00, (1-p) = 1.0, so no issue. For p=1.00, (1-p)=0.0, which leads to many multiplications by 0. But that's fine.
Now I'll write code.
But wait, we can also use the formula E = n - sum_{k=0}^{n-1} F(k) where F(k) = P(S_t <= k). But not necessary.
Now consider potential overflow of combinatorial numbers if we tried to compute using integers? Not needed.
Thus solution ready.
Now produce final answer: Provide explanation and code.
Since the user might expect a program, I'll provide Python code.
Let's also test with sample inputs.
Sample 1:
Input: "1 0.50 1"
Our code: n=1,p=0.5,t=1. DP: cur[0]=1. i=0: max_j = min(0,0)=0, loop j=0: stay=0.5, nxt[0]=0.5; enter=0.5, nxt[1]=0.5. n <=0 false. expected = 00.5+10.5=0.5. Print 0.5000000000 -> matches.
Sample2: "1 0.50 4" -> 0.9375. Print 0.9375000000. Good.
Sample3: "4 0.20 2" -> 0.4. Print 0.4000000000. Good.
Now additional test: n=5, p=0.5, t=2000 (large). Code should run quickly.
Now check memory: cur and nxt each size up to 2001 floats, fine.
Now we should consider that p is given as real with two decimals, but reading as float may cause small rounding error (e.g., 0.10 may be stored as 0.10000000149011612). That's okay; the error will be within tolerance.
Now finalize.
But wait: In DP, we used "if n <= i: nxt[n] += cur[n]". However, note that i is the number of seconds already processed. At iteration i (starting from 0), we are processing the (i+1)-th second. After processing this second, the new time is i+1. The condition for adding cur[n] should be if n <= i+1? Actually after we process the second, if we were already at n before (i seconds), then after the second we should still be at n (since no change). But if we reached n exactly at this second, that is via transition from n-1, then we also add to nxt[n] via the transition from j=n-1 in the loop. Then after that, we also add cur[n] (which was previous probability of being at n) to nxt[n] to keep it. So it's correct to add cur[n] regardless of whether n <= i? Actually if n > i, cur[n] is zero, so no effect. So we can always add cur[n] to nxt[n] (since if cur[n] > 0, we should keep it). But careful: If we are at n, we stay at n with probability 1. So indeed, regardless of i, we should add cur[n] to nxt[n]. However, our loop for j up to n-1 already added contributions to nxt[n] from cur[n-1] * p. But if we also add cur[n] to nxt[n], that accounts for staying. So we can simply do: after the loop for j=0..min(i, n-1), we can add cur[n] to nxt[n] unconditionally. Because cur[n] is only non-zero if we have already reached n at time i. And if we have reached n, we stay there. So that's correct. In our earlier condition, we used "if n <= i" to decide whether cur[n] could be non-zero. But cur[n] could be non-zero even if n = i+1? Actually, at time i (i seconds elapsed), the maximum possible j is i. So if n > i, cur[n] must be zero. So it's safe to always add cur[n], but it's just an extra addition of zero. So we can simply do: nxt[n] += cur[n]. That's simpler. No need for condition.
Thus we can update code to:
nxt = [0.0]*(n+1)
max_j = min(i, n-1)
for j in range(max_j+1):
stay = cur[j] * (1-p)
enter = cur[j] * p
nxt[j] += stay
nxt[j+1] += enter
nxt[n] += cur[n] # stay at n
cur = nxt
That works because for j = n-1, we already added cur[n-1]*p to nxt[n] inside the loop, and then we also add cur[n] to nxt[n] to keep the mass. If n <= i, cur[n] is non-zero; else it's zero. So correct.
Simplify: we can even loop j from 0 to n-1, but then we would be processing j values where cur[j] is zero for j > i. That's fine but adds extra zero operations. Our max_j reduces operations.
Thus final DP code:
cur = [0.0]*(n+1)
cur[0] = 1.0
for i in range(t):
nxt = [0.0]*(n+1)
# handle transitions for states that can change (j < n)
# Only need to consider j up to min(i, n-1) because cur[j] = 0 for j > i.
max_j = min(i, n-1)
for j in range(max_j+1):
if cur[j] != 0.0: # optional
stay = cur[j] * (1-p)
enter = cur[j] * p
nxt[j] += stay
nxt[j+1] += enter
# absorbing state n: stays
nxt[n] += cur[n]
cur = nxt
expected = sum(j * cur[j] for j in range(n+1))
Print.
Now we should confirm for n=1, t=4: i=0, max_j=0, loop j=0: nxt[0]=0.5, nxt[1]=0.5; nxt[1] += cur[1]=0 -> nxt[1]=0.5. cur = [0.5,0.5]. i=1, max_j = min(1,0)=0, loop j=0: nxt[0]=0.25, nxt[1]=0.25; nxt[1] += cur[1]=0.5 -> nxt[1]=0.75. cur = [0.25,0.75]. i=2, max_j=0, loop j=0: nxt[0]=0.125, nxt[1]=0.125; nxt[1] += cur[1]=0.75 -> 0.875. i=3: similarly. Good.
Thus works.
Now one more potential micro-optimization: We can avoid checking cur[j]!=0.0 because it's fast anyway.
Now about reading input: We'll read with sys.stdin.readline().
Final Python code:
import sys
def solve():
line = sys.stdin.readline().strip()
while line == "":
line = sys.stdin.readline().strip()
parts = line.split()
n = int(parts[0])
p = float(parts[1])
t = int(parts[2])
cur = [0.0] * (n + 1)
cur[0] = 1.0
for i in range(t):
nxt = [0.0] * (n + 1)
max_j = min(i, n - 1)
for j in range(max_j + 1):
prob = cur[j]
if prob != 0.0:
stay = prob * (1 - p)
enter = prob * p
nxt[j] += stay
nxt[j + 1] += enter
nxt[n] += cur[n] # absorbing
cur = nxt
expected = 0.0
for j, prob in enumerate(cur):
expected += j * prob
# output with sufficient precision
print("{:.10f}".format(expected))
if name == "main":
solve()
But note: If n=0? Not allowed. So n>=1. If n=2000, n-1=1999, for i up to 1999, max_j = i, but for i=2000? Actually i runs 0..t-1, with t=2000, so i max 1999, so max_j max 1999, which equals n-1 only if n-1 <= 1999. If n=2000, n-1=1999, and i max 1999, so max_j can be 1999 when i=1999. That's fine. For i=1999, we loop j=0..1999, which is all j < n. That's okay. However cur[j] for j > 1999? Actually after 1999 seconds, max successes is 1999, so cur[2000] is zero; we don't need to process j=2000 because it's absorbing and handled separately.
Now the inner loop does 2000 iterations when i=1999 and n=2000. That's 2000 iterations. Summing over i from 0 to 1999 gives about 2 million, as said.
Thus code is efficient.
Now, about floating point errors: For large t and p=0.5, the probabilities cur[j] might be very small for many j, but the sum of probabilities may drift due to rounding. However, the expected value computed from these probabilities may be accurate enough. To double-check, we could compute expected value using the identity E = sum_{k=1}^{n} P(S_t >= k) and compute P(S_t >= k) via regularized incomplete beta or using DP but with less accumulation? But I think it's fine.
But one more nuance: In DP, we multiply by p and 1-p each step. Over many steps, the product of many numbers might cause underflow if we kept a single probability, but because we maintain many states, the values remain within range.
Testing with p=0.5, t=2000: The probability of exactly 1000 successes is about 0.0178? Actually using Stirling, it's about 1/sqrt(pi*1000) ~ 0.0178. So cur[1000] is about 0.018, which is fine. Probabilities near the tails like cur[0] = 0.5^2000 ~ 9e-602, which underflows to 0. That's fine.
Now, could the DP lose probability mass because the sum of cur might become less than 1 due to underflow of many tail probabilities? Let's estimate the total probability of all states that might underflow. For p=0.5, the distribution is symmetric, the tails beyond, say, 400 standard deviations? Actually standard deviation sqrt(500) ≈ 22.36. The probability of being more than, say, 50 standard deviations away is astronomically small and underflows to 0. The sum of those tail probabilities is negligible (less than 1e-300). So the loss is far below 1e-6. So expected value error is negligible.
For p=0.99, the left tail (low successes) underflows, but the total probability of having less than, say, 1000 successes is extremely small (since mean 1980, standard deviation sqrt(20000.990.01) = sqrt(19.8) ≈ 4.45, so probability of being below 1000 is effectively zero, many many standard deviations away). So loss is negligible.
Thus DP is safe.
Now finalize solution.
But wait: The problem might be from Codeforces Round? Actually I recall a problem "Escalator" maybe. The typical solution uses DP as described.
Thus I'll present final answer with explanation and code.
Now output should be a real number. In Python, printing with 10 decimal places should suffice. However, to be absolutely safe about precision, we could print with 12 decimal places.
I'll set print("{:.12f}".format(expected)).
Now final code.
One more check: Input may have multiple lines? It's just one line. But we'll use sys.stdin.readline().
Edge: if input contains trailing spaces, .split() handles it.
Alright.
Now produce final answer. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
p = float(data[1])
t = int(data[2])
# dp[j] = probability that exactly j people have entered the escalator
# after the current number of seconds processed.
cur = [0.0] * (n + 1)
cur[0] = 1.0
for i in range(t): # i seconds have already passed
nxt = [0.0] * (n + 1)
# only states 0..min(i, n-1) can have non‑zero probability
max_j = min(i, n - 1)
for j in range(max_j + 1):
prob = cur[j]
if prob == 0.0:
continue
stay = prob * (1.0 - p)
enter = prob * p
nxt[j] += stay
nxt[j + 1] += enter
# absorbing state: once all n have entered, nothing changes
nxt[n] += cur[n]
cur = nxt
expected = 0.0
for j, prob in enumerate(cur):
expected += j * prob
# required precision 1e-6
print("{:.12f}".format(expected))
if name == "main":
solve()