Algorithm question: Codeforces 251A two points

Source: Internet
Author: User

Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya are wondering in many ways he can choose three distinct points the distance between Of them doesn ' t exceed D.

Note This order of the points inside the group of three chosen points doesn ' t matter.

Input

The contains two integers:n and D (1≤n≤105; 1≤d≤109). The next line contains n integers x1,x2,..., xn their absolute value doesn ' t exceed 109-the x-coordinates of the points That Petya has got.

It is guaranteed this coordinates of the points in the input strictly increase.

Output

Print a single integer-the number of groups of three points, where the distance, between two farthest points ' t doesn Ed D.

Please don't use the%lld specifier to read or write 64-bit integers inс++. It is preferred to use the CIN, cout streams or the%i64dspecifier.

Sample Input

Input

4 3

1 2 3 4

Output

4

Input

4 2

-3-2-1 0

Output

2

Input

5 19

1 10 20 30 50

Output

1

Hint

In the three points meets we conditions of the any group.

In the seconds sample only 2 groups of three points meet we conditions: { -3,-2,-1} and {-2,-1, 0}.

In the third sample only one group does: {1, 10, 20}.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.