use proconio::{input, marker::Bytes}; fn main() { input! { s:Bytes, } let s = s.into_iter().map(|si| si - b'a').collect::>(); const C: usize = 26; let n = s.len(); let mut poss = vec![vec![0; C]; n + 1]; for i in 0..n { for j in 0..C { if s[i] == j as u8 { poss[i + 1][j] = i + 1; } else { poss[i + 1][j] = poss[i][j]; } } } let mut ans = 0; for i in 1..=n { let mut poss_cp = poss[i].clone(); poss_cp.sort(); let mut cnts = vec![0; C + 1]; let mut prev = 0; for j in (1..=C).rev() { cnts[j] = poss_cp[C - j] - prev; prev = poss_cp[C - j]; } // println!("i:{} {:?}",i,cnts); for j in 1..=C { ans += j * cnts[j]; } } let ans = ans as f64 / (n * (n + 1) / 2) as f64; println!("{}", ans); }