AT_abc444_e [ABC444E] Sparse Range
Description
You are given an integer sequence of length $ N $ , $ (A_1,\dots,A_N) $ , and a positive integer $ D $ .
Find the number of pairs of integers $ (L,R) $ that satisfy both of the following conditions:
- $ 1 \leq L \leq R \leq N $
- Any two elements of $ (A_L,A_{L+1},\dots,A_R) $ have a difference of at least $ D $ .
- That is, $ |A_i-A_j|\geq D $ for all pairs of integers $ (i,j) $ satisfying $ L \leq i < j \leq R $ .
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ D $ $ A_1 $ $ \dots $ $ A_N $
Output Format
Output the answer.
Explanation/Hint
### Sample Explanation 1
The eight pairs $ (1,1),(2,2),(3,3),(4,4),(5,5),(2,3),(3,4),(4,5) $ satisfy the conditions.
### Constraints
- $ 2\leq N \leq 4\times 10^5 $
- $ 1 \leq A_i \leq 10^9 $
- $ 1 \leq D \leq 10^9 $