Longest Palindrome

Time limit: 1.5s Memory limit: 256MB Input: Output:


Professor BP loves palindromes. He wrote a sequence VV of NN positive integers on the blackboard and was delighted to see that it contained long palindromic substrings.

However, during the break, one of his students erased some of the numbers from the sequence. Now, Professor BP wants to restore the sequence by replacing all the erased numbers with the same number xx of his choice.

Your task is to determine the length of the longest palindromic contiguous substring that can be obtained after choosing an optimal value for xx.

Input data

The input file consists of two lines:

  • a line containing integer NN.
  • a line containing the NN integers V0,,VN1V_{0}, \, \ldots, \, V_{N-1}. If the number at position ii is erased, Vi=1V_i = -1, otherwise ViV_i is a number between 11 and NN.

Output data

Print a single integer: the length of the longest contiguous palindromic substring that can be obtained after replacing all erased numbers with the same number xx of Professor BP's choice.

Constraints and clarifications

  • 1N200 0001 \le N \le 200 \ 000.
  • 1ViN-1 \le V_i \le N and Vi0V_i \neq 0 for each i=0N1i=0\ldots N-1.

DISCLAIMER! Some tests have been improved compared to the competition tests.

# Points Constraints
1 0 Examples
2 11 N50N \le 50.
3 25 N1 000N \le 1 \ 000.
4 64 No additional constraints.

Example

stdin

10
6 5 5 -1 2 -1 4 5 -1 -1

stdout

5

Explanation

If Professor BP replaces all the erased numbers with the number 44, he obtains the sequence 6 5 5 4 2 4 4 5 4 46 \ 5 \ 5 \ 4 \ 2 \ 4 \ 4 \ 5 \ 4 \ 4.

The last 55 numbers form a palindromic sequence 4 4 5 4 4\texttt{4 4 5 4 4} and it is the longest he can achieve.

Log in or sign up to be able to send submissions!