Longest Increasing Subsequence With At Most One Deletion

VERY HARD · C · 5000ms

Sabbir also wonders: if he's allowed to discard exactly one faulty sensor reading first, how much longer can the increasing calibration sequence become? Given N integers, find the length of the longest strictly increasing subsequence you can form after deleting AT MOST ONE element from the array first (deletion is from the original array, then take an increasing subsequence of what remains).

Input

Line1: N. Line2: N integers.

Output

Length of the best achievable increasing subsequence.

Constraints

1 ≤ N ≤ 10^5

Sample Input

6
5 1 2 3 4 9

Sample Output

5
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Longest Increasing Subsequence With At Most One Deletion · DIU ContestHub