s = input()[::-1] n = len(s) a = [ord(s[i]) - ord("A") for i in range(n)] dp = [[0] * 26 for i in range(2)] ans = 0 for i in range(n): ndp = [[0] * 26 for i in range(2)] for j in range(2): for k in range(26): ndp[j][k] = dp[j][k] ndp[0][a[i]] += 1 for j in range(26): if j == a[i]: continue ndp[1][a[i]] += dp[0][j] ans += dp[1][a[i]] dp[0] = ndp[0][::] dp[1] = ndp[1][::] print(ans)