LPS - Longest Palindromic Substring

A palindrome is a string that is the same as its reverse. Example "malayalam", "dad", "appa" etc. In this problem you are asked to find the length of the longest contiguous substring of a given string, which is a palindrome.

Input

The first line consists of a single integer N, the number of characters in the string. 1 <= N <= 100000.

Second line is a string with N characters, where the characters are always lowercase English letters, i.e. 'a' to 'z'.

Output

A single line with an integer representing the length of longest palindromic substring.

Example
Input:
5
ababa

Output:
5


Added by:Srivatsan B
Date:2009-06-04
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:http://opc.iarcs.org.in/problems/iarcs-feb05-ad-1

hide comments
2014-09-01 01:28:33 nour samir
hi everyone i try to solve this problem using suffix array and that is my solution in c++ <snip>
i get WA :\ but i can't handle case like that abcdcba the right answer is 1 but my code generate 3 :\
help plz

Last edit: 2022-09-18 10:48:24
2012-06-29 04:58:21 Ritesh Kumar Gupta
@All :: Guys I don't know why ,but the gets gives wrong answer .. I changed gets to scanf("%s",buffer) and got accepted.
2010-02-04 12:55:37 Nagi Nahas
I got accepted, but for some reason I am getting "wrong answer" if I use getline() or cin.get() instead of the extraction operator >> . Not only "wrong answer" but also the code finishes in 0.00 seconds, indicating that it read a very small amount of data. I don't know why.

Last edit: 2010-02-04 12:56:34
2009-10-27 07:10:20 Jorge Bernadas
@kk: My solution is correct and gave 1 as answer.
2009-10-03 13:41:31 Ankit kumar jain
what will be the answer of "adfg".
2009-10-03 13:22:56 Ankit kumar jain
what will be the answer of "abcd".
answer is one or zero.
2009-06-04 14:41:03 [Trichromatic] XilinX
Another (almost same) problem PALIM is available in the classical section now.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.