#define _USE_MATH_DEFINES #include using namespace std; string s; int n; long long sum_cnt; long long calc(int l, int r) { return (r - l - 1) * (r - l) / 2; } long long cnt(int c) { long long res = 0; int pre = -1; bool in = false; for (int i = 0; i < n; i++) { if (s[i] != c + 'a') continue; in = true; res += calc(pre, i); pre = i; } if (s.back() != c + 'a') res += calc(pre, n); if (!in) return 0; return sum_cnt - res; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> s; n = (int) s.size(); sum_cnt = 1LL * n * (n + 1) / 2; long long tot = 0; cerr << sum_cnt << endl; for (int i = 0; i < 26; i++) { tot += cnt(i); cerr << "i = " << i << " " << cnt(i) << endl; } cout << setprecision(20) << fixed << 1.0 * tot / sum_cnt << endl; return 0; }