import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve():int= var s = read() a = (0,1) b = (1,0) c = (0,0) fp = initHashSet[((int,int),(int,int),(int,int))]() fp.incl((a,b,c)) for ch in s: if ch == 'a': if a[0] == c[0] and a[1] == c[1]+1: a[1] = c[1]-1 elif a[0] == c[0] and a[1] == c[1]-1: a[1] = c[1]+1 elif a[1] == c[1] and a[0] == c[0]+1: a[0] = c[0]-1 elif a[1] == c[1] and a[0] == c[0]-1: a[0] = c[0]+1 elif ch == 'b': if b[0] == c[0] and b[1] == c[1]+1: b[1] = c[1]-1 elif b[0] == c[0] and b[1] == c[1]-1: b[1] = c[1]+1 elif b[1] == c[1] and b[0] == c[0]+1: b[0] = c[0]-1 elif b[1] == c[1] and b[0] == c[0]-1: b[0] = c[0]+1 elif ch == 'c': if (a[0]+1==c[0] and b[1]+1==c[1]) or (b[0]+1==c[0] and a[1]+1==c[1]): c[0]-=1 c[1]-=1 elif (a[1]-1==c[1] and b[0]-1==c[0]) or (b[1]-1==c[1] and a[0]-1==c[0]): c[0]+=1 c[1]+=1 elif (a[1]+1==c[1] and b[0]-1==c[0]) or (b[1]+1==c[1] and a[0]-1==c[0]): c[0]+=1 c[1]-=1 if (a[0]+1==c[0] and b[1]-1==c[1]) or (b[0]+1==c[0] and a[1]-1==c[1]): c[0]-=1 c[1]+=1 #echo (a,b,c) fp.incl((a,b,c)) return fp.len echo solve()