use std::io::Read; use std::cmp::min; use std::collections::HashMap; 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 mut score: HashMap = HashMap::new(); for i in 0..n{ let ni: usize = iter.next().unwrap().parse().unwrap(); let m: usize = iter.next().unwrap().parse().unwrap(); let s: isize = iter.next().unwrap().parse().unwrap(); for j in 0..m{ let tag = iter.next().unwrap().parse::().unwrap(); *score.entry(tag).or_default() += s; } } let mut vec: Vec<(_, _)> = score.iter().collect(); vec.sort_by(|a, b| (-a.1).cmp(&(-b.1)).then(a.0.cmp(&b.0))); for i in 0..min(10,vec.len()){ println!("{} {}",vec[i].0,vec[i].1) } }