local n = io.read("*n") local p, q = io.read("*n", "*n") r, l = {}, {} for i = 0, n+1 do r[i], l[i] = 0, 0 end r[1] = 1 local rem = 1 local genten = r[1] * p local migi = 0 local sinda = 0 local s, t = {}, {} s[0] = 0 t[0] = 0 s[n+1] = 0 t[n+1] = 0 local tgt_r, tgt_l, prv_r, prv_l = s, t, r, l while(0.001 <= rem) do for i = 1, n do tgt_r[i] = prv_r[i - 1] * q + prv_l[i - 1] * p tgt_l[i] = prv_l[i + 1] * q + prv_r[i + 1] * p sinda = sinda + (prv_r[i] + prv_l[i]) * (1 - p - q) end genten = genten + prv_l[1] * q migi = migi + prv_r[n] * q rem = 1 - sinda - genten - migi if(tgt_r == s) then tgt_r, tgt_l, prv_r, prv_l = r, l, s, t else tgt_r, tgt_l, prv_r, prv_l = s, t, r, l end end print(genten)