gets a=gets.split.map &:to_i a[-2]=a[-3]+a.pop while a[3] a[a[2]==0?a[1]==0?1:2:3,2]=[] puts [a.size-1,a*" "]