
There are $N$ buildings standing in a row in a city. The $i$-th building from the left has height $h_i$.
Every building manager is diligent and wants to benchmark the rooftop gardens of other buildings. Each manager can look only to the right from their own building, so manager $i$ initially wants to see the rooftops of buildings $i+1, i+2, \dots, N$.
The view can be blocked, however. Looking to the right, the moment a manager meets a building whose height is greater than or equal to their own, that building and every building beyond it become invisible. In other words, manager $i$ can only see a consecutive run of strictly shorter buildings, and the view is blocked as soon as the first building of height at least $h_i$ appears (that blocking building is not counted either).
Find the total number of rooftop gardens that all managers can benchmark.
For example, consider $N = 6$ with heights $H = {10, 3, 7, 4, 12, 2}$, illustrated below.
=
= =
= - =
= = = -> viewing direction
= - = = =
= = = = = =
10 3 7 4 12 2 -> building heights
[1][2][3][4][5][6] -> building numbers
Therefore the total is $3 + 0 + 1 + 0 + 1 + 0 = 5$.