Rounddog always has an array $a_1, a_2, \cdots, a_n$ in his right pocket, satisfying $1 \le a_i \le n$.
A subarray is a non-empty subsegment of the original array. Rounddog defines a good subarray as a subsegment $a_l, a_{l+1}, \cdots, a_r$ that all elements in it are different and $\max({a_l, a_{l+1}, \ldots, a_r}) - (r - l + 1) \leq k$.
Rounddog is not happy today. As his best friend, you want to find all good subarrays of $a$ to make him happy. In this case, please calculate the total number of good subarrays of $a$.