Under construction

Still being built. Things may change

Global Warming

Interview

Time limit2sMemory limit512 MB

Summary
Given column heights, find the greatest number of maximal above-water runs over all real sea levels.
Level

Medium5 of 10

Topics
Union-find, Sorting, Array
Solved
No attempts yet

Problem

A scientist wants to study how a rising sea level changes the landform, and above all how it changes the number of islands. He starts with one-dimensional worlds. A one-dimensional world is a sequence of non-negative integers ⟨h0,h1,…,hn−1⟩\langle h_0, h_1, \ldots, h_{n-1} \rangle, where hih_i is the altitude at location ii. The figure below shows the world given by the sequence ⟨5,6,1,3,2,9,8⟩\langle 5, 6, 1, 3, 2, 9, 8 \rangle.

If the sea level is at altitude 2.52.5, there are 3 islands: the first two columns, the fourth column, and the last two columns. If the sea level is at altitude 3.53.5, there are only 2 islands. When the sea level is at altitude xx, land at altitude xx counts as submerged, so at sea level 33 there are again 2 islands. In this world 3 is the largest number of islands over all sea levels.

The sea level xx is any real number, and an island is a maximal run of side by side columns that stay above the water. Given a one-dimensional world, find the largest number of islands over all sea levels.

Input

Your program reads from standard input. The first line contains the integer nn, the number of integers in the sequence. Each of the next nn lines contains one integer, and these nn numbers form the sequence ⟨h0,h1,…,hn−1⟩\langle h_0, h_1, \ldots, h_{n-1} \rangle. Every number in the sequence is non-negative and smaller than 2302^{30}.

Output

Your program writes to standard output one integer, the largest number of islands.

Examples1

  1. Example 1

    Input
    7
    5
    6
    1
    3
    2
    9
    8
    
    Expected output
    3