use std::io::{self, Read}; use std::iter::Peekable; struct Scanner { stream: Peekable, } impl> Scanner { pub fn new(stream: Peekable) -> Scanner { Scanner { stream: stream } } pub fn next_usize(&mut self) -> Option { self.skip_unprintable(); let mut n: usize = 0; if let None = self.stream.peek() { return None; } while let Some(b) = self.stream.next() { if b < 33 || b > 126 { break; } if b < b'0' || b > b'9' { return None; } n *= 10; n += (b - b'0') as usize; } Some(n) } pub fn next_u64(&mut self) -> Option { self.skip_unprintable(); let mut n: u64 = 0; if let None = self.stream.peek() { return None; } while let Some(b) = self.stream.next() { if b < 33 || b > 126 { break; } if b < b'0' || b > b'9' { return None; } n *= 10; n += (b - b'0') as u64; } Some(n) } fn skip_unprintable(&mut self) { while let Some(&b) = self.stream.peek() { if b >= 33 && b <= 126 { break; } self.stream.next(); } } } fn main() { let mut scanner = Scanner::new(io::stdin().bytes() .filter_map(|b| b.ok()).peekable()); let n = scanner.next_usize().unwrap(); let mut sum = 0; for _ in 0..n { sum += scanner.next_u64().unwrap(); } println!("{}", sum); }