Three points:
Recognizing arithmetic sequences lets you apply closed-form counting formulas instead of nested loops.
The number of subarrays of length at least in a sequence of length is , derived from summing .
Track state (current sequence length and difference) to avoid recomputing from scratch at each position.