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::>(); let n = s.len(); let mut lines = vec!['a', 'b', 'c']; let mut x = 0isize; let mut y = 0isize; let mut result = HashSet::new(); result.insert((x, y)); for i in 0..n { let idx = (0..3).filter(|&j| lines[j] == s[i]).nth(0).unwrap(); if i % 2 == 0 { match idx { 0 => { y += 1; lines.swap(1, 2); }, 1 => { x += 1; lines.swap(2, 0); }, 2 => { x -= 1; lines.swap(0, 1); }, _ => { unreachable!(); }, } } else { match idx { 0 => { y -= 1; lines.swap(1, 2); }, 1 => { x -= 1; lines.swap(2, 0); }, 2 => { x += 1; lines.swap(0, 1); }, _ => { unreachable!(); }, } } result.insert((x, y)); } println!("{}", result.len()); }