407773: GYM102892 2 Egocentric Subarrays
Description
You have an array $$$a$$$ consisting of $$$n$$$ positive integers, and an integer $$$k$$$.
You call a subarray an egocentric subarray if the difference between the maximum and minimum elements of the subarray is equal to $$$k$$$.
Recall that a subarray is a contiguous segment of elements of the original array, in order.
For example, if $$$a = [5, 4, 1, 2, 3, 6]$$$ and $$$k = 3$$$, then $$$[4, 1]$$$, $$$[4, 1, 2, 3]$$$, and $$$[3, 6]$$$ are egocentric subarrays, while $$$[5, 4, 1, 2]$$$, $$$[4, 1, 2, 3, 6]$$$, and $$$[5]$$$ are not.
Your task is to find the number of egocentric subarrays in the array.
InputThe first line of input contains two space-separated integers $$$n$$$ $$$(1 <= n <= 100)$$$ and $$$k$$$ $$$(1 <= k <= 10^9)$$$: the length of the array, and the number to find if the difference is equal to, respectively.
The next line consists of $$$n$$$ space-separated integers: the array elements $$$(1 <= a_i <= 10^9)$$$.
OutputOutput the number of egocentric subarrays of the array.
ScoringFull problem: 7 points
ExamplesInput5 3 5 4 1 2 3Output
3Input
11 7 1 3 7 6 4 2 11 18 12 9 1Output
2Note
In the first example, $$$[4, 1]$$$, $$$[4, 1, 2]$$$, and $$$[4, 1, 2, 3]$$$ are egocentric subarrays.
In the second example, $$$[11, 18]$$$ and $$$[11, 18, 12]$$$ are egocentric subarrays.