Good Triplets


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

In a plane, there is a circle with center coordinates (0,0) and circumference C.

There are C integer points on the circumference, numbered 0 to C-1.

Among them:

  • Point 0: the rightmost point on the circle
  • Points 1 to C-1: the counterclockwise arc length from point 0 to the point itself exactly equals its own number

Given an integer sequence P1, P2, ..., PN of length N (where 0 ≤ Pi ≤ C-1).

Please calculate how many distinct integer triples (a, b, c) simultaneously satisfy:

  1. 1 ≤ a < b < c ≤ N
  2. The origin (0,0) is strictly inside the triangle with vertices at points Pa, Pb, Pc
    (Note: points on the edges of the triangle are not considered inside)

Input Format

  • First line: two integers N, C
  • Second line: N integers P1, P2, ..., PN

Output Format

One integer representing the number of triples that satisfy the conditions.


Constraints

  • 3 ≤ N ≤ 106
  • 3 ≤ C ≤ 106
  • 0 ≤ Pi ≤ C-1
  • Note: The Pi are not necessarily distinct

Example

Input:

8 10
0 2 5 5 6 9 0 0

Output:

6

Explanation:

The triples that satisfy the condition are:
(1,2,5), (2,3,6), (2,4,6), (2,5,6), (2,5,7), (2,5,8)


Comments

There are no comments at the moment.