S = input() L = len(S) chars = set(S) #print(chars) D:dict[str,list[int]] = dict() for c in chars: D[c] = [] #print(D) for i in range(L): D[S[i]].append(i) #print(D) ans = 0 for c in chars: if c not in D or len(D[c]) == 1:continue else: #print(c,D[c]) A = D[c] N = len(A) for i in range(1,N): #print(f"{i=},{A[i]=},{L=}") ans += i * (L-A[i]-(N-i)) #print(f"{ans=}") print(ans)