Cats and the Threaded Posts
Gats has placed scratching posts in a row and tied a long thread among them. The -th post has height , and all post heights are distinct.
Gats chooses two posts with indices and , where . This choice forms a smooth span if every post strictly between them has a height strictly between the two endpoint heights. In other words, for every index satisfying ,
If , there are no inner posts, so the span is considered smooth.
Count the number of smooth spans Gats can choose.
Input
The first line contains an integer (), the number of posts.
The second line contains pairwise distinct integers (), where is the height of the -th post.
Output
Print one integer: the number of smooth spans .
Samples
Sample 1
Input
5 4 1 3 5 2
Output
5
The valid endpoint pairs are , , , , and .