Under construction

Still being built. Things may change

Recycled Problem

Interview

Time limit2sMemory limit1024 MB

Summary
Given a sequence, find the length of the longest contiguous subsequence that strictly increases then strictly decreases.
Level

Medium4 of 10

Topics
Array, Implementation, Two pointers, Brute force
Solved
No attempts yet

Problem

The deadline for submitting problems for the finals of the 5th Cheonhajeil Coding Contest is one week away, but Jeonghwi has not even finished half of his problems. With the deadline closing in, he decides to recycle a problem from the preliminaries.

Specifically, he will combine the problems "Standing Tall on the High Namsan" and "Stand on the Foundation Stone" into a new problem.

A sequence A1,⋯ ,ANA_1, \cdots, A_N of length NN is a mountain if it increases up to some point and decreases after that point.

In other words, there is an index ii such that Aj−1<AjA_{j-1} < A_j for every jj with 1<j≤i1 < j \le i, and Aj−1>AjA_{j-1} > A_j for every jj with i<j≤Ni < j \le N.

Note that a sequence of length 1 is always a mountain.

Jeonghwi loves hiking, and he wants to find the length of the longest mountain among the contiguous subsequences of the sequence AA.

A contiguous subsequence is a sequence Ai,Ai+1,Ai+2,⋯ ,AjA_i, A_{i+1}, A_{i+2}, \cdots, A_j formed by choosing two indices i,ji, j with 1≤i≤j≤N1 \le i \le j \le N.

Write a program that finds the length of the longest mountain so that Jeonghwi can hike as much as he wants.

Input

The first line gives the length of the sequence, NN.

The second line gives NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N separated by spaces.

Output

Print the length of the longest mountain among the contiguous subsequences of the sequence AA.

Constraints

  • 1≤N≤5 0001 \leq N \leq 5\,000
  • 1≤Ai≤5 0001 \leq A_i \leq 5\,000

Hint

The contest was postponed by one month, and Jeonghwi was happy about it.

Examples4

  1. Example 1

    Input
    5
    1 2 3 2 1
    
    Expected output
    5
    
  2. Example 2

    Input
    6
    1 2 1 3 4 1
    
    Expected output
    4
    
  3. Example 3

    Input
    5
    1 1 1 1 1
    
    Expected output
    1
    
  4. Example 4

    Input
    5
    3 2 1 2 3
    
    Expected output
    3