Probability Experiment
Time limit1sMemory limit256 MB
Count the triples of given points on a circle that form an acute triangle.
- Level
Medium6 of 10
- Topics
- Two pointers, Combinatorics, Geometry
- Solved
- No attempts yet
Problem
Running a probability experiment as a computer simulation is a standard tool in mathematics and statistics. Draw a circle inside a large square, scatter a huge number of random points, and the fraction that lands inside the circle approximates .
Here is a different experiment. Pick three random points on the circumference of a circle and consider the probability that the triangle they form is acute. A triangle is acute when all three of its interior angles are smaller than 90 degrees. A short calculation shows that this probability is . To check whether a simulation lands near that value, count the acute triangles in one sample. Given points on a circle, count how many acute triangles can be formed by choosing three of them. Count the same triangle only once: after counting triangle abc, do not count bca, cab, or cba again.
Input

The first line has the number of points and the radius of the circle. (, )
The circle is centered at the origin. When a point on the circle sits degrees counterclockwise from the positive axis, its position is written as , so the coordinates of are .
Each of the next lines has the value of one point, given in increasing order of . Every is an integer (), and the values are all different.
Output
Print the number of acute triangles.
Hint
The intermediate values and the answer can exceed the range of a 32-bit integer, so use a 64-bit integer type (long long in C++).