def SameRange(A): N=len(A) pre_same=[-1]*N next_same=[N]*N last_pos = defaultdict(lambda: -1) for i, a in enumerate(A): j = last_pos[a] if j==-1: last_pos[a] = i else: next_same[j] = i pre_same[i] = j last_pos[a] = i return pre_same, next_same def count_pair(i,l,r): """ 部分列 [l,r] の中で、i を含む部分列の個数 """ return (i-l+1)*(r-i+1) ####################################################################################### def example(): global input example = iter( """ 7 1 1 3 3 3 2 2 """ .strip().split("\n")) input = lambda: next(example) ####################################################################################### import sys input = sys.stdin.readline from collections import defaultdict # example() A=[] for s in input().rstrip(): A.append(ord(s)-ord("a")) N=len(A) cnt=0 L,R = SameRange(A) for i in range(N): l,r=L[i],R[i] cnt+=count_pair(i,l+1,N-1) T=N*(N+1)//2 print(cnt/T)