407611: GYM102860 B Triangles and a Circle

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Triangles and a Circletime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

You are given $$$n$$$ distinct points on a circle of length $$$L$$$.

You need to find the number of triangles with vertices in these points that contain the center of the circle inside, or on their border.

Input

The first line of input contains two integers $$$n$$$ and $$$L$$$ ($$$3 \leq n \leq 300\,000$$$, $$$n \leq L \leq 10^9$$$).

Let's choose any point on the circle and call it $$$S$$$. Then any point $$$A$$$ on the circle can be encoded as $$$x$$$, $$$0 \le x < L$$$: clockwise distance from $$$S$$$ to $$$A$$$. We will call this number a coordinate of $$$A$$$.

The second line contains $$$n$$$ distinct integers $$$x_1, x_2, \ldots, x_n$$$: coordinates of the given points on the circle ($$$0 \leq x_i < L$$$).

Output

Print one integer: the number of triangles with vertices in the given points, that contain the center of the circle inside or on their border.

ExamplesInput
3 10
0 1 2
Output
0
Input
10 10
0 1 2 3 4 5 6 7 8 9
Output
60

加入题单

上一题 下一题 算法标签: