import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
    BufferedReader br;
    PrintWriter pw;
    StringTokenizer st;
    long mod = (long) (1e9 + 7);
    int INF = (int) 1e9;
    int n;
    TreeSet<group> r = new TreeSet<>();

    public static void main(String[] args) {
        (new Main()).run();
    }

    void solve() throws IOException {
        String s = nextToken() + "$";
        n = s.length();
        int count = 1;
        int col = s.charAt(0) - 'a';
        ArrayList<group> w = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) != s.charAt(i + 1)) {
                w.add(new group(count, col, i));
                count = 1;
                col = s.charAt(i + 1) - 'a';
            } else {
                count++;
            }
        }
        int m = w.size();
        if (w.size() > 1) {
            w.get(0).right = w.get(1);
            w.get(0).setDel();

        }
        for (int i = 1; i < m - 1; i++) {
            w.get(i).left = w.get(i - 1);
            w.get(i).right = w.get(i + 1);
            w.get(i).setDel();
        }
        if (m - 2 >= 0) {
            w.get(m - 1).left = w.get(m - 2);
            w.get(m - 1).setDel();
        }

        r.addAll(w);
        int ans = 0;
        while (r.size() > 1) {
            group cur = r.pollFirst();
            ans += cur.del;
            for (group z:
                 r) {
                z.del -= cur.del;
            }
            group L = cur.left;
            group R = cur.right;
            if (L != null) L.right = R;
            if (R != null) R.left = L;
            if (L != null && R != null && L.color == R.color) {
                group nw = L.join(R);
                r.remove(L);
                r.remove(R);
                r.add(nw);
            }
        }
        pw.print(ans);
    }

    void run() {
        try {
//            br = new BufferedReader(new FileReader("divljak.in"));
//            pw = new PrintWriter(new BufferedWriter(new FileWriter("divljak.out")));
//            br = new BufferedReader(new FileReader("input.txt"));
//            pw = new PrintWriter(new FileWriter("output.txt"));
            br = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(new OutputStreamWriter(System.out));

            solve();
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    class group implements Comparable<group> {
        int count;
        int color;
        int ind;
        group left;
        group right;
        int del = 0;

        public group(int count, int color, int i) {
            this.count = count;
            this.color = color;
            ind = i;
            left = null;
            right = null;
        }

        @Override
        public int compareTo(group o) {
            if (del != o.del) return del - o.del;
            return ind - o.ind;
        }

        void setDel() {
            if (left == null && right == null) del = INF;
            else if (left == null || right == null) del = count;
            else del = count / 2 + count % 2;
        }

        group join(group t) {
            group res = new group(count + t.count, color, t.ind);
            res.left = left;
            res.right = t.right;
            setDel();
            return res;
        }
    }
}