For the subarray to be sorted starting from the $i$-th integer to the $j$-th integer, for all $k$ such that $i \le k < j$, the condition $A_k < A_{k+1}$ should be satisfied.
This condition can be checked by simply checking all adjacent elements. That is, if we set $B_k$ as `True`

or `False`

based on whether $A_k < A_{k+1}$ is true, for the subarray to be ascending starting from the $i$-th integer to the $j$-th integer, $B_i, B_{i+1}, \cdots, B_{j-1}$ must all be true.

There are multiple ways to count such $(i, j)$ pairs.

- For the case $i = j$, the subarray is always sorted. There are $N$ possible cases like this.
- For the case $i \ne j$, take a contiguous
`True`

block. For any possible combination of starting and ending points within the block, the condition is satisfied. If the length of the block is $k$, there are $\frac{k(k+1)}{2}$ combinations.

The answer is the sum of $\frac{k(k+1)}{2}$ for each continuous block of length $k$ in $B$. All calculations can be performed in $\mathcal O (N)$ time.