package main import ( "bufio" "fmt" "os" "strconv" ) func getNextString(scanner *bufio.Scanner) string { if !scanner.Scan() { panic("scan failed") } return scanner.Text() } func atoi(s string) int { x, _ := strconv.Atoi(s); return x } func getNextInt(scanner *bufio.Scanner) int { return atoi(getNextString(scanner)) } func atoi64(s string) int64 { x, _ := strconv.ParseInt(s, 10, 64); return x } func getNextInt64(scanner *bufio.Scanner) int64 { return atoi64(getNextString(scanner)) } func atof64(s string) float64 { x, _ := strconv.ParseFloat(s, 64); return x } func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { s := getNextString(scanner) n := len(s) type pair [3]int var ( l, r, m int mp map[pair]bool ) l = 0 r = 2 m = 1 now := pair{0, 0, 0} mp = map[pair]bool{} mp[now] = true for i := 0; i < n; i++ { e := int(s[i] - 'a') if now[0] == 0 { switch e { case l: now = pair{1 - now[0], now[1], now[2] - 1} l, r, m = m, l, r case r: now = pair{1 - now[0], now[1], now[2] + 1} l, r, m = m, l, r case m: now = pair{1 - now[0], now[1] - 1, now[2]} } } else { switch e { case l: now = pair{1 - now[0], now[1], now[2]} l, r, m = m, l, r case r: now = pair{1 - now[0], now[1], now[2] + 1} l, r, m = m, l, r case m: now = pair{1 - now[0], now[1] + 1, now[2]} } } mp[now] = true } fmt.Fprintln(writer, len(mp)) }