#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>()
        .chars()
        .map(|ch| ch.to_digit(36).unwrap() as usize - 10)
        .collect::<Vec<_>>();

    let mut state = (2, 0); // 0: a, 1: b, 2: c
    let mut cur = (0, 0);
    let mut entried = vec![(0, 0)];
    for ch in s {
        if ch == state.0 {
            if state.1 == 0 {
                cur.1 -= 1;
            } else {
                cur.1 += 1;
            }
        } else if state.0 == 2 {
            if ch == 1 {
                cur.0 += 1;
                state.0 = 0;
            } else {
                cur.0 -= 1;
                state.0 = 1;
            }
        } else if state.0 == 1 {
            if ch == 0 {
                cur.0 += 1;
                state.0 = 2;
            } else {
                cur.0 -= 1;
                state.0 = 0;
            }
        } else if state.0 == 0 {
            if ch == 2 {
                cur.0 += 1;
                state.0 = 1;
            } else {
                cur.0 -= 1;
                state.0 = 2;
            }
        }

        state.1 = 1 - state.1;
        entried.push(cur);
    }
    entried.sort();
    entried.dedup();
    // debug!(entried);
    println!("{}", entried.len());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}