import javafx.util.Pair;

import java.util.*;

public class Main {

    private static void deleteRepeats(ArrayList<int[]> arr) {
        for (int i = 1; i < arr.size(); i++) {
            if (arr.get(i - 1)[2] == arr.get(i)[2]) {
                arr.get(i - 1)[1] += arr.get(i)[1];
                arr.remove(i);
                i--;
            }
        }
    }

    private static int getMinPick(ArrayList<int[]> arr) {
        int pick = arr.get(0)[1];
        for (int i = 1; i < arr.size() - 1; i++) {
            pick = Integer.min(pick, (int) Math.ceil((float) arr.get(i)[1] / 2));
        }
        return Integer.min(pick, arr.get(arr.size() - 1)[1]);
    }

    private static void minimizeSeq(ArrayList<int[]> arr, int pick) {
        if (arr.size() < 1) return;
        int start = 1;
        if (arr.get(0)[1] <= pick) {
            start = 0;
            arr.remove(0);
        } else {
            arr.get(0)[1] -= pick;
        }
        int stop = 0;

        if (arr.get(arr.size() - 1)[1] <= pick) {
            arr.remove(arr.size() - 1);
        } else {
            arr.get(arr.size() - 1)[1] -= pick;
            stop = 1;
        }
        pick *= 2;
        for (int i = start; i < arr.size() - stop; i++) {
            if (arr.get(i)[1] <= pick) {
                arr.remove(i);
                i--;
            } else {
                arr.get(i)[1] -= pick;
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Long ans = 0L;
        // L - Length - symbol
        ArrayList<int[]> arr = new ArrayList<>();
        char[] allSym = scanner.next().toCharArray();
        if (allSym.length < 2) {
            System.out.println(0);
            return;
        }
        char help = allSym[0];
        int len = 0;
        int pick = 0;
        int q = 1;
        while (q < allSym.length && help == allSym[q]) {
            help = allSym[q];
            q++;
        }
        if (q > 1) {
            arr.add(new int[]{0, q, help});
            pick += q;
        }
        for (int i = q; i < allSym.length; i++) {
            if (help == allSym[i]) {
                len++;
            } else {
                if (len > 1) {
                    arr.add(new int[]{i - len - 1, len + 1, help});
                    pick += len + 1;
                }
                len = 0;
            }
            help = allSym[i];
        }
        if (len > 0) {
            arr.add(new int[]{allSym.length - len - 1, len + 1, help});
            pick += len + 1;
        }
        if (allSym.length != pick) {
            ans++;
            minimizeSeq(arr, 1);
        } else {
            //System.out.println("not minimize");
        }
        deleteRepeats(arr);
        //arr.forEach((qqq) -> System.out.println(Arrays.toString(qqq)));
        while (arr.size() > 1) {
            pick = getMinPick(arr);
            ans += pick;
            minimizeSeq(arr, pick);
            deleteRepeats(arr);
            //System.out.println("---------- new move ---------");
            //arr.forEach((qqq) -> System.out.println(Arrays.toString(qqq)));
            //System.out.println(ans);
        }
        //arr.forEach((qqq) -> System.out.println(Arrays.toString(qqq)));
        System.out.println(ans);
    }
}