YangQiShaoNian has an array of length $n$, a subarray $[l,r]$ in the array is good if and only if each element in $a_l,a_{l+1},\dots a_r$ appears exactly $k$ times in the current interval.
For example, for $a=[1,1,2,3,2,3,1]$ and $k=2$, the intervals $[1,2]$, $[3,6]$, $[1,6]$, etc., are all good. However, $[1,3]$ does not meet the condition because the element $2$ appears only once, and $[1,7]$ does not meet the condition because the element $1$ appears $3$ times.
Please help YangQiShaoNian to find the number of good intervals that can be selected.