From Codeforces. Tangent circles. Solve the geometry problem "NN and the Optical Illusion".
Examples
Input:[1,2,3]
Output:0
Input:[2,3,4]
Output:0
Hints
Outer circle centers form a regular n-gon around inner center. Each outer center is distance R+r from inner center; adjacent outer centers are distance 2r apart (tangent).
Law of cosines on isosceles triangle: (2r)² = (R+r)² + (R+r)² − 2(R+r)² cos(2π/n). Simplify using 1−cosθ = 2 sin²(θ/2) → r = R·sin(π/n) / (1−sin(π/n)).
As n→2, sin(π/n)→1, denominator → 0, solution blows up — output instability for small n. For large n, r ≈ Rπ/n. Use double precision throughout.
NN and the Optical Illusion
**From Codeforces.** Tangent circles. Solve the geometry problem "NN and the Optical Illusion".