use itertools::Itertools; use std::io::Read; use std::cmp::Ordering; fn factorial(x: usize) -> usize { if x == 0 { 1 } else { x * factorial(x - 1) } } fn solve(n: usize, a: &[i64], b: &[i64]) -> f64 { let mut a_wins = 0; for pa in a.iter().permutations(n) { for pb in b.iter().permutations(n) { let m = pa .iter() .zip(pb.iter()) .map(|(x, y)| match x.cmp(y) { Ordering::Greater => 1, Ordering::Less => -1, Ordering::Equal => 0, }) .sum::(); if m > 0 { a_wins += 1; } } } (a_wins as f64) / (factorial(n).pow(2) as f64) } fn main() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| iter.next().unwrap().parse().unwrap()) .collect(); let b: Vec = (0..n) .map(|_| iter.next().unwrap().parse().unwrap()) .collect(); let result = solve(n, &a, &b); println!("{}", result); }