use std::collections::HashMap; use std::io::*; 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 mut mp = HashMap::new(); for i in 0..n { let p = mp.entry(a[i]).or_insert(0); *p += 1; } let mut ans = 0; for i in 0..n { let p = mp.entry(a[i] - 1).or_insert(0); if *p == 0 { ans += a[i]; } } println!("{}", ans); }