#include #include #include #include #include using namespace std; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) #define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c)) templateusing priority_queue_rev = priority_queue, greater>; int main() { string S; cin >> S; int N = S.size(); map> m; rep(i, N) m[S[i]].push_back(i); long long ans = 0; rep(i, N) { priority_queue_rev q; for (const auto& [_, v]:m) if (auto it = all(lower_bound, v, i); it != v.end()) q.push(*it); int n = 0, before = i; while (!q.empty()) { int p = q.top(); q.pop(); ans += n * (p-before); ++n; before = p; } ans += n * (N-before); } cout << 1.0 * ans / (N*(N+1)/2) << endl; return 0; }