#abc360g. G - Suitable Edit for LIS

G - Suitable Edit for LIS

Score : 625625 points

问题陈述

给定一个长度为 NN 的整数序列 AA。高桥将执行以下操作恰好一次:

  • 选择一个介于 11NN 之间的整数 xx,以及任意整数 yy。将 AxA_x 替换为 yy

执行操作后,找出 AA 的最长递增子序列(LIS)的最大可能长度。

什么是最长递增子序列?

序列 AA 的一个子序列是通过从 AA 中提取一些元素而不改变顺序得到的序列。

序列 AA 的一个最长递增子序列是 AA 的一个最长子序列,且是严格递增的。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given an integer sequence AA of length NN. Takahashi will perform the following operation exactly once:

  • Choose an integer xx between 11 and NN, inclusive, and an arbitrary integer yy. Replace AxA_x with yy.

Find the maximum possible length of a longest increasing subsequence (LIS) of AA after performing the operation.

What is longest increasing subsequence?

A subsequence of a sequence AA is a sequence that can be derived from AA by extracting some elements without changing the order.

A longest increasing subsequence of a sequence AA is a longest subsequence of AA that is strictly increasing.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer on a single line.

Sample Input 1

4
3 2 2 4

Sample Output 1

3

The length of a LIS of the given sequence AA is 22. For example, if you replace A1A_1 with 11, the length of a LIS of AA becomes 33, which is the maximum.

Sample Input 2

5
4 5 3 6 7

Sample Output 2

4