Probability Experiment

Count the triples of given points on a circle that form an acute triangle.

Medium6Two pointersCombinatoricsGeometryNo attempts yetTime limit1sMemory limit256 MB

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 π\pi.

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.250.25. To check whether a simulation lands near that value, count the acute triangles in one sample. Given NN 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 NN and the radius RR of the circle. (1N2000001 \le N \le 200000, 1R1000001 \le R \le 100000)

The circle is centered at the origin. When a point PP on the circle sits θ\theta degrees counterclockwise from the positive xx axis, its position is written as ϕ=θ×1000\phi = \theta \times 1000, so the coordinates of PP are (Rcosθ, Rsinθ)(R\cos\theta,\ R\sin\theta).

Each of the next NN lines has the ϕ\phi value of one point, given in increasing order of ϕ\phi. Every ϕ\phi is an integer (0ϕ<3600000 \le \phi < 360000), and the NN 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++).