To recall, a subsequence is a subset of elements from the cow sequence, found at some series of indices
. We say the subsequence is increasing if
.
For example, if we had the list
1 6 2 3 4 3 5 3 4
We can reverse the chosen elements
1 6 2 3 4 3 5 3 4 ^ ^ ^ ^
to get
1 4 2 3 4 3 3 5 6 ^ ^ ^ ^
Observe how the subsequence being reversed ends up using the same indices as it initially occupied, leaving the other elements unchanged.
Please find the maximum possible length of an increasing subsequence, given that you can choose to reverse an arbitrary subsequence once.
The first line of input contains N. The remaining N lines contain, each an integer in the range
.
Output the number of elements that can possibly form a longest increasing subsequence after reversing the contents of at most one subsequence.