s = input() n = len(s) dp = [[0] * 26 for _ in range(n)] # print(ord("a"), ord("A")) dp[0][ord(s[0])-65] += 1 dp[1] = dp[0].copy() dp[1][ord(s[1])-65] += 1 ans = 0 for i in range(2, n): dp[i] = dp[i-1].copy() dp[i][ord(s[i])-65] += 1 dpi = dp[i] ordi = ord(s[i])-65 for j in range(26): if dpi[j] >= 2 and ordi != j: ans += dpi[j]*(dpi[j]-1)//2 # print(dp) print(ans)