luogu#P4889. kls与flag

kls与flag

Background

kls is very good at “poisoning milk” (du nai).

Problem Description

There are nn OI contestants, and each of them set up a flag. One day, for some reason, all the flags were triggered, so there is a row of nn bamboo poles on the ground. The distance between adjacent poles is 11 unit, and their heights are in 1m1 \sim m.

When kls saw these bamboo poles, he felt they did not look nice, so he plans to knock all of them down.

Before doing that, kls thought of a math problem. Each bamboo pole can fall to the left or to the right. If, after choosing their falling directions, the top ends of two bamboo poles can coincide, then we call this pair excellent. Now kls wants to know how many pairs of bamboo poles are excellent.

Input Format

The first line contains two integers n,mn, m, representing the number of bamboo poles and the maximum height.

The second line contains nn positive integers, representing the height of each bamboo pole.

Output Format

Output one line with a single integer, representing how many pairs of bamboo poles are excellent.

5 5
2 3 3 3 2
3

Hint

Sample Explanation

Fafa

  • Poles 11 and 22 can have their top ends coincide if they both fall to the left.
  • Poles 44 and 55 can have their top ends coincide if they both fall to the right.
  • Pole 11 falling to the right and pole 55 falling to the left can have their top ends coincide.

Constraints

For 30%30\% of the testdata, n2000n \le 2000, m5000m \le 5000.

For 60%60\% of the testdata, n200000n \le 200000, m500000m \le 500000.

For 100%100\% of the testdata, n200000n \le 200000, m109m \le 10^9.

Translated by ChatGPT 5