use std::io::{BufRead, BufWriter, Write, StdinLock, StdoutLock}; fn input(stdin: &mut StdinLock) -> String { let mut input = String::new(); stdin.read_line(&mut input).ok(); input } macro_rules! read { ($stdin:expr, [$t:tt; $n:expr]) => { (0..$n).map(|_| read!($stdin, $t)).collect::>() }; ($stdin:expr, [$t:tt]) => { input($stdin) .split_whitespace() .map(|x| parse!(x, $t)) .collect::>() }; ($stdin:expr, ($($t:tt),*)) => { { let input = input($stdin); let mut iter = input.split_whitespace(); ( $( parse!(iter.next().unwrap(), $t) ),* ) } }; ($stdin:expr, $t:tt) => { parse!(input($stdin).trim(), $t) }; } macro_rules! parse { ($s:expr, chars) => { $s.chars().collect::>() }; ($s:expr, usize1) => { parse!($s, usize) - 1 }; ($s:expr, $t:ty) => { $s.parse::<$t>().unwrap() } } trait ProconWrite { fn writeln(&mut self, x: T); fn writeln_iter(&mut self, iter: I) where I::Item: std::fmt::Display { self.writeln( iter.map(|x| x.to_string()).collect::>().join(" ") ); } } impl ProconWrite for BufWriter> { fn writeln(&mut self, x: T) { writeln!(self, "{}", x).ok(); } } fn solve(stdin: &mut StdinLock, writer: &mut BufWriter) { let s = read!(stdin, String); let f = |x: i32| { let res = x % 6; if res < 0 { res + 6 } else { res } }; let (mut x, mut y): (i32, i32) = (0, 0); let mut set = std::collections::HashSet::new(); set.insert((x, y)); for c in s.chars() { if c == 'a' { match f(x) { 0 => x -= 1, 1 => if y % 2 == 0 { y += 1; } else { y -= 1; }, 2 => x += 1, 3 => x -= 1, 4 => if y % 2 == 0 { y -= 1; } else { y += 1; }, _ => x += 1, } } else if c == 'b' { match f(x) { 0 => x += 1, 1 => x -= 1, 2 => if y % 2 == 0 { y -= 1; } else { y += 1; }, 3 => x += 1, 4 => x -= 1, _ => if y % 2 == 0 { y += 1; } else { y -= 1; }, } } else { match f(x) { 0 => if y % 2 == 0 { y -= 1; } else { y += 1; }, 1 => x += 1, 2 => x -= 1, 3 => if y % 2 == 0 { y += 1; } else { y -= 1; }, 4 => x += 1, _ => x -= 1, } } set.insert((x, y)); } writer.writeln(set.len()); } fn main() { let stdin = std::io::stdin(); let mut stdin = stdin.lock(); let stdout = std::io::stdout(); let mut writer = BufWriter::new(stdout.lock()); solve(&mut stdin, &mut writer); }