MULPAL - Multiplicative Palindrome

Given a sequence of N integers. Find two disjoint contiguous palindromic subsequences. Lets call them X and Y. Your task is to find X and Y such that product of their lengths is maximal possible.

Input

First line will contain one integer N (1 ≤ N ≤ 106).

Second line will contain N integers representing a sequence from the text of the task (0 ≤ Ai ≤ 2*109).

Output

First and only line of output should contain only one integer, the maximum possible product from the text of problem.

Example

Input:
2
1 1

Output:
1
Input:
4
1 1 2 2

Output:
4
Input:
6
10 11 12 12 11 10

Output:
4
Input:
6
0 1 0 1 0 1

Output:
9

Added by:Zvonimir Medic
Date:2010-11-28
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:own problem

hide comments
2012-02-11 13:33:16 MarioYC
disjoint contiguous palindromic subsequences = disjoint palindromic substrings? (looking each number as a character)


Last edit: 2012-12-24 01:17:59
2011-10-15 21:35:11 Buda IM (retired)
Yes, my O ( N ) got TLE, some IO optimization took care of it.

Last edit: 2011-10-15 21:38:26
2011-01-26 07:44:32 Prabakaran
@Shaka Shadows:In ur post length(11 12 12 11)*length(10),in Y part 10 is not a palindrome.then hw can u consider it?
i think the sol is len(11)*len(11)=4
2010-12-17 10:04:15 Kinan Sarmini
If anyone is getting WA a lot, then you either forget n = 1 case or long long
2010-12-16 19:39:28 Siarhei Kulik
Time limit is a little strict. Even O(N) solution may not fit in the time.
2010-12-12 18:13:40 .::Manish Kumar::.
What was your Time-complexity?
2010-12-12 02:43:17 Shaka Shadows
Yes :). Besides, X and Y don't need to be one exactly after the other. Read the text carefully.
2010-12-11 19:16:17 .::Manish Kumar::.
So, ultimately it has nothing to do with numbers, numbers can be considered as a single element.

Last edit: 2010-12-11 19:17:22
2010-12-11 18:57:22 Shaka Shadows
No, the answer is 4 because length(11 12 12 11) * length(10) = 4 * 1 = 4. The problem asks for finding 2 disjoint and palindromic contiguous sequences, X and Y, such that length(X) * length(Y) is maximum.
2010-12-11 18:53:09 .::Manish Kumar::.
Is the answer to 3rd sample 4 because:
length(11)*length(11) = 2*2 = 4 ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.