Problem: Count subarrays with at most distinct elements.
Approach: For each right endpoint, find smallest valid left. Count: subarrays ending at right.
Trick: "Exactly " = "At most " "At most ". Counting exactly directly is complex; subtracting two simpler counts avoids edge cases.