Fish Between the Guards
Gats has arranged bowls in a row. Bowl contains fish, and every bowl contains a different number of fish.
Gats chooses two different bowls and , where , and places one guard cat at each of them. This placement is well-framed if every bowl satisfying has a fish count strictly between the counts at the two guarded bowls. Formally, it must satisfy
for every such that .
If , there are no bowls between the guards, so the placement is automatically well-framed.
Count the number of well-framed pairs .
Input
The first line contains an integer (), the number of bowls.
The second line contains integers . They form a permutation of the set .
Output
Print one integer: the number of well-framed pairs .
Samples
Sample 1
Input
5 3 1 4 5 2
Output
5
The five well-framed placements are , , , , and .