Scan the array and track the length of the current arithmetic sequence. When the difference changes, count the slices from the previous sequence and reset.
For each position, check if equals the previous difference. If yes, increment the sequence length. If no, use the formula to count slices and start a new sequence.
This takes time with space. The summation formula eliminates nested loops.