#STK0000078. Vườn trên mái (Rooftop Garden)

Vườn trên mái (Rooftop Garden)

Rooftop Garden

Source: Baekjoon Online Judge

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN buildings arranged from left to right. The owner of building ii can see the rooftops of consecutive buildings to the right until the first building whose height is greater than or equal to building ii. Compute the total number of rooftops visible to all owners.

Input

The first line contains NN. Each of the next NN lines contains one building height, in left-to-right order.

Output

Print one integer: the total number of visible owner-rooftop pairs described above.

Subtasks

  • Subtask 1 (30 points): N≤2000N\le2000; all other conditions are unchanged.
  • Subtask 2 (70 points): 1≤N≤800001\le N\le80000, 1≤Hi≤1091\le H_i\le10^9.

Examples

Input

6
10
3
7
4
12
2

Output

5

Explanation

Consider the buildings from left to right:

  • Height 1010 sees the rooftops of heights 3,7,43,7,4. Height 1212 is the first building with height at least 1010, so the view stops before it: contribution 33.
  • Height 33 immediately meets height 7≥37\ge3, so it sees no rooftop: contribution 00.
  • Height 77 sees height 44, then height 12≥712\ge7 blocks the view: contribution 11.
  • Height 44 is immediately blocked by height 12≥412\ge4: contribution 00.
  • Height 1212 sees the final rooftop of height 22: contribution 11.
  • The last building has nothing to its right: contribution 00.

The total is 3+0+1+0+1+0=53+0+1+0+1+0=5, so the output is 5.