from collections import Counter S = input() A = [{s:0 for s in set(list(S))} 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] if A[i][s] >= 1: ans += A[i][s]*(len(S) - 1 - i ) print(ans)