class A def initialize d = gets.chomp.to_i a = gets.chomp.split(' ').map(&:to_i).reverse 0.upto(d-3) do |num| a[num+2] += a[num] a[num] = 0 end if a.index{|i| i != 0} puts d - a.index{|i| i != 0} else puts 0 end if a.index(&:nonzero?).nil? puts 0 else a = a[a.index(&:nonzero?)..-1] puts (a.size.zero?)? 0 : a.reverse.join(' ') end end end A.new