using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static LinkedList<int> value(string s)
    {
        LinkedList<int> p = new LinkedList<int>();
        char prev =s[0];
        int k = 1;
        for(int i = 1; i < s.Length; i++)
        {
            if (s[i] == prev)
                k++;
            else
            {
                p.AddLast(k);
                k = 1;
                prev = s[i];
            }
        }
        p.AddLast(k);
        return p;
    }

    static int red(LinkedList<int> p)
    {
        int z = 0;
        for(var i= p.First?.Next; i != null; i = i.Next)
        {
            int k = Math.Min(i.Value, i.Previous.Value);
            if (k != 0)
            {
                i.Value -= k;
                i.Previous.Value -= k;
                z+=k;
            }
        }
        for (var i = p.First?.Next; i != null;)
        {
            if (i.Value == 0)
            {
                if (i.Previous != null && i.Previous.Value == 0)
                {
                    var s = i.Next;
                    p.Remove(i.Previous);
                    p.Remove(i);
                    i = s;
                    continue;
                }
                else if (i.Next !=null)
                {
                    var s = i.Next;
                    i.Next.Value += i.Previous.Value;
                    p.Remove(i.Previous);
                    p.Remove(i);
                    i = s;
                    continue;
                }
            }
            i = i.Next;
        }
        return z;
    }
    public static void Main()
    {
        string s = Console.ReadLine();
        var yt = value(s);

        int a = 0,p;
        do
        {
            p = red(yt);
            a += p;
        }
        while (p != 0);
        Console.WriteLine(2 * a);
    }
}