S = input() p = ["abc", "cab", "bca"] s = set([(0, 0)]) x, y = 0, 0 cur = 0 for i in range(len(S)): ind = p[cur].index(S[i]) cur += ind cur %= 3 if i % 2: if ind == 0: x += 1 y += 1 if ind == 1: y -= 2 if ind == 2: x -= 1 y += 1 else: if ind == 0: x -= 1 y -= 1 if ind == 1: x += 1 y -= 1 if ind == 2: y += 2 s.add((x, y)) print(len(s))