use std::collections::HashMap; fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let peak_max: usize = read(); let mut peaks = HashMap::new(); loop { let input: Vec = read_vec(); { let e = peaks.entry(input[0]).or_insert(0); *e += 1; } { let e = peaks.entry(input[1]).or_insert(0); *e += 1; } if peaks.len() >= peak_max { break; } } let mut operation = 0; for (_peak, count) in &peaks { if *count > 2 { operation += *count - 2; } } println!("{}", operation); }