use std::collections::HashSet;


fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim().chars().collect::<Vec<_>>();

    let mut pos = HashSet::new();
    let mut up = false;
    let mut x = 0isize;
    let mut y = 0isize;
    pos.insert((x, y));
    let mut lines = vec!['a', 'b', 'c'];
    for &c in s.iter() {
        let idx = lines.iter().enumerate().filter(|&(i, &target)| target == c).nth(0).unwrap().0;
        if up {
            match idx {
                0 => { y -= 1; lines.swap(1, 2); },
                1 => { x -= 1; lines.swap(0, 2); },
                2 => { x += 1; lines.swap(0, 1); },
                _ => { unreachable!(); }
            }
        } else {
            match idx {
                0 => { y += 1; lines.swap(1, 2); },
                1 => { x += 1; lines.swap(0, 2); },
                2 => { x -= 1; lines.swap(0, 1); },
                _ => { unreachable!(); }
            }
        }
        pos.insert((x, y));
        up = !up;
    }
    println!("{}", pos.len());
}