dic = {"a": 0, "b": 1, "c": 2} S = [dic[s] for s in input()] st0 = 0 # 0:上向き、1;下向き st1 = [0, 1, 2] #水平辺、左辺、右辺の順 Moved = {(0, 0)} now = [0, 0] for s in S: a = st1.index(s) if a == 0: if st0 == 0: now[0] += 1 else: now[0] -= 1 elif a == 1: now[1] -= 1 st1 = st1[2:] + st1[:2] else: now[1] += 1 st1 = st1[1:] + st1[:1] st0 ^= 1 if tuple(now) not in Moved: Moved.add(tuple(now)) print(len(Moved))