import java.math.RoundingMode import kotlin.math.PI import kotlin.math.acos import kotlin.math.pow /** * At first sight: Circles that is scary. Reading it again, oh this is quite easy. Then take to long to properly implement it. * This problem is like an addict, you think you can solve it easily, but every step during the way new problems pop up. * But every big pitfall seems to be covered in the examples. * Pitfall: The distance is the shortest distance, not following the circle line (distance is the chord, not the arc) (example 3 fails) * Pitfall: Precision in doubles can be tricky. Example 2 failed until I started rounding on the 6th digit */ const val CIRCLE = 2 * PI fun main() { val input = System.`in`.bufferedReader() val (circles, distance) = input.readLine().split(" ").take(2).map { it.toDouble() } val radii = input.readLine().split(" ").take(circles.toInt()).map { it.toDouble() } println(radii.sumOf { val squared = it.pow(2) val alpha = acos((squared * 2 - distance.pow(2)) / (2 * squared)) when { alpha.isNaN() -> 0 else -> (CIRCLE / alpha).toBigDecimal().setScale(6, RoundingMode.HALF_UP).toLong() } }) }