use std::collections::BTreeSet; fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().chars().map(|c| c as usize - 'a' as usize).collect::>(); let n = s.len(); let pattern = n * (n+1) / 2; let mut pos = vec![vec![]; 26]; for i in 0..n { pos[s[i]].push(i); } let mut total = 0usize; for pos in pos.iter() { let mut idx = 0usize; for i in 0..n { if idx == pos.len() { break; } total += n - pos[idx]; if pos[idx] == i { idx += 1; } } } println!("{}", total as f64 / pattern as f64); }