class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i class RangeUpdate: def __init__(self, n): self.p = Bit(n + 1) self.q = Bit(n + 1) def add(self, s, t, x): t += 1 self.p.add(s, -x * s) self.p.add(t, x * t) self.q.add(s, x) self.q.add(t, -x) def sum(self, s, t): t += 1 return self.p.sum(t) + self.q.sum(t) * t - \ self.p.sum(s) - self.q.sum(s) * s #yukicoder218B s = input() ngs = len(s) alp = [[] for i in range(26)] li = [0]*(ngs) rui = [0]*(ngs+1) for i in range(ngs): idx = ord(s[i]) - ord("a") li[i] = li[i-1] if len(alp[idx]) == 0: li[i] += 1 alp[idx].append(i) ru = RangeUpdate(ngs+1) for i in range(ngs): ru.add(i+1,i+1,li[i]) ans = ru.sum(1,ngs) aidx = [1]*26 for i in range(1,ngs): idx = ord(s[i-1]) - ord("a") if len(alp[idx]) <= aidx[idx]: ru.add(i+1,ngs,-1) else: ru.add(i+1,alp[idx][aidx[idx]],-1) aidx[idx] += 1 ans += ru.sum(i+1,ngs) print(ans/((ngs*(ngs+1))/2))