S = input() alpha_set = set(list(S)) A = [{s:0 for s in alpha_set} for _ in range(len(S)+1)] for i, s in enumerate(S): i += 1 for key in A[i]: A[i][key] += A[i-1][key] A[i][s] += 1 # print(A[-1]) ans = 0 for i in range(len(S)): s = S[i] for key in A[i]: if s == key: continue ans += A[i][key]*(A[i][key]-1)//2 # print(s,key, A[i][key]*(A[i][key]-1)//2) print(ans)