use std::io::*; fn permutation(n: usize, p: &mut Vec, used: &mut Vec, all: &mut Vec>) { if p.len() == n { all.push(p.to_vec()); return; } for i in 0..n { if !used[i] { p.push(i); used[i] = true; permutation(n, p, used, all); p.pop(); used[i] = false; } } } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let b: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut p: Vec = Vec::new(); let mut used = vec![false; n]; let mut all: Vec> = Vec::new(); let mut cnt = 0; permutation(n, &mut p, &mut used, &mut all); for i in 0..all.len() { for j in 0..all.len() { let mut win = 0; let mut lose = 0; for k in 0..n { if a[all[i][k]] > b[all[j][k]] { win += 1; } if a[all[i][k]] < b[all[j][k]] { lose += 1; } } if win > lose { cnt += 1; } } } println!("{:.10}", (cnt as f64) / (all.len() * all.len()) as f64); }