import java.util.Scanner; /** * NC402 包含不超过两种字符的最长子串 * @author d3y1 */ public class Main { public static void main(String[] args) { solution(); } /** * 贪心+滑动窗口(双指针) */ private static void solution(){ Scanner in = new Scanner(System.in); char[] chars = in.nextLine().toCharArray(); int n = chars.length; if(n <= 2){ System.out.println(n); return; } int result = 0; int[] cnt = new int[26]; int kind = 0; // 滑动窗口(双指针) for(int i=0,j=0; i<=j&&j<n; j++){ // 贪心 if(cnt[chars[j]-'a']++ == 0){ kind++; } while(kind > 2){ if(--cnt[chars[i++]-'a'] == 0){ kind--; } } result = Math.max(result, j-i+1); } System.out.println(result); } }