S = input() from collections import defaultdict d = defaultdict(list) ans = 0 N = len(S) for i in range(len(S)): d[S[i]].append(i) import bisect for i in range(len(S)): x = bisect.bisect_left(d[S[i]],i) ans += x*(N-(i+1)-(len(d[S[i]])-(x+1))) print(ans)