n = gets.to_i s = gets.split.map(&:to_i) n.downto(3){|i| s[i - 2] += s[i] s[i] = 0 } d = 0 ans = 0 ([n,2].min).downto(0){|i| if s[i] != 0 d = i ans = s[0..i].join(' ') break end } p d puts ans