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 p a end if a.index{|i| i != 0} puts d - a.index{|i| i != 0} else puts 0 end a.delete(0) puts (a.size.zero?)? 0 : a.reverse.join(' ') end end A.new