#P8398. Counting Good Triangles

    ID: 21575 Type: Default 1000ms 256MiB

Counting Good Triangles

Counting Good Triangles

Andrew is a very curious student. One day, he drew a circle with center at \( (0,0) \) and circumference \( C \). Every point \( p \) on the circle has coordinates given by an expression (as shown in the image). Andrew later marked \( n \) points on the circle. The \( i\)-th point is marked at position \( p_i \), and note that multiple points might be marked at the same position.

A triangle \((a, b, c)\) (with \(1 \le a < b < c \le n\)) formed by points \( p_a, p_b, p_c \) is called a good triangle if the origin \( (0,0) \) lies strictly inside the triangle (i.e. it is not on the boundary of the triangle).

For a triangle inscribed in a circle, a necessary and sufficient condition for the origin (the center of the circle) to lie inside the triangle is that none of the arcs between consecutive vertices (when the points are arranged in clockwise order) has a length \( \ge \frac{C}{2} \). In other words, if you sort the points by their positions along the circle, then for any triple the triangle is good if and only if the maximum arc between consecutive points (taking the wrap‐around into account) is strictly less than \( \frac{C}{2} \).

Your task is to count the number of good triangles.

inputFormat

The first line contains two numbers: an integer \( n \) and a real number \( C \) denoting the number of points and the circumference of the circle, respectively.

The second line contains \( n \) real numbers \( p_1, p_2, \ldots, p_n \) representing the positions of the points on the circle. These positions are given as distances along the circumference from some fixed starting point. Note that the points are not necessarily in sorted order and there may be duplicates.

outputFormat

Output a single integer: the number of good triangles.

sample

3 360
0 120 240
1