// Arup Guha
// Completed on 12/21/2025
// Solution to SER 2025 D1/D2 Problem: Swap for Palindrome

import java.util.*;

public class swapforpalindrome {

	public static int n;
	public static char[] s;
	public static int[] minI;
	public static int[] maxI;
	
	public static void main(String[] args) {
	
		// Get input.
		Scanner stdin = new Scanner(System.in);
		s = stdin.next().toCharArray();
		n = s.length;
		
		// Store minimum and maximum index of each letter, so minI[3] stores the smallest index
		// that has a 'd' for example...
		minI = new int[26];
		Arrays.fill(minI, n);
		maxI = new int[26];
		Arrays.fill(maxI, -1);
		for (int i=0; i<n; i++) {
			minI[s[i]-'a'] = Math.min(minI[s[i]-'a'], i);
			maxI[s[i]-'a'] = Math.max(maxI[s[i]-'a'], i);
		}
		
		// We can always do this.
		int res = 1;
		
		// m is the left middle character...so we search for odd and even separately...
		for (int m=0; m<n-1; m++) {
			res = Math.max(res, go(m, m+1));
			res = Math.max(res, go(m, m+2));
		}
		
		// Ta da!
		System.out.println(res);
	}
	
	// Does an outward even length palindrome search with middle two characters x and x+1.
	public static int go(int x, int y) {
	
		// Just store indexes of differences.
		int i=x, j=y, curS = y-x-1;
		ArrayList<Integer> diff = new ArrayList<Integer>();
		while (i>=0 && j<n) {
			if (s[i] != s[j]){
				diff.add(i);
				diff.add(j);
			}
			curS += 2;
			i--;
			j++;
			if (diff.size() > 4) break;
		}
		
		// Cases of diff.
		if (diff.size() == 0)
			return curS;
			
		// Maybe we can swap a correct letter from out of range.
		int limit = diff.size() > 2 ? diff.get(3)-diff.get(2)-1 : curS;
			
		int lowI = diff.get(0);
		int highI = diff.get(1);
		int midI = (lowI+highI)/2;
		
		// This is if we don't swap to help.
		int res = highI - lowI - 1;
			
		// There is an error at lowI and highI. We can try to swap a character that matches either
		// of these mismatching characters. Greedily, we would only want to try swapping in the
		// appropriate letter from the lowest or highest possible index.
		if (minI[s[highI]-'a'] < lowI) res = Math.min(limit, Math.max(res, bestMin(x,y,minI[s[highI]-'a'])) );
		if (minI[s[lowI]-'a'] < lowI) res = Math.min(limit, Math.max(res, bestMin(x,y,minI[s[lowI]-'a'])) );
		if (maxI[s[highI]-'a'] > highI) res = Math.min(limit, Math.max(res, bestMax(x,y,maxI[s[highI]-'a'])) );
		if (maxI[s[lowI]-'a'] > highI) res = Math.min(limit, Math.max(res, bestMax(x,y,maxI[s[lowI]-'a'])) );
		
		// If odd look to switch with middle char.
		if ( (x+y)%2 == 0 && (s[midI] == s[lowI] || s[midI] == s[highI]) )
			res = Math.max(res, limit);
		
		// Get this out of the way.
		if (diff.size() == 2) return res;
				
		// This is the maximum the difference could be.
		limit = diff.size() > 4 ? diff.get(5)-diff.get(4)-1 : curS;
		
		// Only thing we haven't looked for is the perfect swap.
		int[] freq = getFreq(diff);
		
		// Last improvement.
		if (freq[2] == 2) res = Math.max(res, limit);
		
		return res;
	}
	
	// If x and y are the middle starting indexes, and the first error is at swapLowI, where
	// swapLowI < x, this returns the longest possible palindrome this could be.
	public static int bestMin(int x, int y, int swapLowI) {
		int lowC = x - swapLowI;
		return 2*lowC + (y-x-1);
	}
	
	// Same as function above but here swapHighI > y.
	public static int bestMax(int x, int y, int swapHighI) {
		int highC = swapHighI-y;
		return 2*highC + (y-x-1);
	}
	
	// diff must be size 4 or more.
	public static int[] getFreq(ArrayList<Integer> diff) {
		
		// Get frequency array of these 4 letters.
		int[] freq = new int[26];
		for (int i=0; i<4; i++)
			freq[s[diff.get(i)]-'a']++;
		
		// The frequencies all have to be 0, 1 or 2.
		int[] res = new int[3];
		for (int i=0; i<26; i++)
			res[freq[i]]++;
		
		return res;
	}
}