import sys

sys.stdin = open("strange.in", "r")
sys.stdout = open("strange.out", "w")

s = input()
n = len(s)
prev = 0
prevc = None
cur = 0
curc = None

singles = [0] * 26
pairs = dict()

def relax():
    if curc != None:
        singles[ord(curc) - ord('a')] = max(singles[ord(curc) - ord('a')], cur)

    if prevc != None:
        if (prevc, curc) not in pairs:
            pairs[(prevc, curc)] = []
        pairs[(prevc, curc)].append((prev, cur))


for i in range(n):
    if s[i] == curc:
        cur += 1
    else:
        relax()

        prevc, prev = curc, cur
        cur = 1
        curc = s[i]

relax()

ans = sum(singles)

for p in pairs:
    a = pairs[p]
    a.sort()
    px, py = 0, 0
    for x, y in a:
        if x == px:
            ans += y - py
        else:
            ans += y * (x - px)
        px, py = x, y

print(ans)