#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;
 
use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;

    input!{
        s: Chars,
    }
    let mut s: VecDeque<char> = VecDeque::from(s);
    let mut leaved = vec![];
    let all_num = s.len();

    loop {
        // dbg!(&s);
        // dbg!(&leaved);
        if s.len() == 0 || s.iter().chain(leaved.iter()).all_equal() { break; }

        let s1 = s.pop_front().unwrap();

        if !leaved.is_empty() {
            let l = leaved.pop().unwrap();
            if l != s1 { continue; }
            leaved.push(l);
        }

        let s2 = s.pop_front().unwrap();

        if s1 != s2 { continue };

        leaved.push(s1);
        s.push_front(s2);
    }

    println!("{}", all_num - s.len())
}

fn main() {
    solve();
}
