{"raw_statement":[{"iden":"statement","content":"Bob has discovered a new quality in himself — he likes to trick people a lot! In particular, Bob wants to try his tricking skills in the shell game.\n\nThe shell game involves three identical cups and a single ball. In the beginning the host (that's Bob!) puts the cups upside down and places the ball inside one of the cups. Then he shuffles the cups and the player has to guess where the ball is. The host then lifts that cup, revealing whether the ball was inside or not. The player wins if he makes a correct guess, otherwise the host wins.\n\nThe form of each cup is a sliced cone. Formally, the base of the cup is a circle with radius r, and the opening of the cup is a circle with radius R. The height of the cup is equal to h. A ball for the shell game is simply a sphere.\n\nWhat the player is not going to know is that Bob smeared the inner surface of each cup with glue, resulting in the cup holding the ball when Bob lifts it up — so the player will never win! However, the ball will stick only if it touches the inner surface of a cup. For this reason Bob wants to get the largest possible ball that fits inside the cup when the cup is placed upside down on the table.\n\nBob has already found three identical cups in his grandmother's locker — now he only has to buy a ball of the required size so that he may start playing the shell game. Help Bob and calculate the largest size of such a ball!\n\nThe first line contains three space-separated integers r, R and h, the radii of the base and the opening, and the height of the cup (1 ≤ r < R ≤ 104, 1 ≤ h ≤ 104).\n\nOutput a single number — the radius of the largest ball that can fit in the cup. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.\n\n"},{"iden":"input","content":"The first line contains three space-separated integers r, R and h, the radii of the base and the opening, and the height of the cup (1 ≤ r < R ≤ 104, 1 ≤ h ≤ 104)."},{"iden":"output","content":"Output a single number — the radius of the largest ball that can fit in the cup. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6."},{"iden":"examples","content":"Input3 4 8Output3.531128874149"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ r, R, h \\in \\mathbb{R}^+ $ be the base radius, top radius, and height of a frustum-shaped cup, with $ 1 \\leq r < R \\leq 10^4 $ and $ 1 \\leq h \\leq 10^4 $.  \n\n**Objective**  \nFind the radius $ \\rho $ of the largest sphere that can fit inside the frustum when placed upside down (i.e., with the larger circle $ R $ at the bottom and smaller circle $ r $ at the top), such that the sphere is tangent to the inner lateral surface and the base.  \n\n**Geometric Constraint**  \nThe sphere is inscribed in the frustum, touching:  \n- The conical lateral surface,  \n- The circular base of radius $ R $.  \n\nThe largest such sphere is tangent to the frustum’s lateral side and rests on the base. The problem reduces to finding the radius of the incircle of the isosceles trapezoid cross-section through the axis of the frustum, inscribed in the right triangle formed by extending the frustum to a full cone.  \n\nLet the full cone have height $ H $ and base radius $ R $. The frustum is a slice of this cone at height $ H - h $, leaving a smaller cone of height $ H - h $ and base radius $ r $. By similar triangles:  \n$$\n\\frac{r}{R} = \\frac{H - h}{H} \\quad \\Rightarrow \\quad H = \\frac{hR}{R - r}\n$$\n\nThe inscribed sphere of radius $ \\rho $ touches the lateral side and the base. Consider the right triangle formed by the axis, the radius $ R $, and the slant side. The inscribed circle in this triangle (tangent to the base and the hypotenuse) has radius:  \n$$\n\\rho = \\frac{R \\cdot (H - h)}{\\sqrt{R^2 + H^2} + R}\n$$\n\nBut since the sphere must fit entirely within the frustum and touch the lateral wall and the base, we use the standard formula for the radius of the largest sphere inscribed in a frustum of a cone, resting on the larger base:  \n\n$$\n\\rho = \\frac{r + R}{2} \\cdot \\frac{h}{\\sqrt{(R - r)^2 + h^2} + \\frac{R + r}{2}}\n$$\n\nActually, the correct and standard derivation:  \n\nConsider the 2D cross-section: an isosceles trapezoid with bases $ 2R $ and $ 2r $, height $ h $. The largest circle inscribed in this trapezoid (touching both non-parallel sides and the longer base) has radius:  \n\nLet $ \\theta $ be the angle between the slant side and the vertical. Then:  \n$$\n\\tan \\theta = \\frac{R - r}{h}\n$$\n\nThe center of the sphere lies along the central axis at height $ \\rho $ above the base. The distance from the center to the slant side must be $ \\rho $.  \n\nThe perpendicular distance from the axis to the slant side at height $ y $ is $ R - y \\cdot \\frac{R - r}{h} $.  \n\nAt height $ \\rho $, the horizontal distance from axis to wall is $ R - \\rho \\cdot \\frac{R - r}{h} $.  \n\nThis must equal $ \\rho $, because the sphere touches the wall:  \n$$\nR - \\rho \\cdot \\frac{R - r}{h} = \\rho\n$$\n\nSolve for $ \\rho $:  \n$$\nR = \\rho \\left(1 + \\frac{R - r}{h}\\right)\n\\quad \\Rightarrow \\quad\n\\rho = \\frac{R}{1 + \\frac{R - r}{h}} = \\frac{R h}{h + R - r}\n$$\n\nWait — this is incorrect because the sphere touches the *lateral side* and the *base*, but the horizontal distance from axis to wall at height $ \\rho $ is not simply $ R - \\rho \\cdot \\frac{R - r}{h} $ — that’s the radius of the frustum at that height, and the sphere’s center is at height $ \\rho $, so the horizontal distance from center to wall is $ R - \\rho \\cdot \\frac{R - r}{h} $, and this must equal the radius of the sphere $ \\rho $, since the sphere is tangent to the wall.  \n\nSo:  \n$$\nR - \\rho \\cdot \\frac{R - r}{h} = \\rho\n\\Rightarrow R = \\rho \\left(1 + \\frac{R - r}{h}\\right)\n\\Rightarrow \\rho = \\frac{R}{1 + \\frac{R - r}{h}} = \\frac{R h}{h + R - r}\n$$\n\nBut this gives a sphere that touches the lateral side and the base — and since the cup is upside down, the base is the large circle $ R $, and the top is small $ r $. So the sphere rests on the large base and touches the sloped side.  \n\nIs this the maximal possible? Yes, because if it were larger, it would protrude above the frustum or not fit within the narrowing walls.  \n\n**Final Formula**  \n$$\n\\rho = \\frac{R h}{h + R - r}\n$$\n\nBut wait — this formula gives a sphere that touches the lateral side and the base, but is it entirely contained? Let’s verify: at the top of the sphere (height $ 2\\rho $), the radius of the frustum is $ R - 2\\rho \\cdot \\frac{R - r}{h} $. We must ensure that this is $ \\geq 0 $, and that the sphere doesn’t intersect the top rim. But the sphere’s top is at height $ 2\\rho $, and the frustum’s radius at that height is $ R - 2\\rho \\cdot \\frac{R - r}{h} $. The sphere has radius $ \\rho $, so at height $ 2\\rho $, the sphere’s horizontal extent is 0 (it’s the top point). So as long as the frustum’s radius at height $ 2\\rho $ is $ \\geq 0 $, it’s fine. But we don’t require the sphere to touch the top — only the base and the side. So the formula is correct.  \n\nActually, the standard known result for the largest sphere inscribed in a frustum (resting on the larger base) is:  \n\n$$\n\\rho = \\frac{r R + \\sqrt{r R (r R + h^2)}}{r + R + \\sqrt{(R - r)^2 + h^2}}\n$$\n\nNo — simpler and correct derivation:  \n\nThe sphere touches the conical surface. The cone’s side has slope $ m = \\frac{R - r}{h} $. The distance from the center of the sphere (at $ (0, \\rho) $) to the slant side must be $ \\rho $.  \n\nThe slant side is a line from $ (R, 0) $ to $ (r, h) $. The equation of this line:  \n\nParametrize: from point $ (R, 0) $ to $ (r, h) $. The direction vector is $ (r - R, h) $.  \n\nThe line equation:  \n$$\n\\frac{y - 0}{x - R} = \\frac{h}{r - R} \\Rightarrow y = \\frac{h}{r - R}(x - R)\n$$\n\nRewrite:  \n$$\n\\frac{h}{R - r}(R - x) = y \\quad \\text{(since } r - R = -(R - r)\\text{)}\n$$\n\nSo:  \n$$\ny = \\frac{h}{R - r}(R - x)\n$$\n\nThe distance from point $ (0, \\rho) $ to this line must be $ \\rho $.  \n\nGeneral distance from point $ (x_0, y_0) $ to line $ ax + by + c = 0 $:  \n\nWrite line as:  \n$$\n\\frac{h}{R - r} x + y - \\frac{h R}{R - r} = 0\n\\Rightarrow h x + (R - r) y - h R = 0\n$$\n\nSo $ a = h $, $ b = R - r $, $ c = -h R $  \n\nDistance from $ (0, \\rho) $:  \n$$\n\\frac{|h \\cdot 0 + (R - r)\\rho - h R|}{\\sqrt{h^2 + (R - r)^2}} = \\rho\n$$\n\nSo:  \n$$\n\\frac{|(R - r)\\rho - h R|}{\\sqrt{h^2 + (R - r)^2}} = \\rho\n$$\n\nSince $ (R - r)\\rho - h R < 0 $ (because $ \\rho < R $ and $ h R $ is large), we drop absolute value with sign change:  \n$$\n\\frac{h R - (R - r)\\rho}{\\sqrt{h^2 + (R - r)^2}} = \\rho\n$$\n\nMultiply both sides:  \n$$\nh R - (R - r)\\rho = \\rho \\sqrt{h^2 + (R - r)^2}\n$$\n\nBring terms with $ \\rho $ to one side:  \n$$\nh R = \\rho \\left( (R - r) + \\sqrt{h^2 + (R - r)^2} \\right)\n$$\n\nTherefore:  \n$$\n\\boxed{\n\\rho = \\frac{h R}{(R - r) + \\sqrt{h^2 + (R - r)^2}}\n}\n$$\n\nThis is the correct formula.  \n\n**Final Formal Statement**\n\n**Definitions**  \nLet $ r, R, h \\in \\mathbb{R}^+ $ satisfy $ 1 \\leq r < R \\leq 10^4 $ and $ 1 \\leq h \\leq 10^4 $. The cup is a frustum of a cone with base radius $ R $, top radius $ r $, and height $ h $, oriented with the larger base on the table.  \n\n**Objective**  \nFind the radius $ \\rho $ of the largest sphere that fits inside the frustum and is tangent to its lateral surface and base:  \n$$\n\\rho = \\frac{h R}{(R - r) + \\sqrt{h^2 + (R - r)^2}}\n$$","simple_statement":"Find the largest ball radius that can fit inside an upside-down cup shaped like a frustum, with base radius r, top radius R, and height h.","has_page_source":false}