Everybody loves palindromes, but Artur doesn't.
He has a string S that consists of lowercase English letters ('a' - 'z'). Artur wants to find a substring T of S of the maximal length, so that T isn't a palindrome.
He has a string S that consists of lowercase English letters ('a' - 'z'). Artur wants to find a substring T of S of the maximal length, so that T isn't a palindrome.
Input
The input contains a single line, containing string S. String S consists of lower case English letters.
Output
In a single line print the length of T
Constraints
1 ≤ |S| ≤ 100000
1 ≤ |S| ≤ 100000
Sample Input:
aba
Sample Output:
2
Explanation:
"aba" is a palindrome, but "ab" isn't.
C Implementation:
#include <stdio.h>
#define MAX 1000000
int length(char *s)
{
int len = 0;
while(*s)
len++,s++;
return len;
}
int ispalin(char *s)
{
int l = 0;
int r = length(s)-1;
int flag = 1;
while(l<r)
{
if(s[l]!=s[r])
{
flag = 0;
break;
}
l++;
r--;
}
return flag;
}
int main()
{
char *s;
int i,len,maxlen,l;
s=(char*)malloc(sizeof(char)*MAX);
scanf("%s",s);
len = length(s);
maxlen = 0;
for(i=0;s[i];i++)
{
if(!(ispalin(s+i)))
{
l = len - i;
maxlen = l>maxlen?l:maxlen;
}
}
printf("%d",maxlen);
return 0;
}