Leaning Lantern Frames
In the Lantern Arcade there are lanterns in a straight row, indexed through from left to right. The height of lantern is .
A camera frame is a contiguous group of lanterns, described by two indices and with . Inside the frame, let be the maximum height among .
The frame is called leaning if both conditions hold:
- there is exactly index with and ;
Count how many camera frames are leaning.
Input
The first line contains an integer (), the number of lanterns. The second line contains space-separated integers (), the heights of the lanterns in left-to-right order. Lanterns are indexed through in the order given.
Output
Print integer on line: the number of leaning camera frames.
Samples
Sample 1
Input
5 3 1 4 2 5
Output
8
The leaning frames are , , , , , , , and .