#### Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

## Problem Description

There are *N* guard towers, with the *i*th guard tower from the left having height *H _{i}*. Two guard towers can see each other if no guard tower between them has a strictly greater height than both of the guard towers.

More specifically, guard towers *i* and *j* can see each other if there exists no *k* such that *i* < *k* < *j* and *H _{k}* > max(

*H*,

_{i}*H*).

_{j}
Count the number of pairs of guard towers that can see each other. **It is guaranteed that no two guard towers have the same height.**

## Input

The first line of input will contain one integer, *N*.

The next line of input will contain *N* integers, representing the array *H*.

## Output

The output should contain one line with one integer, the number of pairs of guard towers that can see each other.

## Limits

For all subtasks: 1 ≤ H_{i} ≤ 10^{9}.

Subtask 1 (18%): 1 ≤ N ≤ 300.

Subtask 2 (36%): 1 ≤ N ≤ 2000.

Subtask 3 (22%): 1 ≤ N ≤ 100000.

Subtask 4 (24%): 1 ≤ N ≤ 2000000.

Subtask 5 (0%): Sample Testcases.

## Sample Input 1

5 1 5 2 3 6

## Sample Output 1

8

### Tags

### Subtasks and Limits

Subtask | Score | #TC | Time | Memory | Scoring |
---|---|---|---|---|---|

1 | 18 | 21 | 1s | 256MB | Minimum |

2 | 36 | 41 | 1s | 256MB | Minimum |

3 | 22 | 61 | 1s | 256MB | Minimum |

4 | 24 | 71 | 1s | 256MB | Minimum |

5 | 0 | 1 | 1s | 256MB | Minimum |

### Judge Compile Command

g++-8 ans.cpp -o guardtowers -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512