s = list(str(input())) S = [] for c in s: if c == 'a': S.append(0) elif c == 'b': S.append(1) else: S.append(2) S.reverse() d = set() n = len(S) cur = (0, 0, 0) d.add(cur) ans = 1 pre = -1 for i in range(n): c = S.pop() pos = [0, 0, 0] if pre != c: for i in range(3): if i != c: pos[i] = cur[i] else: pos[i] = cur[i]+1 pre = c else: for i in range(3): if i != c: pos[i] = cur[i] else: pos[i] = cur[i]-1 pre = -1 pos = tuple(pos) if pos not in d: ans += 1 d.add(cur) cur = pos print(ans)