import java.util.*;

public class Solution {
    public int getLongestPalindrome(String A, int n) {
        // write code here
        char[] cc = A.toCharArray();
        int res = 0;
        for(int i = 0; i < cc.length; ++i){
            int L = i, R = i, RR = i;
            // 如果相同,L,R指标就跳过去
            while(L - 1 >= 0 && cc[L - 1] == cc[i]) L--;
            while(R + 1 <= 0 && cc[R + 1] == cc[i]) R++;
            RR = R;
            while(L - 1 >= 0 && R + 1 <= cc.length - 1 && cc[L - 1] == cc[R + 1]){
                L--;
                R++;
            }
            res = Math.max(res, R - L + 1);
            i = RR;
        }
        return res;
    }
}