Jim and the Skyscrapers#11720

Jim and the Skyscrapers

1 second
128 megabytes
Medium

Given an array h_1, h_2, \ldots, h_n. Count the number of pairs of indices , 1 \le i < j \le n, such that the following conditions hold: h_i = h_j and \max_{i < k < j} h_k \le h_j.

Input

The first line contains one integer (1 \le n \le 3 \cdot 10^5). The second line contains integers h_1, h_2, \ldots, h_n (1 \le h_i \le 10^6).

Output

Print the number of pairs of indices that satisfy the given conditions.

Examples

In the first example, the valid pairs are: , , and .

Example 1

Loading
Loading

Example 2

Loading
Loading