RoAlgo Contest #12 - NiceContest | B. Nice Mustache Growth

This was the problem page during the contest. Access the current page here.
Time limit: 0.2s Memory limit: 64MB Input: Output:

Vasile has a mustache of gigantic proportions and wishes to trim it. His mustache can be seen as a vector, AA, of NN elements, where AiA_i = the length of the iith hair, i[0,N)\forall i \in [0, N). We define the ugliness degree of an interval [l,r][l, r] as the difference between the longest and the shortest hair in the interval [l,r][l, r].

Task

Determine how many intervals [l,r][l, r] exist such that the ugliness degree is between aa and bb.

Input data

The first line contains the natural number NN, as described above.
The second line contains the natural numbers aa and bb, as described above.
The third line contains NN natural numbers, representing the vector AA.

Output data

The first line will contain a single integer, representing the number of intervals [l,r][l, r] such that the ugliness degree is between aa and bb.

Constraints and clarifications

  • 1N100 0001 \leq N \leq 100 \ 000
  • 0ab1090 \leq a \leq b \leq {10}^{9}
  • 0Ai1090 \leq A_i \leq {10}^{9}
  • For 30%30 \% of the tests: N100N \leq 100
  • For 60%60 \% of the tests: N1 000N \leq 1 \ 000
  • Recall that AA is indexed from 00
  • It is recommended to use fast I/O

Example 1

stdin

6
4 5
1 7 5 4 2 6

stdout

5

Explanation

max([1,4])min([1,4])=72=5max([1, 4]) - min([1, 4]) = 7 - 2 = 5
max([1,5])min([1,5])=72=5max([1, 5]) - min([1, 5]) = 7 - 2 = 5
max([2,5])min([2,5])=62=4max([2, 5]) - min([2, 5]) = 6 - 2 = 4
max([3,5])min([3,5])=62=4max([3, 5]) - min([3, 5]) = 6 - 2 = 4
max([4,5])min([4,5])=62=4max([4, 5]) - min([4, 5]) = 6 - 2 = 4

Example 2

stdin

5
0 0
1000000000 1000000000 1000000000 1000000000 1000000000

stdout

15

Explanation

All intervals have an ugliness degree of 00.

Log in or sign up to be able to send submissions!