s = input() x = 0 y = 0 cnt = 0 se = set() se.add((0, 0)) for c in s: t = 0 if c == 'b': t = 1 elif c == 'c': t = 2 # if cnt % 2 == 0: now = -x + 2 * t now %= 3 if now == 0: if cnt % 2 == 0: y -= 1 else: y += 1 if now == 2: x += 1 if now == 1: x -= 1 # # else: # now = t * 2-x # now %= 3 # if now == 0: # y += 1 # if now == 1: # x += 1 # if now == 2: # x -= 1 se.add((x, y)) cnt += 1 print(len(se))