```
int numberOfArithmeticSlices(vector<int>& A) {
int subc = 2, count = 0;
for (auto i = A.begin()+2; i <= A.end(); ++i)
i<A.end() && *i-*(i-1)==*(i-1)-*(i-2)? ++subc : subc = ((count+=(subc-1)*(subc-2)/2), 2);
return count;
}
```

**Key observation:**

- Arithmetic array of size
`N`

has exactly`(N-1)*(N-2)/2`

arithmetic slices. - Any array
`A`

can be uniquely partitioned into consecutive arithmetic subsections {`sub`

_{i=1:M}}, where adjacent`sub`

_{i}and`sub`

_{i+1}share exactly one element at boundary.

For example, array

`A = [1, 2, 3, 4, 6, 8, 10, 12, 15]`

can be uniquely partitioned into consecutive arithmetic subsections:`[1, 2, 3, 4], [4, 6, 8, 10, 12], [12, 15]`

.

Adding up count of arithmetic slices for each subsection gives the total count.

**Note:** Do not count arithmetic slices for a subsection if not complete scanning an entire subsection yet. This makes sure to update total count for minimum number of times.