s = list(map(lambda c: ord(c)-65, input())) n = len(s) dp = [[[0, 0, 0] for _ in range(26)] for _ in range(n+1)] for i in range(n): c = s[i] for j in range(26): for k in range(3): dp[i+1][j][k] += dp[i][j][k] dp[i+1][c][2] += dp[i][j][1] * (c != j) dp[i+1][c][0] += 1 dp[i+1][c][1] += dp[i][c][0] ans = 0 for i in range(26): ans += dp[n][i][2] print(ans)