Count the triples of given points on a circle that form an acute triangle.
Medium6Two pointersCombinatoricsGeometryNo attempts yetTime limit1sMemory limit256 MBRunning 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 0.25. To check whether a simulation lands near that value, count the acute triangles in one sample. Given N 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.

The first line has the number of points N and the radius R of the circle. (1≤N≤200000, 1≤R≤100000)
The circle is centered at the origin. When a point P on the circle sits θ degrees counterclockwise from the positive x axis, its position is written as ϕ=θ×1000, so the coordinates of P are (Rcosθ, Rsinθ).
Each of the next N lines has the ϕ value of one point, given in increasing order of ϕ. Every ϕ is an integer (0≤ϕ<360000), and the N values are all different.
Print the number of acute triangles.
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++).