#![allow(non_snake_case)] #[allow(unused_macros)] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut tokens = $s.split_whitespace(); input_inner! { tokens, $($r)* } }; ($($r:tt)*) => { let s = { use std::io::Read; let mut res = String::new(); ::std::io::stdin().read_to_string(&mut res).unwrap(); res }; let mut tokens = s.split_whitespace(); input_inner! { tokens, $($r)* } }; } #[allow(unused_macros)] macro_rules! input_inner { ($tokens:expr) => {}; ($tokens:expr,) => {}; ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($tokens, $t); input_inner! { $tokens $($r)* } }; } #[allow(unused_macros)] macro_rules! read_value { ($tokens:expr, ( $($t:tt),* )) => { ( $(read_value!($tokens, $t)),* ) }; ($tokens:expr, [ $t:tt; $len:expr ]) => { (0..$len).map(|_| read_value!($tokens, $t)).collect::>() }; ($tokens:expr, chars) => { read_value!($tokens, String).chars().collect::>() }; ($tokens:expr, usize1) => { read_value!($tokens, usize) - 1 }; ($tokens:expr, $t:ty) => { $tokens.next().unwrap().parse::<$t>().expect("parse error") }; } fn main() { input! { TABLE: [(String,i64); 5], N1: usize, A: [String; N1], N2: usize, B: [String; N2], N3: usize, C: [String; N3], } let mut cnt = [0_i64; 5]; for (i,s) in TABLE.iter().map(|(s,_)| s).enumerate() { let c1 = A.iter().filter(|&e| e == s).count() as i64; let c2 = B.iter().filter(|&e| e == s).count() as i64; let c3 = C.iter().filter(|&e| e == s).count() as i64; cnt[i] = 5 * c1 * c2 * c3; } let total: i64 = (0..5).map(|i| TABLE[i].1 * cnt[i]).sum(); let ans = total as f64 / (N1*N2*N3) as f64; println!("{}", ans); for e in cnt.iter() { println!("{}", e); } }