luogu#P4889. kls与flag
kls与flag
Background
kls is very good at “poisoning milk” (du nai).
Problem Description
There are 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 bamboo poles on the ground. The distance between adjacent poles is unit, and their heights are in .
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 , representing the number of bamboo poles and the maximum height.
The second line contains 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

- Poles and can have their top ends coincide if they both fall to the left.
- Poles and can have their top ends coincide if they both fall to the right.
- Pole falling to the right and pole falling to the left can have their top ends coincide.
Constraints
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
Translated by ChatGPT 5