cswork / OAOpen practice workspace

MicrosoftOA #67

The Longest Spike

Estimated EasyJudge-ready

Topics (AI-labelled)Hashing

Choose any numbers from the array and rearrange them into a sequence that strictly increases and then strictly decreases. The two parts share the peak, and either part may consist of just the peak, so purely increasing, purely decreasing, and single-element sequences are also valid. Return the maximum length.

This site uses a standard input/output protocol.

Input

The first line contains N, and the second line contains N integers. This site uses 1≤N≤200000 and elements in −10⁹..10⁹.

Output

Output a single integer, the answer.

Example 1

Input:

2
1 2

Output:

2

Example 2

Input:

6
2 5 3 2 4 1

Output:

6

Example 3

Input:

3
5 5 5

Output:

1

Example notes

Example 1: 1, 2 is already a peak, of length 2. Example 2: you can arrange 1, 2, 3, 4, 5, 2, of length 6. Example 3: strictness forbids repeating the peak value, so only one 5 can be used.

Editorial

Loading solution…