use std::io::*; use std::str::FromStr; use utils::*; pub fn main() { let i = stdin(); let mut o = Vec::new(); run(i.lock(), &mut o); stdout().write_all(&o).unwrap(); } fn run(i: R, o: &mut W) { let mut i = CpReader::new(i); let d = i.read::(); let a = i.read_vec::(d + 1); let r = solve(a); writeln!(o, "{}", r.len() - 1).unwrap(); for i in 0..r.len() { if i != 0 { write!(o, " ").unwrap(); } write!(o, "{}", r[i]).unwrap(); } writeln!(o, "").unwrap(); } fn solve(mut a: Vec) -> Vec { while a.len() >= 4 { let i = a.len() - 1; a[i - 2] += a[i]; a.remove(i); } while a.len() > 1 && a[a.len() - 1] == 0 { a.pop(); } a } mod utils { use super::*; pub struct CpReader { r: R, s: String, } impl CpReader { pub fn new(r: R) -> Self { CpReader { r: r, s: String::new(), } } pub fn read_line(&mut self) -> &str { self.s.clear(); self.r.read_line(&mut self.s).unwrap(); self.s.trim() } pub fn read(&mut self) -> T { self.read_line().parse().ok().unwrap() } pub fn read_vec(&mut self, n: usize) -> Vec { self.read_line() .split(' ') .take(n) .map(|x| x.parse().ok().unwrap()) .collect() } } }