#![allow(unused_macros)] #![allow(dead_code)] #![allow(unused_imports)] use crate::lib::{Scanner, Permutation}; use std::collections::*; const U_INF: usize = 1 << 60; const I_INF: isize = 1 << 60; fn main() { let mut sc = Scanner::new(); let n = sc.next_usize(); let a = (0..n).map(|_| sc.next_usize()).collect::>(); let b = (0..n).map(|_| sc.next_usize()).collect::>(); let p = Permutation::new(&(0..n).collect()); let mut win = 0; let mut sum = 0; for c in p.clone() { for d in p.clone() { let mut score = 0; for i in 0..n { if a[c[i]] > b[d[i]] { score += 1; } else { score -= 1; } } if score > 0 { win += 1; } sum += 1; } } println!("{}", win as f64 / sum as f64); } pub mod lib { #[derive(Clone)] pub struct Permutation { v: Vec, l: Vec, not_start: bool, } impl Permutation { pub fn new(v: &Vec) -> Permutation { Permutation { l: vec![0; v.len()], v: v.clone(), not_start: true, } } } impl Iterator for Permutation { type Item = Vec; fn next(&mut self) -> Option> { // non-permutated vector if self.not_start { self.not_start = false; return Some(self.v.clone()); } for n in 0..self.v.len() { if self.l[n] < n { if (n + 1) % 2 == 1 { self.v.swap(0, n); self.l[n] += 1; } else { self.v.swap(self.l[n], n); self.l[n] += 1; } return Some(self.v.clone()); } else { self.l[n] = 0 } } return None; } } pub struct Scanner { buf: std::collections::VecDeque, } impl Scanner { pub fn new() -> Self { Self { buf: std::collections::VecDeque::new(), } } fn scan_line(&mut self) { let mut flag = 0; while self.buf.is_empty() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut iter = s.split_whitespace().peekable(); if iter.peek().is_none() { if flag >= 5 { panic!("There is no input!"); } flag += 1; continue; } for si in iter { self.buf.push_back(si.to_string()); } } } pub fn next(&mut self) -> T { self.scan_line(); self.buf .pop_front() .unwrap() .parse() .unwrap_or_else(|_| panic!("Couldn't parse!")) } pub fn next_usize(&mut self) -> usize { self.next() } pub fn next_isize(&mut self) -> isize { self.next() } pub fn next_chars(&mut self) -> Vec { self.next::().chars().collect() } pub fn next_string(&mut self) -> String { self.next() } pub fn next_char(&mut self) -> char { self.next() } pub fn next_float(&mut self) -> f64 { self.next() } } }