/* -*- coding: utf-8 -*- * * 852.cc: No.852 連続部分文字列 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000000; /* typedef */ typedef long long ll; /* global variables */ char s[MAX_N + 4]; int pps[26]; /* subroutines */ /* main */ int main() { scanf("%s", s); memset(pps, -1, sizeof(pps)); int n = 0; ll sum = 0, d = 0; for (; s[n]; n++) { int c = s[n] - 'a'; d += n - pps[c]; sum += d; //printf("%d: %lld %lld %d\n", n, d, sum, pps[n]); pps[c] = n; } ll cnt = (ll)n * (n + 1) / 2; printf("%.8lf\n", (double)sum / cnt); return 0; }